0

I was wondering, If

(cons (quote (a b c)) #f)

gives an output

(( a  b  c ))

Then what output does this give:

(cons (quote (a b c)) #t)

?

Thank you

epsilon
  • 73
  • 8
  • Perhaps you are confusing `'()` and `NIL` as both 'false' from CommonLisp. In Scheme `'()` is not a boolean. – GoZoner Mar 16 '14 at 05:13
  • 3
    Is there some reason that you can't type this into a Scheme prompt and see what `(cons '(a b c) #f)` returns? – Joshua Taylor Mar 16 '14 at 20:54

2 Answers2

5

The first expression will not evaluate to ((a b c)) in most interpreters, it seems that your interpreter is evaluating #f as an empty list:

(cons (quote (a b c)) '())
=> '((a b c))

Having said that, you just substituted a #f with a #t, the standard results will look like this:

(cons (quote (a b c)) #f)
=> '((a b c) . #f)

(cons (quote (a b c)) #t)
=> '((a b c) . #t)

Why don't you try it online? in here for instance.

Óscar López
  • 232,561
  • 37
  • 312
  • 386
  • Thank you very much! I am writing a Scheme Interpreter in C, so that was one of the output samples. So if my interpreter is evaluating #f as an empty list, this means that there is nothing special with #t right? – epsilon Mar 15 '14 at 21:16
  • It means two things: that there's nothing special about `#t` and `#f` when building a list, and that your interpreter is evaluating `#f` incorrectly ;) because this expression should be false: `(equal? #f '())`. Perhaps the sample output you were given is wrong? – Óscar López Mar 15 '14 at 21:34
  • Well, it could be wrong, but thats our assignment, so I should do it anyways :) – epsilon Mar 16 '14 at 00:17
  • 1
    @epsilon If that's the case, then your assignment isn't really about Scheme, but some other language in the Lisp family. – Joshua Taylor Mar 16 '14 at 20:56
0

CommonLisp:

* (if '() 'true 'false)
FALSE

Scheme:

> (if '() 'true 'false)
true

And back in CommonLisp:

* (cons (quote (a b c)) nil)
((A B C))
GoZoner
  • 67,920
  • 20
  • 95
  • 145