Thanks a lot guys.<div><br></div><div>As Eli pointed out, the main objective here is to use the special identifiers as macros, so I'll take a look at his suggestion.</div><div><br></div><div>Basically, @anything is used as a macro for dsl-style variable assignments: ie, </div>
<div>@x = something, @y = something</div><div>Here '@' is the macro, and the rest of it is parsed out and stores 'x' or 'y' in local scope.</div><div><br></div><div>Similarly, I'd like a macro $something, $something-else, where '$' is the macro for a kind of named action that has special properties.</div>
<div><br></div><div>I could make these work as (@ x = 2) or ($ call-my-action), but would prefer the token to be self-contained as in (@x = 2) or ($do-something).</div><div><br></div><div>Scott.<br><br><div class="gmail_quote">
On Sun, Jan 27, 2013 at 1:08 AM, Eli Barzilay <span dir="ltr"><<a href="mailto:eli@barzilay.org" target="_blank">eli@barzilay.org</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 Wednesday, Scott Klarenbach wrote:<br>
> Is it possible to have a macro bound to an identifier with wildcards<br>
> in it?<br>
><br>
> So, for example, a macro (@*) that would be used for (@x) and (@y),<br>
> where the symbols x and y are available during expansion.<br>
><br>
> Or is this something that would have to be done at the reader level?<br>
> ie, (@ ...) is the macro, and the reader turns @x and @y into (@ x)<br>
> and (@ y) respectively.<br>
<br>
</div>This is possibly irrelevant, but since there were some pointers in a<br>
direction that is not doing the above:<br>
<br>
1. You should try to avoid doing this at the reader level as much as<br>
possible. If you're trying to replace `@foo' by something else,<br>
then you can easily run into a mess when these things are quoted<br>
etc. In addition, since you're at the reader level, you cannot<br>
know if you're looking at something which is any other kind of<br>
non-expression, like argument names etc.<br>
<br>
(This is from experience: a previous attempt at the scribble reader<br>
was reading @foo{blah} as (dispatch foo "blah"). It was<br>
problematic for these reasons.)<br>
<br>
2. Identifier macros don't seem so helpful either, since they're used<br>
as bindings for known names.<br>
<br>
3. Using `#%top' might work, if you want the bindings of the<br>
wildcard-ed @foo identifiers to be values as in Danny's example,<br>
but it won't work if you want them to be macros.<br>
<br>
So if you really want them to be macros, then I think that your best<br>
bet is to hook into both the `#%top' and the `#%app' macros, the<br>
former to identify cases where you want (.... @foo ....) to expand to<br>
some (.... "at-foo" ....), and the latter to identify cases where you<br>
want (@foo ....) to get expanded to something else (that is, not just<br>
expand the @foo as in the identifier case).<br>
<br>
Here's an example that shows how both are used -- for fun, I made two<br>
things magical, `foo%' identifiers, and `@foo' things that were read<br>
by the scribble reader (which can be identified via a syntax<br>
property).<br>
<br>
<br>
-------------------------------------------------------------------------------<br>
#lang at-exp racket/base<br>
<br>
(module magic racket/base<br>
<br>
(provide (rename-out [top #%top] [app #%app]))<br>
<br>
(require (for-syntax racket/base))<br>
<br>
(define-for-syntax (magical? id)<br>
(and (identifier? id)<br>
(regexp-match? #rx"%$" (symbol->string (syntax-e id)))))<br>
<br>
(define-syntax (top stx)<br>
(syntax-case stx ()<br>
[(_ . id)<br>
(cond [(magical? #'id) #''id]<br>
[(syntax-property stx 'scribble) #''id]<br>
[else #'id])]))<br>
<br>
(define-syntax (app stx)<br>
(syntax-case stx ()<br>
[(_ id x ...)<br>
(cond [(magical? #'id) #'(vector 'id x ...)]<br>
[(syntax-property stx 'scribble) #'(list 'id x ...)]<br>
[else #'(id x ...)])]))<br>
<br>
)<br>
<br>
(require 'magic)<br>
<br>
blah%<br>
(blah% 1 2 3)<br>
@blah<br>
@blah{zzz}<br>
-------------------------------------------------------------------------------<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:<br>
<a href="http://barzilay.org/" target="_blank">http://barzilay.org/</a> Maze is Life!<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Talk to you soon,<br><br>Scott Klarenbach<br><br>PointyHat Software Corp.<br><a href="http://www.pointyhat.ca" target="_blank">www.pointyhat.ca</a><br>
p 604-568-4280<br>e <a href="mailto:scott@pointyhat.ca" target="_blank">scott@pointyhat.ca</a><br>#308 - 55 Water St.<br>Vancouver, BC V6B1A1<br><br>_______________________________________<br>To iterate is human; to recur, divine
</div>