[racket] Macros as a first class objects?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri Aug 13 09:58:14 EDT 2010

1. The generally accepted terminology in PL says an object is first-class if the value can flow into functions, out of functions, into data structures (lists, arrays, hashes, etc) and out of them, etc. People do make exceptions and do not insist that such a value can flow thru 'write' and 'read'. 

2. Depending on the time, you can think of compile-time first-class values or run-time first-class values. Unless you qualify the phrase, the latter is meant. 

3. As for macros, you need to distinguish the idea of the macro (cond) vs the syntax function that implements it. The latter could easily be made available at any time and can be passed around. That's not what the OP is asking about. 

4. When you think about macros as syntax and when you realize that syntax no longer exists at run-time, it makes no sense whatsoever to formulate the question. It doesn't denote. {Conduct the following thought experiment: (map if '(a b) '(1 2) '(% $)) .}

5. Having said all this, the OP should follow Shriram's advice and read up on FEXPRS (starting with why Lisp had it and threw it out) as well as REFLECTION (3Lisp). 

-- Matthias

On Aug 13, 2010, at 8:41 AM, Thomas Chust wrote:

> 2010/8/13 The Configurator <configurator at gmail.com>:
>> There must be great reasons why this would be horribly wrong, but why
>> shouldn't macros and syntaxes be passed as first class objects, method
>> parameters, return values etc.?
>> [...]
> Hello,
> somehow I must be misunderstanding this question — in my eyes macros
> and syntax *are* first class objects in Racket: A macro is just a
> procedure operating on syntax objects and a syntax object is just an
> instance of a certain structure type.
> The distinction between a "macro" and a "regular procedure" cannot be
> made based on the type of the object but only based on whether it is
> (potentially) executed during expansion or during runtime. If the
> distinction between these phases was removed you would get a different
> programming language, but I don't think it would make any sense at all
> to talk about "macros" in that language.
> Ciao,
> Thomas
> -- 
> When C++ is your hammer, every problem looks like your thumb.
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Posted on the users mailing list.