user499372
user499372

Reputation: 129

How can I include 'quote inside a list in Scheme?

I am trying to make a list in Scheme like this: (list 'quote 'a) and I expect the output to be (quote a) but the interpreter excutes the quote and the output is: 'a

How can I write the code to get the expected output?

Upvotes: 0

Views: 213

Answers (2)

samdphillips
samdphillips

Reputation: 131

Which implementation are you using. Changing how the REPL prints out sexps depends on your implementation of scheme, and if the implementation supports writing out sexps in an expanded form.

Upvotes: 0

Nietzche-jou
Nietzche-jou

Reputation: 14720

That's as it ought to be, since the expression 'a is an abbreviation for the list (quote a), and the interpreter's printer is using that shorthand for its output. You should note that if you tell the interpreter to evaluate 'a, it prints out a unadorned with an apostrophe.

If you try taking out the parts of (list 'quote 'a), you would see that you have exactly the list you expected to get:

> (car (list 'quote 'a))
quote
> (cadr (list 'quote 'a))
a

So in summary, you are getting the expected output, just not the expected representation. If you truly demand that you get as output (quote a), then you have to look into your interpreter's documentation to see if that's supported. Or you might have to write your own procedure to print out lists.

Upvotes: 4

Related Questions