Apex Predator
Apex Predator

Reputation: 171

Transforming this into an expression

enter image description here

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

Answers (2)

Óscar López
Óscar López

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

Dan D.
Dan D.

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

Related Questions