[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: need for macros (was Re: Icon)



I've never been able to come up with a list of what you
can use macros for.  I continue to be surprised by what
you can do with them.  For example, at one point in 
the Arc code I'm writing I needed to create a block with
a unique identifier, so I know which button someone
clicked.  The code is going to be evaluated multiple
times and the identifier associated with each button has
to be the same.  Answer: create the identifier at compile-
time:

(mac with-unique-id (var . body)
  `(let ,var ',(unique-id)
     ,.body))

where unique-id is a function that returns an id-string 
guaranteed (since starting Arc) to be unique.  Then you
can say in the code that makes the html page

(with-unique-id x
  ...
  (input type 'submit value "Submit" name x)
  ...)

And every button everywhere in your code has a single
distinct name.

This use of macros doesn't seem to be on your list.


--- Matthias Felleisen <matthias@ccs.neu.edu> wrote:
> 
> la@iki.fi writes: 
> 
>   Note that there is no need for any syntax transformations, this is
> pure
>   Haskell. You can get surprisingly far without macros when just
> about
>   everything is a first-class value...
> 
> That's not true. There are three reasons for introducing a syntactic
> abstraction (macro) rather than a function:
> 
>  1. new binding forms
>  2. implicit quoting or, more generally, a data sub-language
>  3. an order of evaluation that is incompatible with evaluation 
> 
> A lazy language makes macros fro 3 unnecessary. A function with
> first-class
> functions still needs macros for 1; otherwise you keep writing 
>   foo (fn x => ...)
> all over the place. 
> 
> -- Matthias
> 
>   
> 


__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com