문제

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