Вопрос

L1 = ((A B) C D)
L2 = ((E) F)

The expression I'm supposed to evaluate is: (CONS (CAR L1) (LIST (CDR L2)))

I've traced it out as follows:

(CONS (CAR L1) (LIST (CDR L2)))
(CONS ((A B)) (LIST ((F))))
(CONS ((A B)) (((F))))
((((A B)) (((F)))))

Or (I'm not sure if this is more readable or not, but I've pressed space too many times to back out now):

(
 (
  (
   (A B)
  )
  (
   (
    (F)
   )
  )
 )
)

Is this correct? It just seems like there's entirely too many parentheses, but maybe I'm just being paranoid?

None of the examples I can find have nested lists like this, so I'm really not sure if I'm doing it right.

Thanks

Это было полезно?

Решение

CL-USER 13 > (step (CONS (CAR L1) (LIST (CDR L2))))
(CONS (CAR L1) (LIST (CDR L2))) -> :s
   (CAR L1) -> :s
      L1 -> :s
      ((A B) C D) 
   (A B) 
   (LIST (CDR L2)) -> :s
      (CDR L2) -> :s
         L2 -> :s
         ((E) F) 
      (F) 
   ((F)) 
((A B) (F)) 

Другие советы

It's incorrect. Let's try again.

(car '((a b) c d)) is the datum (a b).

(cdr '((e) f)) (which is the same as (cdr '((e) . (f)))) is the datum (f), which means (list (cdr '((e) f))) is the datum ((f)).

Thus, (cons (car l1) (list (cdr l2))) is the same as (cons '(a b) '((f))), which is the datum ((a b) . ((f))), which is the same as ((a b) (f)).

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top