Are macros relevant in lazy functional languages? 
Author Message
 Are macros relevant in lazy functional languages?

Sometime ago, a C++ programmer asks me what is that macros can do
while inline functions can't. My answer is like that, but it is not
really relevant to him as a C++ programmer. Anyway.

My answer is that, to put it simply, if you don't have a, say, switch
statment in your language, then only macros can give it to you from
more primitive if statement, while inline functions can't do that for
you.

To put it in the context of Scheme, a function call is something like
(f a b c), if do is implemented as a function call based on other
primitives, you have to call it as (do '((v i s)) '(t r) 'e1 'e2),
ie., the quote is needed which really is not pretty. But if do is
implemented as a macro, then you don't need the quote and can write in
a more natural way.

First, is the above of my understanding correct?

Second, if the above is correct, then, back to the subject of this
post, is macro relevant for a lazy functional language?

Thanks for your time and patience to read this! Please clarify this
issue for me! Thank you!



Tue, 12 Jul 2005 00:17:20 GMT  
 Are macros relevant in lazy functional languages?

Quote:

> Sometime ago, a C++ programmer asks me what is that macros can do
> while inline functions can't.

The hot topic in the C++ community right now is using templates to do
"metaprogramming"--that is, tricking the template instantiation
mechanism into generating computer code which is subsequently compiled.
Scheme and lisp macros are about metaprogramming, only it's way beyond
what can be done in C++. Your analysis is correct, but it's only the
beginning.

-thant



Tue, 12 Jul 2005 01:03:01 GMT  
 Are macros relevant in lazy functional languages?

Quote:

> To put it in the context of Scheme, a function call is something like
> (f a b c), if do is implemented as a function call based on other
> primitives, you have to call it as (do '((v i s)) '(t r) 'e1 'e2),
> ie., the quote is needed which really is not pretty. But if do is
> implemented as a macro, then you don't need the quote and can write in
> a more natural way.

> First, is the above of my understanding correct?

Yes.

Quote:
> Second, if the above is correct, then, back to the subject of this
> post, is macro relevant for a lazy functional language?

Yes.  Consider a test harness macro that not only runs the code, but
also prints a string to a log file that describes the code being run.


Tue, 12 Jul 2005 03:28:51 GMT  
 Are macros relevant in lazy functional languages?

R there ny,,....
i m a newbie and have no idea bout that
links or library names required...

thanks for ny help

