Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #28639
| Newsgroups | comp.lang.forth |
|---|---|
| Date | 2014-02-20 21:36 -0800 |
| References | <194ebd0a-9808-4612-947c-d031ae0b64f7@googlegroups.com> <2014Feb19.163656@mips.complang.tuwien.ac.at> |
| Message-ID | <9965dd68-c2d2-46bd-980a-656d2f3a7c20@googlegroups.com> (permalink) |
| Subject | Re: +TO in GForth |
| From | hughaguilar96@yahoo.com |
On Wednesday, February 19, 2014 8:36:56 AM UTC-7, Anton Ertl wrote: > 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 This is total baloney! The ANS-Forth >BODY only works with words defined by CREATE. In 6.1.0550 it says: "An ambiguous condition exists if xt is not for a word defined via CREATE." There is nothing in the ANS-Forth document (see 6.2.2405) that says VALUE is defined internally by CREATE DOES> --- this would only be true in crude compilers, but I would expect an optimizing compiler to define VALUE such that it generates a colon word. Local variables are not going to be defined with CREATE DOES> in any compiler, crude or optimizing. Mark: Just use my +TO in my novice package --- that way you will have compatibility to any ANS-Forth compiler, and your +TO will work with both VALUEs and local variables.
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