Scheme - How to use “.” as a symbol

萝らか妹 提交于 2019-12-11 00:51:43

问题


I want to do something like:

(car '(. a))

and get

.

as a result.

For example, if you type

'.

into the console you will get the output that I want. The problem is that I don't want to have an apostrophe infront of all of the . in a list.

Any guidance?


回答1:


In Scheme's read syntax, a standalone dot is special. '. won't get you a dot symbol; it's invalid syntax. (If it works in your implementation, then that's just a special quirk of your implementation.)

Instead, you have to escape it. In most Scheme implementations, you can either use '|.| or '\..

(car '(\. a))   ; returns the same thing as (string->symbol ".")
(car '(|.| a))  ; likewise



回答2:


EDIT: This appears to only work in MIT/GNU Scheme.

' creates symbol and list literals. If you want . as a symbol, it's '..

If a is a symbol literal, you can use

(car '(. a))

or

(car (list '. 'a))

If a is a variable, try

(car `(. ,a))

or

(car (list '. a))


来源:https://stackoverflow.com/questions/9986664/scheme-how-to-use-as-a-symbol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!