2

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?

0

2 Answers 2

7

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
0
3

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))
4
  • Try (car '(. a)) ... it doesn't work for me :( . This is the problem that I'm trying to fix actually. Apr 3, 2012 at 14:04
  • Huh. Worked for me (MIT/GNU Scheme) but that might be an implementation thing.
    – Taymon
    Apr 3, 2012 at 14:40
  • The other answer here suggests that your solution is invalid syntax... Who's right? :)
    – amindfv
    Apr 4, 2012 at 4:06
  • Going by R5RS, I think they are. Mine works under MIT/GNU Scheme but apparently not under Racket.
    – Taymon
    Apr 4, 2012 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.