2

I am writing a scheme interpreter in scheme (well, Racket). In my parse/eval function, I have the following rule:

(quotation [(Q datum) (string->symbol $2)])

string->symbol is apparently an incorrect definition of quote in such an interpreter.

I have tried many other ways, but none of them worked. Of course, if I try using the Racket quote function it doesn't work, since the $2 is interpreted literally, so everything evaluates to $2.

Now, if I evaluate some examples at the REPL:

$> (eval '1)
$> 1
$> (eval '#f)
$> #f
$> (eval 's)
$> s

VS. the Racket REPL:

$> (eval '1)
$> 1
$> (eval '#f)
$> #f
$> (eval 's)
$> 's

Note the difference: (eval 's) -> s in mine, -> 's in Racket. Furthermore, doing (symbol? (eval x)) also behaves differently.

How I am supposed to implement quote in such a case?

Raoul
  • 1,872
  • 3
  • 26
  • 48
  • 2
    You can give a look at [this answer](https://stackoverflow.com/a/33780140/2382734) about the difference concerning the quote. – Renzo Jun 09 '18 at 10:02
  • 1
    @Renzo Thankks, although if I understand what you are implying, I should write that `(quotation [(Q datum) $2])`, isn'it? That returns without eval. However in Racket `(eval 's)` returns `'s`, while if I run the modified version I get `s`. Is that DrRacket just confusing me, as you say in your linked answer? – Raoul Jun 09 '18 at 10:46
  • 1
    @Raoul Yes, that is the correct implementation. Don't use the REPL as proof since it's visualization of values are not the result themselves unless the results are self evaluating. You can turn that off by going to bottom left choose "Determine language from source" and a modal shows up. Press "Show Details" and set `write` as output style. Now you see the values in a way shared by most lisp implementations and what you can use in most cases. – Sylwester Jun 09 '18 at 11:18

1 Answers1

0

So as stated in the comments, this is an issue with REPL printing, and the correct implementation is:

(quotation [(Q datum) $2])

Thanks to those who helped me!

Raoul
  • 1,872
  • 3
  • 26
  • 48