Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #3614

Re: macro expansion ?

From Chris Hinsley <chris.hinsley@gmail.com>
Newsgroups comp.lang.forth
Date 2011-06-28 20:39 +0100
Message-ID <2011062820391536125-chrishinsley@gmailcom> (permalink)
References <2011062814435882049-chrishinsley@gmailcom> <o56dncRbu8HmuZfTnZ2dnUVZ_uidnZ2d@supernews.com>
Subject Re: macro expansion ?

Show all headers | View raw


On 2011-06-28 19:59:06 +0100, Elizabeth D Rather said:

> On 6/28/11 3:43 AM, Chris Hinsley wrote:
>> From the recent thread on IMMEDIATE I quote this word:
>> 
>> \ macros
>> : MACRO ( "name" <ccccc"> -- )
>> CREATE ," IMMEDIATE DOES> COUNT EVALUATE ;
>> 
>> When I first added this word to my Forth project I belived it would
>> allow me to define words that were 'macro expanded' in a text
>> substitution manner.
>> 
>> Is this indead the case ? The call to EVALUATE made me think this would
>> act as if it was text substitution rather than just a IMMIDEATE word
>> that would execute during compilation. My intention was somthing that
>> would be expanded during compilation and therefore may get optimised as
>> inlined code into the word curently deing defined, so no subroutine call
>> overhead.
> 
> Whether it compiles something would depend on whether it's used in 
> compile state, obviously.  The use of EVALUATE has a potential 
> side-effect in that if a word in the string has been redefined, you'll 
> get the most recent version, whereas when you compile a definition you 
> always have the version that was current at the time it was compiled.

I see the possibility of redefintion during expansion as a feature, not 
a problem. !

> 
>> Clearly it suffers from haveing a single " being scanned for the end of
>> the evaluated string, but that could be improved maybe ?
>> 
>> But this led me on to thinking how would I do a more Lisp like macro ?
>> Somthing that would be expanded and then that expantion expanded till
>> there was no more expantions. One of the thoughs that's bothering me on
>> this is what happens if the expansion leads to new words needing to be
>> defined within a partial expansion, and then on the next expantion pass
>> they are executed, all this while not yet finishing the definition of
>> the original word that used the macro in the first place ?
>> 
>> I would like to resolve these thoughts with any help from the Forth
>> GURU's out there. :)
> 
> My big question is, why do you want to do this?  If it's an academic 
> exercise, to just see if it's possible, that's one thing: enjoy. But 
> I'm not very enamored of macros in general, because they're often a 
> substitute for "programming by copy/paste" which is a pernicious 
> practice.  People do it in languages where a CALL (and surrounding 
> setup, etc.) is costly, but given that the entire architecture of Forth 
> is designed to minimize the cost of a call, I really don't see the 
> point as a practical matter.
> 
> Cheers,
> Elizabeth

It's not an academic exersise ! At least not the way I see it. I 
disagree that CALL is cheap ! It is on your own Forth CPU, it's not on 
a general RISC chip.

I would like to have the ability to have a powerfull macro system that 
works at the source level. Somthing like what LISP has, or (forgive me 
mentioning it) C++ templates. Before the Forth compiler starts to lay 
down the definition of a word I wish to have text substitution happen, 
I want the full power of Forth to be available during the expansion to 
manipulate the source. I don't seam to be able to do this in a simple 
way useing what's available within the language itself ?

Chris

Back to comp.lang.forth | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 14:43 +0100
  Re: macro expansion ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-06-28 10:58 -0500
    Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 18:34 +0100
      Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 18:51 +0100
        Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 19:02 +0100
          Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 19:11 +0100
            Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 19:17 +0100
              Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 19:47 +0100
                Re: macro expansion ? Josh Grams <josh@qualdan.com> - 2011-06-29 15:34 +0000
                Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 19:21 +0100
            Re: macro expansion ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-06-29 03:15 -0500
              Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 13:11 +0100
            Re: macro expansion ? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-06-29 17:17 +0100
              Re: macro expansion ? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-06-29 18:09 +0100
                Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 19:32 +0100
                Re: macro expansion ? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-07-02 08:48 +0100
    Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 00:44 +0100
    Re: macro expansion ? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2011-06-29 20:39 +0100
  Re: macro expansion ? Elizabeth D Rather <erather@forth.com> - 2011-06-28 08:59 -1000
    Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 20:39 +0100
      Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-28 21:34 +0100
        Re: macro expansion ? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2011-06-29 03:26 -0500
  Re: macro expansion ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-06-29 11:25 +0000
    Re: macro expansion ? Chris Hinsley <chris.hinsley@gmail.com> - 2011-06-29 13:24 +0100
      Re: macro expansion ? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2011-07-03 14:02 +0000
    Re: macro expansion ? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2011-06-29 18:48 +0000
  Re: macro expansion ? BruceMcF <agila61@netscape.net> - 2011-06-30 11:11 -0700
  Re: macro expansion ? Ian Osgood <iano@quirkster.com> - 2011-07-02 16:22 -0700
  Re: macro expansion ? Hugh Aguilar <hughaguilar96@yahoo.com> - 2011-07-05 17:35 -0700

csiph-web