January 9 2007 火曜日

  Yesterday evening I eventually get the root of that strange phenomenon.  There is rule that all schedule
commands must be sorted, in other words, every schedule command, except for the last, must be more early
than its latter; each schedule command, except for the first, must be more later than its former.  They
are a good sequence.

  However, I set the default zero value to initialize a schedule command.  Obviously, I made a mistaken.
When sending a schedule command out, because other three commands was filled zeros there are not a good
sequence again.  As matter of a fact, I always send four schedule command out how many commands is in a
schedule file.

  Today I reviewed the syntax macro "with-syntax".  I downloaded codes from Wangyin, my a friend.

(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))))))))))

  The "loop" macro is used to help us understand "with-syntax".  When I met the "with-syntax" firstly,
I felt that I can met a monster.  But it is not monstrous.  For above example, we can know "break" is
used to jump out a loop, a instance of "loop" macro.  The key is following.

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

  Let's get the "with-syntax" inside.  ((_ ((p e0) ...) e1 e2 ...)  The "_" matched "with-syntax",
macro name.  ((break (datum->syntax-object (syntax k) 'break))) is matched by ((p e0) ...).
The e1 e2 ... is those statements in a loop.  They are not a key point to understand.  It is uncomfortable
that the second (syntax-case ...), it is embeded into the first.  But it just power.

  Let's call up how to use the "syntax-case".  (syntax x () ...).  Yes, there is a "x".  So, do you know
why there is a (list e0 ...) put inside the second (syntax-case ...).  In that way, our second (syntax-case ...)
can work correctly.  In my viewpoint, there is a anonymous macro like following code.

(define-syntax break
  (lambda ()
    (syntax-case s ()
      ((_ ...) (begin e1 e2 ...)))))

  In "with-syntax" macro, we used "p" as a symbol variable to represent variant names.  So, the "p" is
used to matched a macro name, this macro name must be in a syntax object.  (datum->syntax-object (syntax k) 'break)
is necessary.  OK.  "'break" is just the macro name.

  Why use (list e0 ...)?  The (list e0 ...) is used to match "s".  That is the rule of "synax-case". 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值