Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #28580 > unrolled thread
| Started by | Mark Wills <markrobertwills@yahoo.co.uk> |
|---|---|
| First post | 2014-02-19 07:08 -0800 |
| Last post | 2014-02-19 22:44 -0800 |
| Articles | 8 — 6 participants |
Back to article view | Back to comp.lang.forth
+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
| From | Mark Wills <markrobertwills@yahoo.co.uk> |
|---|---|
| Date | 2014-02-19 07:08 -0800 |
| Subject | +TO in GForth |
| Message-ID | <194ebd0a-9808-4612-947c-d031ae0b64f7@googlegroups.com> |
How does one define +TO in GForth? 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. TIA
[toc] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2014-02-19 07:31 -0800 |
| Message-ID | <7e9dad3b-1844-4b03-9b00-c85196a6773b@googlegroups.com> |
| In reply to | #28580 |
On Wednesday, February 19, 2014 9:08:36 AM UTC-6, Mark Wills wrote: > How does one define +TO in GForth? If these words followed ' ['] char [char] and friends, you could do this: : +TO ( x "value" -- ) ' >body +! ; : [+TO] ( x "value" -- ) ' >body postpone literal postpone +! ; immediate But they don't, so you have to write a state-smart word or, in gforth, a dual-semantics word: ' +to ' [+to] interpret/compile: +to ( x "value" -- ) See gforth's manual. -- Julian
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2014-02-19 15:36 +0000 |
| Message-ID | <2014Feb19.163656@mips.complang.tuwien.ac.at> |
| In reply to | #28580 |
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/
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@yahoo.com |
|---|---|
| Date | 2014-02-20 21:36 -0800 |
| Message-ID | <9965dd68-c2d2-46bd-980a-656d2f3a7c20@googlegroups.com> |
| In reply to | #28584 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Harold <hzrabbie@gmail.com> |
|---|---|
| Date | 2014-02-21 10:39 -0800 |
| Message-ID | <57e2d186-e95a-4000-925e-dfc9103a800b@googlegroups.com> |
| In reply to | #28639 |
On Thursday, February 20, 2014 9:36:58 PM UTC-8, hughag...@yahoo.com wrote: > 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." Correct. > I would expect an optimizing compiler to define VALUE such that it generates a colon word. If the dictionary is writeable, I'd expect VALUE to compile the same as CONSTANT. The run-time semantics are the same.
[toc] | [prev] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2014-02-23 04:31 -0800 |
| Message-ID | <95621045-bcd1-4104-a346-8ed93a5dad11@googlegroups.com> |
| In reply to | #28639 |
On Thursday, February 20, 2014 11:36:58 PM UTC-6, hughag...@yahoo.com wrote: > 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? > > > : +to-int ( n "value" -- ) ' >body +! ; > > : +TO-COMP ( comp: "value" -- ; run-time: n -- ) > > ' >body postpone literal postpone +! ; immediate > > ' +to-int ' +to-comp interpret/compile: +to (abbreviated.) > 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." > The title of this thread is "+TO in GForth". The question is "How does one define +TO in GFoth?". The answers above are appropriate for gforth. If Mark Wills wants to port his +TO -using program to another Forth, later on, what he then needs a +TO with the same behavior on the destination Forth system. If he's at a loss for a definition appropriate for that Forth system, he can always implement your stupid EVALUATE version that will work for any ANS Forth. You're always whining about how onerous and terrible and painful ANS Forth is. I think most of the problem with 'ANS Forth' for you is with your treatment of it. The +TO above isn't even 'non-standard'. Mark's Forth program, incuding this definition, just needs a declared environmental dependency on >BODY working with VALUEs. And an error message like "+TO ?" is probably the easist porting hurdle there is. Slightly worse are where a commonly understood word is implemented slightly differently -- like how STRING, on SwiftForth adds a null after the string. The worst is where your application depends on extra-Forth stuff like Win32 library calls or Android jni calls or Unix system commands. -- Julian
[toc] | [prev] | [next] | [standalone]
| From | Mark Wills <markwills1970@gmail.com> |
|---|---|
| Date | 2014-02-23 15:10 -0800 |
| Message-ID | <7f0beaae-e52d-4d2a-b78b-9e27cd20cf0d@googlegroups.com> |
| In reply to | #28711 |
It's okay. I just changed the code to use variables instead. I prefer values only because I don't like visual noise induced by @ and !. I'm disappointed that +TO is not included in GForth. I know it's not part of the standard, but it's very common, and I was surprised to see it's not included.
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@yahoo.com |
|---|---|
| Date | 2014-02-19 22:44 -0800 |
| Message-ID | <19d0c73d-380a-40a8-8077-56124204ae5d@googlegroups.com> |
| In reply to | #28580 |
On Wednesday, February 19, 2014 8:08:36 AM UTC-7, Mark Wills wrote: > How does one define +TO in GForth? There is a definition in the novice package: http://www.forth.org/novice.html All of this is ANS-Forth, so it should work on any ANS-Forth system. For the most part, I prefer to use variables rather than values. Unfortunately, in ANS-Forth locals are values rather than variables --- in my language I will only have variables and not have values at all, and locals will be variables too. I consider values to be one of the grosser parts of ANS-Forth --- I never used them in Forth-83 (when they were called items) and would have been okay with considering them to be a failed experiment.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.forth
csiph-web