Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #3609
| From | Chris Hinsley <chris.hinsley@gmail.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Date | 2011-06-28 19:11 +0100 |
| Message-ID | <2011062819111570841-chrishinsley@gmailcom> (permalink) |
| References | <2011062814435882049-chrishinsley@gmailcom> <DLadnaa9famEZ5TTnZ2dnUVZ8v2dnZ2d@supernews.com> <2011062818340635857-chrishinsley@gmailcom> <20110628185151666-chrishinsley@gmailcom> <2011062819022446632-chrishinsley@gmailcom> |
| Subject | Re: macro expansion ? |
On 2011-06-28 19:02:24 +0100, Chris Hinsley said: > On 2011-06-28 18:51:51 +0100, Chris Hinsley said: > >> On 2011-06-28 18:34:06 +0100, Chris Hinsley said: >> >>>>> >>>>> 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. >>>> >>>> I think that's going to happen anyway. When EVALUATE comes across a >>>> MACRO it'll expand it recursively. >>>> >>>> Perhaps you could show us an example of something like this not >>>> working. >>>> >>>> Andrew. >>> >>> A simple example that does work as intended. >>> >>> macro ma * +" >>> macro mp1 1 -rot ma" >>> : t1 1 -rot * + ; >>> : t2 mp1 ; >>> >>> Both t1 and t2 dissesemble to exactly the same code. Good that's as I >>> intended. And show the expansion of macros is recursive. :) >>> >>> However now I'm thinking how would a do a macro that can use itself ? >>> Part of this is no problem, the EVALUATE call will be able to find the >>> named macro and recurse in no problem. >>> >>> macro bert bert" >>> >>> Would just recurse till it crashed. But there's no problem with defineing it. >>> >>> So how would I exit a macro expansion ? I'd presumably have to have >>> interpret time, rather than runtime conditions used in the macro ? >>> >>> Forgive me if I'm rambling a bit, I'm making this up on the fly here, >>> trying to see if I can spot a problem. Would I hit a problem that IF, >>> ELSE, ENDIF are only available as compile time words (well they are for >>> my Forth, I know others have made them work at interpret time). Maybe >>> you just stick to useing [IF], [ELSE], [THEN] in macro definitions and >>> it will all just work (tm). >>> >>> I'll try a few more experiments. >>> >>> Chris >> >> OK, somthing definate as an example I'd like to see work. >> >> Lets say I have a Forth Hakiu pixel shader, it defines a word that >> takes x,y and gives back an ARGB. Normally I call this each pixel at >> runtime to generate a pixel on the fly, either in a shader on the GPU >> or with a peice of code that creates a texture at runtime. >> >> However, maybe I'd like to create a macro that uses the Haiku to create >> an embeded version of the texture as read only data stored as a word >> that returned a pointer to the embeded array of pixels ? All the >> processing of the pixels is to be done at compile time, no runtime >> overhead. Can I create a _macro_ that expands into the ARGB data array >> given a Hauku name and resolution value at compile time ? >> >> I'm just throwing this out as an example, I've not actualy tried to do >> it yet, but it might show up a problem. I can see that you could define >> a word that is an IMMEDIATE word to do this job at compile time, but >> can you do it with the/a macro concept ? >> >> Chris > > How about a macro that did greatest common divider ? > > Function gcd(a As Integer, b As Integer) As Integer > If b = 0 Then > gcd = a > Else > gcd = gcd(b,a) > End If > End Function > > Chris I think I'm rapidly getting into the 'but you wouldn't do it like that' teritory. You'd just define a word that did the calcutation, and then use it with somthing like [ 15 5 GCD ] LITERAL. But I'm pushing the issue of how you'd do it with a macro called GCD to expose the limits. Chris
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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