So it looks like there are a lot more complicated things going on in define-type and type-case than I naively tried to implement myself. It's probably safer to just do the nice (require (only-in)) thing and not reinvent a worse version of the wheel. Although I did get my particular define-syntax to work as I wanted it to, I'm guessing it could be used in more interesting ways than I anticipated, and cause things to break horribly in ways I don't want.<div>
<br></div><div>Thanks for the tips!<br clear="all"><br>Jeremy<br>
<br><br><div class="gmail_quote">On Sun, Sep 11, 2011 at 1:06 PM, Danny Yoo <span dir="ltr"><<a href="mailto:dyoo@cs.wpi.edu">dyoo@cs.wpi.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Sun, Sep 11, 2011 at 1:44 PM, Jeremy Kun <<a href="mailto:kun.jeremy@gmail.com">kun.jeremy@gmail.com</a>> wrote:<br>
</div><div class="im">> Is there an existing Racket analogue for the "define-type" language form<br>
> from the PLAI text?<br>
<br>
</div>You can pull out specific things from a language or module by using:<br>
<br>
(require (only-in some-module<br>
language-feature-1 language-feature-2 ...))<br>
<br>
<br>
In particular, it looks like you want to pull some of the features of<br>
the PLAI language<br>
<div class="im"><br>
<a href="http://docs.racket-lang.org/plai/plai-scheme.html" target="_blank">http://docs.racket-lang.org/plai/plai-scheme.html</a><br>
<br>
</div>into vanilla racket. Yup, that should work!<br>
<br>
<br>
For example:<br>
<br>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br>
#lang racket<br>
<br>
(require (only-in plai<br>
define-type<br>
type-case))<br>
<div class="im"><br>
(define-type expr<br>
[num (val integer?)]<br>
</div> [sum (lhs expr?)<br>
(rhs expr?)])<br>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;<br>
<div class="im"><br>
<br>
<br>
> Or<br>
> perhaps, is there a way for me to look at the original syntax definitions so<br>
</div>> I can puzzle ovdrer how it's done?<br>
<br>
The PLAI language is written in Racket itself, so you're always<br>
welcome to look at how it's implemented. I think it starts around<br>
here:<br>
<br>
<a href="https://github.com/plt/racket/tree/master/collects/plai" target="_blank">https://github.com/plt/racket/tree/master/collects/plai</a><br>
<br>
You'll see in <a href="https://github.com/plt/racket/blob/master/collects/plai/main.rkt" target="_blank">https://github.com/plt/racket/blob/master/collects/plai/main.rkt</a><br>
that the implementation is made of two modules, one that implements<br>
the datatype stuff, and the other the testing harness. The datatype<br>
library itself (<a href="https://github.com/plt/racket/blob/master/collects/plai/datatype.rkt" target="_blank">https://github.com/plt/racket/blob/master/collects/plai/datatype.rkt</a>)<br>
looks... well.. substantial... :) Might take a while to understand<br>
how it all fits together. We can talk about it more if you'd like.<br>
<br>
<br>
<br>
[cutting your macro code]<br>
<div class="im"><br>
> I get an interesting error along the lines of<br>
><br>
> define-values: illegal use (not at top-level) in: (define-values...<br>
><br>
> I'm guessing it has something to do with the rule that a define-syntax isn't<br>
> allowed to change the surrounding lexical scope<br>
<br>
</div>Yeah; there are certain syntactic contexts<br>
<br>
[see: <a href="http://docs.racket-lang.org/reference/syntax-model.html#(part._expand-context-model)" target="_blank">http://docs.racket-lang.org/reference/syntax-model.html#(part._expand-context-model)</a><br>
for gory details]<br>
<br>
where you're not allowed to have a define-syntax. Expression position<br>
is one of them. The arguments to values are in expression context.<br>
You probably want to use 'begin' here instead, unless I'm<br>
misunderstanding your code?<br>
<div class="im"><br>
<br>
<br>
<br>
> On another note, is there a nice way for me to print out the literal<br>
> expansion performed by define-syntax?<br>
<br>
</div>Have you tried the macro debugger tool in DrRacket yet? The macro<br>
debugger at the DrRacket toolbar lets you step through macro<br>
expansion.<br>
<br>
There are also tools in:<br>
<br>
<a href="http://docs.racket-lang.org/macro-debugger/index.html" target="_blank">http://docs.racket-lang.org/macro-debugger/index.html</a><br>
<br>
that may help.<br>
</blockquote></div><br></div>