May 23th Wednesday (五月 二十三日 水曜日)

The "(map proc list1 ...)" applies a procedure element-wise to the elements of the lists and
returns a list of the results, in order.  The dynamic order in which the procedure is applied
to the elements of the lists is unspecified.

  But the "(for-each proc list1 ...)" is guaranteed to call "proc" on the elements of the "lists"
in order from the first element(s) to the last, and the value returned by "for-each" is unspecified.

  The "(apply proc arg1 ...)", calls "proc" with the elements of the arguments list as the actual
arguments.

(define-syntax with-syntax
  (lambda (x)
    (syntax-case x ()
      ((_ ((p e0) e1 e2 ...))
       (syntax (syntax-case (list e0 ...) ()
                 ((p ...) (begin e1 e2 ...))))))))

(define-syntax loop
  (lambda (x)
    (syntax-case x ()
      ((k e ...)
       (with-syntax ((break (datum->syntax-object (syntax k) 'break)))
         (syntax (call/cc (lambda (break)
                            (let f () e ... (f))))))))))

  Let's come back to the "with-syntax" again.  Firstly, there is a discrepancy between the environment
of defining a macro "loop" and the enivronment of invoking the macro "loop".

(syntax (call/cc (lambda (break)
                          (let f () e ... (f)))))

  The above codes is a classic loop and break segment in scheme.  For escaping from a loop, there is
a current continutaion.  How to put a invoked current continuation into the "with-syntax" macro.

(break (datum->syntax-object (syntax k) 'break))

  This is a key code.  It binds a invoking environment to a 'break label.  Now the "with-syntax" can
matchs its pattern with it.

(_ ((p e0) e1 e2 ...))

  The "_" is "with-syntax" macro name.  The (p e0) matched (break (datum->syntax-object (syntax k) 'break)).
The "p" is 'break now.  So, in actual fact, (p ...) is (break ...).  First "p" matched from "with-syntax"'s
pattern matched; second "p" must matched pattern from (list e0 ...).  In (list e0 ...) there is a
invoking current continuation.  Okey, the rest codes can escape from a loop by using the current continuation. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值