savior michael
2013-12-17 05:28:04 UTC
ÕâžöÏ°ÌâÊÇÏëʹÓÃlambdaÀŽÊµÏÖcons »¹ÓÐcar cdr.ÎÒ¿ŽÁ˺ßòÅÃ÷°×ÒâÍŒ¡£ÌâÄ¿ÉÏûÓОø³öÏêÏžµÄœâÊÍ¡£
ÊÇ¿ŽÁËŽð°žÖ®ºó²ÅÃ÷°×ÕâÁœžöº¯ÊýÊÇÈçºÎÔËÐеġ£Žð°žÈçÏ£º
;; ex 2.4. Alternate procedural rep of pairs.
;; given:
(define (cons a b)
(lambda (m) (m a b)))
;; Commentary: cons returns a function that takes a function of 2 ;; args, a and b. The function will receive the values of a and b ;; passed to cons when cons was called initially.
;; z is a function that takes a 2-arg function. That inner function ;; will be passed p and q in that order, so just return the first arg, p. (define (car z)
(z (lambda (p q) p)))
;; ... so this is obvious. (define (cdr z)
(z (lambda (p q) q)))
;; Usage: (define x (cons 3 4))
(car x)
(cdr x)
ÎÒÏëžÄ³Écommon lispµÄʵÏÖ£¬ÐŽÁË°ëÌìҲûÓÐÐŽ³öÀŽ¡£ÇóœÌŽóÉñÖžµã¡£
ÊÇ¿ŽÁËŽð°žÖ®ºó²ÅÃ÷°×ÕâÁœžöº¯ÊýÊÇÈçºÎÔËÐеġ£Žð°žÈçÏ£º
;; ex 2.4. Alternate procedural rep of pairs.
;; given:
(define (cons a b)
(lambda (m) (m a b)))
;; Commentary: cons returns a function that takes a function of 2 ;; args, a and b. The function will receive the values of a and b ;; passed to cons when cons was called initially.
;; z is a function that takes a 2-arg function. That inner function ;; will be passed p and q in that order, so just return the first arg, p. (define (car z)
(z (lambda (p q) p)))
;; ... so this is obvious. (define (cdr z)
(z (lambda (p q) q)))
;; Usage: (define x (cons 3 4))
(car x)
(cdr x)
ÎÒÏëžÄ³Écommon lispµÄʵÏÖ£¬ÐŽÁË°ëÌìҲûÓÐÐŽ³öÀŽ¡£ÇóœÌŽóÉñÖžµã¡£
--
--
Lisp-cn(LispÖÐÎÄÓû§×é)
CLUG http://lisp.org.cn
---
ÄúÊÕµœŽËÓÊŒþÊÇÒòΪÄú¶©ÔÄÁË Google ÍøÉÏÂÛ̳µÄ¡°Lisp-cn(LispÖÐÎÄÓû§×é)¡±ÂÛ̳¡£
ÒªÍ˶©ŽËÂÛ̳²¢Í£Ö¹œÓÊÕŽËÂÛ̳µÄµç×ÓÓÊŒþ£¬Çë·¢Ë͵ç×ÓÓÊŒþµœ lisp-cn+***@googlegroups.com¡£
Òª²é¿Žžü¶àÑ¡ÏÇë·ÃÎÊ https://groups.google.com/groups/opt_out¡£
--
Lisp-cn(LispÖÐÎÄÓû§×é)
CLUG http://lisp.org.cn
---
ÄúÊÕµœŽËÓÊŒþÊÇÒòΪÄú¶©ÔÄÁË Google ÍøÉÏÂÛ̳µÄ¡°Lisp-cn(LispÖÐÎÄÓû§×é)¡±ÂÛ̳¡£
ÒªÍ˶©ŽËÂÛ̳²¢Í£Ö¹œÓÊÕŽËÂÛ̳µÄµç×ÓÓÊŒþ£¬Çë·¢Ë͵ç×ÓÓÊŒþµœ lisp-cn+***@googlegroups.com¡£
Òª²é¿Žžü¶àÑ¡ÏÇë·ÃÎÊ https://groups.google.com/groups/opt_out¡£