DrRacket 中的宏步进器

发布于 2024-12-28 06:05:18 字数 298 浏览 2 评论 0原文

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

但是,当我要尝试时,我无法在非零的定义中得到 myor 的第二次展开?函数,只有第一个。另外,我没有“上一学期”和“下一学期”按钮。

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吻泪 2025-01-04 06:05:18

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

#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 开发人员发送了错误报告 ,所以希望这个问题能尽快得到解决。上述程序的syntax-case版本如下所示。

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

下面是更长的故事...

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

(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 的用法。很奇怪!

让我们看看 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 以及预发行版中看到的相同问题。

该错误似乎与“宏隐藏”功能的行为有关,该功能在设置为标准时试图不让您因完整扩展而不知所措。如果将其设置为“禁用”,您将看到宏调试器将显示扩展的完整、不加修饰的荣耀,并且它确实包含我们期望看到的扩展:

(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 开发人员。

如果您使用syntax-case(而不是syntax-rules)编写宏,则它似乎与宏步进器配合使用效果更好。

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

当我完成这个步骤时,它似乎工作得更好。因此,无论触发该错误的是什么,它似乎都是与宏步进器和语法规则的某种交互。因此,请尝试使用 syntax-case 代替。

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

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...

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

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

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

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

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

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

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

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.

巾帼英雄 2025-01-04 06:05:18

它对我有用,无需做任何额外的事情。尝试使用最新版本的 Racket,也尝试从菜单中选择不同的语言,并确保为您选择的语言选择了调试

It worked for me without having to do anything additional. Try with the newest version of Racket, also try choosing a different language from the menu, and make sure that debugging is selected for the language you select.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文