--
=============================================================================
        .--.                                                        
       |o_o |          
       |:_/ |          choose a job you love,and you will never
      //   \ \         have to work a day in your life          
     (|harsh|)                                                  
    /'\_   _/`\                      
    \___)=(___/                                                  

=============================================================================



Tue, 12 Jul 2005 03:56:21 GMT  
 Are macros relevant in lazy functional languages?

Quote:

> Yes.  Consider a test harness macro that not only runs the code, but
> also prints a string to a log file that describes the code being run.

That's right! This is just another cute application of macros.

Thanks for the clarification!



Tue, 12 Jul 2005 07:15:23 GMT  
 Are macros relevant in lazy functional languages?

Quote:

> Scheme and lisp macros are about metaprogramming, only it's way beyond
> what can be done in C++.

Yes and no.  Constant expressions in C++ template expressions get
evaluated at compile time, which gives you the ability to implement
numerical computations at compile time.  Scheme doesn't have a concept
of constant expressions, so this can't be done without extreme effort.


Tue, 12 Jul 2005 09:13:24 GMT  
 Are macros relevant in lazy functional languages?

Quote:


>> Scheme and lisp macros are about metaprogramming, only it's way beyond
>> what can be done in C++.

> Yes and no.  Constant expressions in C++ template expressions get
> evaluated at compile time, which gives you the ability to implement
> numerical computations at compile time.  Scheme doesn't have a concept
> of constant expressions, so this can't be done without extreme effort.

Not sure I understand. When I build a Scheme macro, I have the full
power of the language available. Macros can use values produced before
the macro itself is evaluated. How is this inferior to C++'s
template-langauge constant expressions?

If C++'s macros have any advantage over Scheme's, it's derived from
their tie-in with C++'s type system.

-thant



Tue, 12 Jul 2005 09:56:41 GMT  
 Are macros relevant in lazy functional languages?

[...]

Quote:
> If C++'s macros have any advantage over Scheme's, it's derived from
> their tie-in with C++'s type system.

Of course that should be "...C++'s templates...", not "...C++'s macros...".

-thant



Tue, 12 Jul 2005 09:58:03 GMT  
 Are macros relevant in lazy functional languages?

Quote:

> Not sure I understand. When I build a Scheme macro, I have the full
> power of the language available.

What sort of "Scheme macro" are you referring to?  R5RS macros certainly
don't have this.  Some Scheme implementations have a low level macro
system with more power (at least in a practical if not theoretical sense).


Tue, 12 Jul 2005 10:00:30 GMT  
 Are macros relevant in lazy functional languages?

Quote:

> Sometime ago, a C++ programmer asks me what is that macros can do
> while inline functions can't. My answer is like that, but it is not
> really relevant to him as a C++ programmer. Anyway.

> My answer is that, to put it simply, if you don't have a, say, switch
> statment in your language, then only macros can give it to you from
> more primitive if statement, while inline functions can't do that for
> you.

> To put it in the context of Scheme, a function call is something like
> (f a b c), if do is implemented as a function call based on other
> primitives, you have to call it as (do '((v i s)) '(t r) 'e1 'e2),
> ie., the quote is needed which really is not pretty. But if do is
> implemented as a macro, then you don't need the quote and can write in
> a more natural way.

> First, is the above of my understanding correct?

> Second, if the above is correct, then, back to the subject of this
> post, is macro relevant for a lazy functional language?

One word (a really long word ;):
http://research.microsoft.com/~simonpj/papers/meta-haskell

Though I'd say it's slightly less necessary in a lazy functional
language (don't need to worry about eager evaluation of 1/0, e.g. if
can be a function instead of a special form).



Tue, 12 Jul 2005 14:54:14 GMT  
 Are macros relevant in lazy functional languages?

Quote:


>> Not sure I understand. When I build a Scheme macro, I have the full
>> power of the language available.

> What sort of "Scheme macro" are you referring to?  R5RS macros certainly
> don't have this.  Some Scheme implementations have a low level macro
> system with more power (at least in a practical if not theoretical sense).

Is this your way of starting a conversation about how the current
standard leaves something to be desired?

My experience actually predates the R5RS when technically there was no
standard macro system. I used, among other things, syntax-case. If I
remember correctly, it didn't have the limitation you allude to despite
being high level. I must sadly admit, however, that I've completely
forgotten how to use it.

-thant



Tue, 12 Jul 2005 21:31:20 GMT  
 Are macros relevant in lazy functional languages?
Several years back, Richard Mann used FFIGEN to parse the header
files for Xlib and OpenGL and write a set of signature files in
S-expression format. He then wrote a collection of macros for a
number of Scheme and Common Lisp implementations that
automatically generate the FFI declarations for Xlib and OpenGL in
those implementations. This provides a cross-platform compatible
API for Xlib and OpenGL. I believe he did this for GCL, AllegroCL,
Scheme->C, Stalin, and perhaps others. It should be straightforward
to adapt this to any other Common Lisp or Scheme implementation
that provides an FFI that supports passing and return scalar
objects.

http://tapir-server.uwaterloo.ca/~mannr/software.html



Tue, 12 Jul 2005 22:57:32 GMT  
 
 [ 28 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Speed of FP languages, prospects (was Re: Benchmarking Lazy Functional Languages)

2. multiplatform GUI design with parallelized lazy functional language

3. Lazy and Strict Functional languages

4. Benchmarking Lazy Functional Languages

5. Partial Evaluation for Lazy Functional Languages

6. Monitoring (Lazy) Functional Languages

7. Profiling Lazy Functional Languages

8. Time complexity of lazy programs. profiling functional languages

9. Lazy-evaluation functional language for MS DOS

10. Applications for lazy functional languages

11. Functional Programming Languages with Lazy Evaluation

12. Parial Evaluation & Lazy Functional Language

 

 
Powered by phpBB® Forum Software