Scheme macro vs Common Lisp macro

Source: Internet
Author: User

Let macro of Common LISP is defined as follows:

 
(Defmacro our-left (binds & Body) '(lambda, (mapcar #' (lambda (x) (if (consp X) (Car X )) binds), @ body), @ (mapcar # '(lambda (x) (if (consp X) (cadr x) Nil )) binds); (Our-left (x 1) (Y 2) (+ x y) after expansion, it becomes => (lambda (x y) (+ x y) 1 2) here we can easily see that let is actually a Lambda syntactic sugar :)


The let macro of scheme is defined as follows:

 
(Defien-syntax let (syntax-rules () (_ (x V )...) e1 E2 ...) (lambda (X ...) e1 E2 ...) V ...)))) scheme is more elegant and intuitive than the one above. We can see how this let works internally without effort.

Let * macro of scheme is as follows:

 
(Define-syntax my-Let * (syntax-rules () (_ (p v) B ...) (Let (p v) B ...)) (_ (P1 V1) (P2 V2 )...) B ...) (Let (P1 V1) (my-Let * (P2 V2 )...) B ...))))) in fact, the macro of scheme is a pattern match, so we must consider all the situations in advance.

There is really no need to use @ to deconstruct. To see how shceme is handled, there is no need to wrap it first and then deconstruct it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.