Reputation: 171
Hi guys i'm wanted to know if i have the correct expression for this picture, if not why please
(a((f(b c))(g h))e)
Upvotes: 1
Views: 46
Reputation: 236004
You're close, but not quite right. It'll be more clear if we build the list structure explicitly using cons
; this is more like it:
(cons 'a
(cons (cons (cons 'f
(cons 'b 'c))
(cons 'g
(cons 'h '())))
(cons 'e '())))
=> '(a ((f b . c) g h) e)
Notice that in this part: (f b . c)
we have an improper list, because the sublist doesn't end in null
.
Upvotes: 3
Reputation: 74645
You answer is incorrect as it doesn't properly express the improper list (f b . c)
. Also the parentheses around g h
are an error.
With dotted pairs the full expression would be:
'(a ((f b . c) g h) e)
Note that '(f b . c)
is not the same as '(f (b c))
.
See that '(f (b c))
is:
(cons 'f (cons (cons 'b (cons 'c '())) '()))
Rather than what '(f b . c)
is:
(cons 'f (cons (cons 'b 'c) '()))
Note the improper list.
Upvotes: 2