正在加载图片...
expl (1oop)))) here test, expl, exp2,., expn can be arbitrary expressions Hence one way to implement the transformation is as a procedure, which takes the until expression and returns the transformed expression define (until->transformed exp) (let ((test (cadr exp)) (other-exps (cddr exp))) (list f let (list ' define test (cons ' begin (append other-exps (list (loop))))) (1。op)))) This is the direct way of creating the transform. You should check it through carefully to see how the use of list and quote will create an appropriate expression. This form is also a bit cumbersome, because we have to do so much direct list manipulation Optional Material: Quasiquote, Unquote, Unquote-splicing Here is an alternative method called quasiquote. note that this is much hairer don't feel you have to use this approach as the version above is perfectly fine However, you can check out the Scheme reference manual for more details on quasiquote (define (until->transformed exp) (let ((test (cadr exp)) (other-exps (cddr exp))) (1et() (define (loop) (主f,test done (begin ,G (1oop)))) (1oop)))) As this example illustrates, the special syntax characters backquote(),comma (), and at-sign(@) are extremely useful in writing syntactic transformations... expn (loop)))) (loop)) where test, exp1, exp2, ..., expn can be arbitrary expressions. Hence one way to implement the transformation is as a procedure, which takes the until expression and returns the transformed expression. (define (until->transformed exp) (let ((test (cadr exp)) (other-exps (cddr exp))) (list 'let '() (list 'define '(loop) (list 'if test ''done (cons 'begin (append other-exps (list '(loop)))))) '(loop)))) This is the direct way of creating the transform. You should check it through carefully to see how the use of list and quote will create an appropriate expression. This form is also a bit cumbersome, because we have to do so much direct list manipulation. Optional Material: Quasiquote, Unquote, Unquote-splicing Here is an alternative method called quasiquote. Note that this is much hairer - - don't feel you have to use this approach as the version above is perfectly fine! However, you can check out the Scheme reference manual for more details on quasiquote. (define (until->transformed exp) (let ((test (cadr exp)) (other-exps (cddr exp))) `(let () (define (loop) (if ,test 'done (begin ,@other-exps (loop)))) (loop)))) As this example illustrates, the special syntax characters backquote (`), comma (,), and at-sign (@) are extremely useful in writing syntactic transformations
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有