Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #10738 > unrolled thread
| Started by | Helmar Wodtke <helmwo@gmail.com> |
|---|---|
| First post | 2012-03-29 08:29 -0700 |
| Last post | 2012-04-03 17:02 -0700 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.lang.forth
Backquoted Macros Helmar Wodtke <helmwo@gmail.com> - 2012-03-29 08:29 -0700
Re: Backquoted Macros Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-04-03 09:33 +0000
Re: Backquoted Macros Mark Wills <markrobertwills@yahoo.co.uk> - 2012-04-03 06:46 -0700
Re: Backquoted Macros Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-03 03:32 -0700
Re: Backquoted Macros BruceMcF <agila61@netscape.net> - 2012-04-03 17:02 -0700
| From | Helmar Wodtke <helmwo@gmail.com> |
|---|---|
| Date | 2012-03-29 08:29 -0700 |
| Subject | Backquoted Macros |
| Message-ID | <21091167.276.1333034944725.JavaMail.geo-discussion-forums@yneo2> |
Hi, I'm working on some documentation to my Forth system (forth4p) and came across the nice invention of "Backquoted Macros" from FreeForth again. Does anyone else than FreeForth and my Forth use this? It's very practical: : 2dup` over` over` ; could be a definition of 2dup. The backquote at colon-definition name means more or less the thing is "IMMEDIATE" and inside code it means more or less to "POSTPONE" the word. So similar thing in "Forth 94" would look like: : 2dup postpone over postpone over ; immediate The nice thing about it is that you see if a word is immediate right after colon. The other nice thing is that you have much less space consumed than to write "POSTPONE". Actually neither forth4p nor FreeForth use the quirky semantics of "POSTPONE" if it comes to STATE (FreeForth does not even have this if I remember right). Maybe this concept is interesting for others - look at FreeForth page for the original: http://christophe.lavarenne.free.fr/ff/ HelFORTH and forth4p also implement a backquote in front of a word, which is similar (well, "about similar") to something like ['] name. Regards, -Helmar
[toc] | [next] | [standalone]
| From | Albert van der Horst <albert@spenarnc.xs4all.nl> |
|---|---|
| Date | 2012-04-03 09:33 +0000 |
| Message-ID | <m1wd7u.5i5@spenarnc.xs4all.nl> |
| In reply to | #10738 |
In article <21091167.276.1333034944725.JavaMail.geo-discussion-forums@yneo2>,
Helmar Wodtke <helmwo@gmail.com> wrote:
>Hi,
>
>I'm working on some documentation to my Forth system (forth4p) and came acr=
>oss the nice invention of "Backquoted Macros" from FreeForth again.
>
>Does anyone else than FreeForth and my Forth use this?
>
>It's very practical:
>
>: 2dup` over` over` ;
This syntax is all wrong, IMO. OVER and 2DUP are not special,
the compilation is. So it should be
`:` 2DUP OVER OVER `;`
or just
: 2DUP OVER OVER ; INLINED
By the way, there is no precedent of a compiling word that gets a name
from the input stream, and then compiles a definied with that name
mangled. This convention destroys one of the few certainties one has
in reading new Forth code.
<SNIP>
Groetjes Albert
>
>Regards,
>-Helmar
--
--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markrobertwills@yahoo.co.uk> |
|---|---|
| Date | 2012-04-03 06:46 -0700 |
| Message-ID | <7b8b8864-64f1-4fac-8e5d-dd5bc54512d0@j15g2000vbt.googlegroups.com> |
| In reply to | #10804 |
On Apr 3, 10:33 am, Albert van der Horst <alb...@spenarnc.xs4all.nl> wrote: > > : 2DUP OVER OVER ; INLINED > Yep. That's the one; and is how I intend to implement such a thing if I ever get around to writing a native compiler.
[toc] | [prev] | [next] | [standalone]
| From | Hugh Aguilar <hughaguilar96@yahoo.com> |
|---|---|
| Date | 2012-04-03 03:32 -0700 |
| Message-ID | <cfefdcfa-9d06-4dc1-aa93-32573830e908@x17g2000yqj.googlegroups.com> |
| In reply to | #10738 |
On Mar 29, 9:29 am, Helmar Wodtke <hel...@gmail.com> wrote:
> Hi,
>
> I'm working on some documentation to my Forth system (forth4p) and came across the nice invention of "Backquoted Macros" from FreeForth again.
>
> Does anyone else than FreeForth and my Forth use this?
>
> It's very practical:
>
> : 2dup` over` over` ;
>
> could be a definition of 2dup. The backquote at colon-definition name means more or less the thing is "IMMEDIATE" and inside code it means more or less to "POSTPONE" the word. So similar thing in "Forth 94" would look like:
>
> : 2dup postpone over postpone over ; immediate
>
> The nice thing about it is that you see if a word is immediate right after colon. The other nice thing is that you have much less space consumed than to write "POSTPONE". Actually neither forth4p nor FreeForth use the quirky semantics of "POSTPONE" if it comes to STATE (FreeForth does not even have this if I remember right).
>
> Maybe this concept is interesting for others - look at FreeForth page for the original:http://christophe.lavarenne.free.fr/ff/
> HelFORTH and forth4p also implement a backquote in front of a word, which is similar (well, "about similar") to something like ['] name.
>
> Regards,
> -Helmar
In my novice package I have the MACRO: word. It could be used like
this:
macro: 2dup ( a b -- a b a b )
over over ;
The downside is that this will no longer work the way that you expect
it to:
: test ( a b -- a b a b )
['] 2dup execute ;
Notice that you can search for ": 2dup" in your text editor and find
the definition whether it is defined with : or with MACRO: (you don't
have to remember which words have been upgraded from : to MACRO:).
The 2DUP defined above will work either from the console or in a colon
definition. Some macros won't work at the console however:
macro: dor ( Da Db -- Da|Db )
rot or >r or r> ;
Note that it is possible to write macros that would be impossible as
colon words:
0
w field .fore
constant list
macro: next>r ( node -- node ) \ r: -- next-node
dup .fore @ >r ;
macro: each[ \ toucher: i*x node -- j*x
begin dup while
next>r ;
macro: ]each
r> repeat drop ;
[toc] | [prev] | [next] | [standalone]
| From | BruceMcF <agila61@netscape.net> |
|---|---|
| Date | 2012-04-03 17:02 -0700 |
| Message-ID | <05cd3558-4366-46e2-857d-2b210e1de5d7@w5g2000yqi.googlegroups.com> |
| In reply to | #10738 |
On Mar 29, 11:29 am, Helmar Wodtke <hel...@gmail.com> wrote: > Hi, > I'm working on some documentation to my Forth system (forth4p) and came across the nice invention of "Backquoted Macros" from FreeForth again. > Does anyone else than FreeForth and my Forth use this? > It's very practical: > : 2dup` over` over` ; > could be a definition of 2dup. The backquote at colon-definition name means more or less the thing is "IMMEDIATE" and inside code it means more or less to "POSTPONE" the word. So similar thing in "Forth 94" would look like: > : 2dup postpone over postpone over ; immediate Except now 2dup is broken at the command line. If you have a Forth where COMPILE-ONLY words are done by not "seeing" compile-only words in interpret mode, then you could well have: : 2dup ` over ` over `;' ... with the sometimes used definition of ` as a shorthand for "POSTPONE", and `;' being a deliberately obscure and confusing shorthand for: ; IMMEDIATE COMPILE-ONLY But Albert is absolutely correct, your defining words should take WHATEVER space delimited token and use it unmodified as the name of the word being defined. There's no reason to modify : if you want to compile an immediate, compile-only postpone macro ~ it works fine as is.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web