DrRacket中的宏步进 [英] Macro stepper in DrRacket

查看:50
本文介绍了DrRacket中的宏步进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在链接上 http://www.ccs.neu.edu/home/ryanc/macro-stepper/tutorial.html 有使用宏步进器的说明.

On the link http://www.ccs.neu.edu/home/ryanc/macro-stepper/tutorial.html there are instructions for working with the macro stepper.

但是,当我尝试使用它时,我无法在非零的定义中得到myor的第二次扩展?功能,只有第一位.另外,我没有按钮上一个词"和下一个词".

However, when I'm going to try it, I can't get the second expansion of myor in the definition of nonzero? function, only the first. Also, I have no buttons "Previous term" and "Next term".

所以我的问题是:我必须如何配置宏步进器才能进行第二次扩展,就像在教程中一样?

So my question is: how i must configure macro stepper to get the second expansion, like in tutorial?

推荐答案

我假设您的源程序看起来像这样:

I'm assuming that your source program looked something like this:

#lang racket
(define-syntax myor
  (syntax-rules ()
    [(myor e) e]
    [(myor e1 . es)
     (let ([r e1]) (if r r (myor . es)))]))
(define (nonzero? r)
  (myor (negative? r)
        (positive? r)))

简短的故事:暂时使用syntax-case 而不是syntax-rules;似乎有一些与宏步进器和语法规则相关的错误.我已经将错误报告发送给了Racket开发人员,因此希望很快会解决.上面程序的语法大小写版本如下.

Short story: use syntax-case rather than syntax-rules for the moment; there appears to be some bug associated with the Macro stepper and syntax-rules. I've sent along a bug report to the Racket developers, so hopefully this will be fixed soon. The syntax-case version of the above program looks like this.

#lang racket

(define-syntax (myor stx)
  (syntax-case stx ()
    [(_ e) #'e]
    [(_ e1 . es)
     #'(let ([r e1]) (if r r (myor . es)))]))

(define (nonzero? r)
  (myor (negative? r)
        (positive? r)))


下面是更长的故事...


Below is the longer story...

当我在5.2.1的预发行版中运行程序时,在宏步进器中看到以下内容,宏隐藏设置为标准":

When I run your program under the pre-release of 5.2.1, I see the following in the Macro Stepper, with Macro hiding set to "Standard":

(module anonymous-module racket
  (#%module-begin
   (define-syntax myor
     (syntax-rules () [(myor e) e] [(myor e1 . es) (let ([r e1]) (if r r (myor . es)))]))
   (define (nonzero? r)
     (let:26 ([r:26 (negative? r)]) (if:26 r:26 r:26 (myor:26 (positive? r)))))))

这看起来不对.它仅将 myor 的一种用法扩展为 if 的用法.很奇怪!

which looks wrong. It expands only one use of myor out to uses of if. Very odd!

让我们看看在球拍5.2下是什么样子...

Let's see what things look like under Racket 5.2...

(module anonymous-module racket
  (#%module-begin
   (define-syntax myor
     (syntax-rules () [(myor e) e] [(myor e1 . es) (let ([r e1]) (if r r (myor . es)))]))
   (define (nonzero? r) (let ([r (negative? r)]) (if r r (myor (positive? r)))))))

啊.好的,我可以确认我看到的是与Racket 5.2和预发行版中相同的问题.

Ah. Ok, I can confirm that I see the same problem that you see in Racket 5.2, as well as the pre-release.

该错误似乎与宏隐藏"功能的行为有关,该功能在设置为标准"时尝试不使您完全扩展.如果将其设置为"Disabled",您将看到宏调试器将以完整无损的荣耀显示扩展,并且确实包含了我们期望看到的扩展:

The bug seems related to the behavior of the "Macro hiding" feature, which tries to not overwhelm you with the full expansion when it is set to Standard. If you set it to "Disabled", you'll see that the macro debugger will show the expansion in its full, unvarnished glory, and it does include the expansion that we expect to see:

(module anonymous-module racket
  (#%module-begin
   (define-syntaxes (myor)
     (lambda (x)
        ; ... I'm omitting the content here: it's way too long.
     ))
   (define-values:20 (nonzero?)
     (lambda:21 (r) (let-values:22 (((r) (#%app:23 negative? r))) (if r r (#%app:24 positive? r)))))))

我将编写一个错误报告并发送交给Racket开发人员.

I'll write a bug report and send it to the Racket developers.

如果您使用 syntax-case (语法大小写)写宏,而不是 syntax-rules (语法规则),那么它与Macro Stepper一起使用似乎效果更好.

If you write your macro using syntax-case, as opposed to syntax-rules, it appears to work better with the Macro Stepper.

#lang racket

(define-syntax (myor stx)
  (syntax-case stx ()
    [(_ e) #'e]
    [(_ e1 . es)
     #'(let ([r e1]) (if r r (myor . es)))]))

(define (nonzero? r)
  (myor (negative? r)
        (positive? r)))

当我逐步执行此操作时,它似乎工作得更好.因此,无论触发该错误的原因是什么,它似乎都与Macro Stepper和 syntax-rules (语法规则)发生了相互作用.因此,请尝试改用语法大小写.

When I step through this, it appears to work a lot better. So whatever is triggering the bug, it appears to be some interaction with the Macro Stepper and syntax-rules. So try using syntax-case instead.

这篇关于DrRacket中的宏步进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