Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #28584
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: +TO in GForth |
| Date | 2014-02-19 15:36 +0000 |
| Organization | Institut fuer Computersprachen, Technische Universitaet Wien |
| Message-ID | <2014Feb19.163656@mips.complang.tuwien.ac.at> (permalink) |
| References | <194ebd0a-9808-4612-947c-d031ae0b64f7@googlegroups.com> |
Mark Wills <markrobertwills@yahoo.co.uk> writes:
>How does one define +TO in GForth?
You don't! Use variables if you update stuff frequently; and we have
a word +! that helps there.
>I tried:
>
>: +to ( n tib:"value" -- ) ' >body dup >r @ + r> ! ; immediate
>
>Works in immediate mode, but doesn't work in a colon-def. Probably only works in ITC, too.
Why would you think that it only works in ITC? And think about why it
works interpretevely, but not compiled.
Let's refine your solution a little:
: +to-int ( n "value" -- ) ' >body +! ;
Note that the IMMEDIATE is unnecessary for interpretive use, and we
already have a nice word for "DUP >R @ + R> !".
Let's see how we can do a +TO-COMP
: +TO-COMP ( comp: "value" -- ; run-time: n -- )
' >body postpone literal postpone +! ; immediate
We want the ' >BODY to happen at compile time, so we have to make
+TO-COMP immediate, but the +! has to be at run-time, so we POSTPONE
it to counter the IMMEDIATE. And we have to get the address from
compile-time to run-time; the POSTPONE LITERAL does that.
Now let's combine these two words into a word +TO; it's interpretation
semantics should be +TO-INT, it's compilation semantics +TO-COMP:
' +to-int ' +to-comp interpret/compile: +to
Tests:
5 value foo
6 +to-int foo
foo .
: bar +to-comp foo ;
7 bar
foo .
' +to-int ' +to-comp interpret/compile: +to
8 +to foo
foo .
: boing +to foo ;
9 boing
foo .
- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: http://www.forth200x.org/forth200x.html
EuroForth 2013: http://www.euroforth.org/ef13/
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
+TO in GForth Mark Wills <markrobertwills@yahoo.co.uk> - 2014-02-19 07:08 -0800
Re: +TO in GForth Julian Fondren <julian.fondren@gmail.com> - 2014-02-19 07:31 -0800
Re: +TO in GForth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2014-02-19 15:36 +0000
Re: +TO in GForth hughaguilar96@yahoo.com - 2014-02-20 21:36 -0800
Re: +TO in GForth Harold <hzrabbie@gmail.com> - 2014-02-21 10:39 -0800
Re: +TO in GForth Julian Fondren <julian.fondren@gmail.com> - 2014-02-23 04:31 -0800
Re: +TO in GForth Mark Wills <markwills1970@gmail.com> - 2014-02-23 15:10 -0800
Re: +TO in GForth hughaguilar96@yahoo.com - 2014-02-19 22:44 -0800
csiph-web