Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #15025 > unrolled thread
| Started by | programmingkidx@gmail.com |
|---|---|
| First post | 2012-08-18 19:28 -0700 |
| Last post | 2012-08-19 14:43 -0700 |
| Articles | 20 on this page of 83 — 16 participants |
Back to article view | Back to comp.lang.forth
continue equivalent in Forth? programmingkidx@gmail.com - 2012-08-18 19:28 -0700
Re: continue equivalent in Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-19 01:43 -0500
Re: continue equivalent in Forth? mhx@iae.nl - 2012-08-19 03:40 -0700
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-19 21:07 +1000
Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-19 13:55 +0200
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-20 22:13 +1000
Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-19 14:18 +0200
Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-19 14:57 +0200
Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-19 16:39 +0200
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-20 22:18 +1000
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-21 00:05 -0400
Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-20 21:17 -0700
Re: continue equivalent in Forth? Alex McDonald <blog@rivadpm.com> - 2012-08-21 02:40 -0700
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-22 15:33 +1000
Re: continue equivalent in Forth? Alex McDonald <blog@rivadpm.com> - 2012-08-21 02:37 -0700
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 00:53 -0400
Re: continue equivalent in Forth? Alex McDonald <blog@rivadpm.com> - 2012-08-22 04:10 -0700
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-21 11:40 +0000
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 00:53 -0400
Re: continue equivalent in Forth? "Elizabeth D. Rather" <erather@forth.com> - 2012-08-21 21:18 -1000
Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-22 00:52 -0700
Re: continue equivalent in Forth? Alex McDonald <blog@rivadpm.com> - 2012-08-22 04:12 -0700
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 07:43 -0400
Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-22 20:04 -0700
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-25 15:50 +1000
Re: continue equivalent in Forth? "Elizabeth D. Rather" <erather@forth.com> - 2012-08-24 21:03 -1000
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-26 22:13 +1000
Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-25 10:40 +0200
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-29 18:29 +1000
Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-29 21:26 +0200
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-26 22:33 +1000
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 07:46 -0400
Re: continue equivalent in Forth? "Elizabeth D. Rather" <erather@forth.com> - 2012-08-22 07:20 -1000
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-22 09:37 +0000
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-22 20:46 +1000
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 07:44 -0400
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-22 14:26 +0000
Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-24 17:34 +0100
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-24 16:50 +0000
Re: continue equivalent in Forth? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-08-24 13:47 -0700
Re: continue equivalent in Forth? mhx@iae.nl - 2012-08-24 22:51 -0700
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-25 08:55 +0000
Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-25 20:47 -0700
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-26 06:20 -0400
Re: continue equivalent in Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-26 11:04 -0500
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-26 16:06 +0000
Re: continue equivalent in Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-26 15:32 -0500
Re: continue equivalent in Forth? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-08-27 22:58 -0700
Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-26 22:07 +0100
Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-27 18:14 +0200
Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-27 18:22 +0100
Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-27 20:45 +0200
Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-27 21:43 +0100
Re: continue equivalent in Forth? "Elizabeth D. Rather" <erather@forth.com> - 2012-08-27 12:15 -1000
Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-28 20:43 +0200
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-29 17:10 +1000
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-28 15:56 +0000
Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-28 20:35 +0200
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-30 12:32 +0000
Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-30 22:39 +0200
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-08-31 09:14 +0000
Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-31 21:32 +0200
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-09-02 20:30 +1000
Re: continue equivalent in Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-09-02 13:15 +0000
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-31 18:27 +1000
Re: continue equivalent in Forth? mhx@iae.nl (Marcel Hendrix) - 2012-08-31 20:39 +0200
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-09-01 14:28 +1000
Re: continue equivalent in Forth? hughaguilar96@yahoo.com - 2012-08-21 22:59 -0700
Re: continue equivalent in Forth? Bernd Paysan <bernd.paysan@gmx.de> - 2012-08-21 20:49 +0200
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-22 07:46 -0400
Re: continue equivalent in Forth? Bernd Paysan <bernd.paysan@gmx.de> - 2012-08-22 16:24 +0200
Re: continue equivalent in Forth? programmingkidx@gmail.com - 2012-08-19 14:37 -0700
Re: continue equivalent in Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2012-08-20 05:17 -0500
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-20 22:34 +1000
Re: continue equivalent in Forth? "Ed" <invalid@nospam.com> - 2012-08-20 23:01 +1000
Re: continue equivalent in Forth? stephenXXX@mpeforth.com (Stephen Pelc) - 2012-08-21 08:34 +0000
Re: continue equivalent in Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-08-21 15:53 +0100
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-19 11:00 -0400
Re: continue equivalent in Forth? Coos Haak <chforth@hccnet.nl> - 2012-08-19 20:29 +0200
Re: continue equivalent in Forth? "Rod Pemberton" <do_not_have@notemailnot.cmm> - 2012-08-21 00:04 -0400
Re: continue equivalent in Forth? programmingkidx@gmail.com - 2012-08-19 14:09 -0700
Re: continue equivalent in Forth? Mark Wills <markrobertwills@yahoo.co.uk> - 2012-08-19 11:31 -0700
Re: continue equivalent in Forth? programmingkidx@gmail.com - 2012-08-19 14:43 -0700
Page 4 of 5 — ← Prev page 1 2 3 [4] 5 Next page →
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-08-31 09:14 +0000 |
| Message-ID | <2012Aug31.111420@mips.complang.tuwien.ac.at> |
| In reply to | #15279 |
mhx@iae.nl (Marcel Hendrix) writes:
>OK, here is the complete example:
>a label in a high-level definition (no sugar).
>
>: blah ." blah " ;
>: foo ." foo " ;
>
>: aword blah blah blah 0 if ;
>: label_001 then foo foo foo ;
>
>FORTH> label_001 foo foo foo ok
>FORTH> aword blah blah blah foo foo foo ok
The answer specific to this example was posted by Alex MacDonald:
: label_001 foo foo foo ;
: aword blah blah blah label_001 ;
In general, one can organize the words to avoid control structures
crossing words.
But if you really want to do such a thing, here's one way to do it in
Gforth:
: blah ." blah " ;
: foo ." foo " ;
: aword blah blah blah
0 if [ >r >r >r ] ; : label_001 [ r> r> r> ] then
foo foo foo ;
My question about SECURE was actually meant as follows: If SECURE is
on, iForth apparently does not accept some Forth-94-compliant control
structures. What does it offer that is worth that cost?
BTW, your posting would have been easier to read if your newsreader
also put quote characters in front of cited empty lines.
- 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 2012: http://www.euroforth.org/ef12/
[toc] | [prev] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2012-08-31 21:32 +0200 |
| Message-ID | <16711404958435@frunobulax.edu> |
| In reply to | #15306 |
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: continue equivalent in Forth? > mhx@iae.nl (Marcel Hendrix) writes: [..] > My question about SECURE was actually meant as follows: If SECURE is > on, iForth apparently does not accept some Forth-94-compliant control > structures. What does it offer that is worth that cost? For that cost, you can compile code that other Forths won't. Of course, it would be better to have gForth-like diagnostics with a SECURE flag to disable them for exceptional cases. Maybe for the next redesign -- after my retirement, or when iForth goes open-source :-) > BTW, your posting would have been easier to read if your newsreader > also put quote characters in front of cited empty lines. You actually notice uncited empted lines between all the quoted-printable crap that has become the standard lately? -marcel
[toc] | [prev] | [next] | [standalone]
| From | "Ed" <invalid@nospam.com> |
|---|---|
| Date | 2012-09-02 20:30 +1000 |
| Message-ID | <k1vc9g$45c$1@speranza.aioe.org> |
| In reply to | #15326 |
Marcel Hendrix wrote: > anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: continue equivalent in Forth? > > > mhx@iae.nl (Marcel Hendrix) writes: > [..] > > My question about SECURE was actually meant as follows: If SECURE is > > on, iForth apparently does not accept some Forth-94-compliant control > > structures. What does it offer that is worth that cost? > > For that cost, you can compile code that other Forths won't. > > Of course, it would be better to have gForth-like diagnostics with a > SECURE flag to disable them for exceptional cases. Maybe for the next > redesign -- after my retirement, or when iForth goes open-source :-) Another ANS refusenik.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-09-02 13:15 +0000 |
| Message-ID | <2012Sep2.151548@mips.complang.tuwien.ac.at> |
| In reply to | #15326 |
mhx@iae.nl (Marcel Hendrix) writes:
>anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: continue equivalent in Forth?
>
>> mhx@iae.nl (Marcel Hendrix) writes:
>[..]
>> My question about SECURE was actually meant as follows: If SECURE is
>> on, iForth apparently does not accept some Forth-94-compliant control
>> structures. What does it offer that is worth that cost?
>
>For that cost, you can compile code that other Forths won't.
Like what? It seems to me that iForth with the default SECURE ON
cannot compile some standard code that other Forths can compile.
>Of course, it would be better to have gForth-like diagnostics with a
>SECURE flag to disable them for exceptional cases.
So what you mean is maybe this: SECURE OFF offers additional features
(without needing funny stuff like you would have to do in Gforth);
SECURE ON offers diagnostics, but is a little overzealous and might be
fixed in the far future. Correct?
>> BTW, your posting would have been easier to read if your newsreader
>> also put quote characters in front of cited empty lines.
>
>You actually notice uncited empted lines between all the
>quoted-printable crap that has become the standard lately?
Yes. And given that you have the option of fixing your newsreader
rather than just switching to a different one, I chose to make you
aware of that. Concerning the crap, if something is too hard to read,
I don't.
- 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 2012: http://www.euroforth.org/ef12/
[toc] | [prev] | [next] | [standalone]
| From | "Ed" <invalid@nospam.com> |
|---|---|
| Date | 2012-08-31 18:27 +1000 |
| Message-ID | <k1psbj$d41$1@speranza.aioe.org> |
| In reply to | #15223 |
Marcel Hendrix wrote:
> ...
>
> IF C CORE
> Compilation: ( -- orig )
> Put the location of a new unresolved forward reference orig onto the
> control flow stack. Append the execution semantics given below to the
> current definition. The semantics are incomplete until orig is resolved
> (e.g., by THEN ).
> Execution: ( x -- )
> If all bits of x are zero, continue execution at the location specified
> by the resolution of orig.
> See also: ELSE THEN
>
>
> I see nothing here that allows an error message.
"The [compilation] semantics are incomplete until orig is resolved (e.g., by THEN )."
[toc] | [prev] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2012-08-31 20:39 +0200 |
| Message-ID | <12641504958435@frunobulax.edu> |
| In reply to | #15301 |
"Ed" <invalid@nospam.com> writes Re: continue equivalent in Forth? > Marcel Hendrix wrote: >> ... >> >> IF C CORE >> Compilation: ( -- orig ) [..] >> I see nothing here that allows an error message. > "The [compilation] semantics are incomplete until orig is resolved (e.g., by THEN )." So? The following definition is also incomplete. : foo blah \ until we type blah blah ; -marcel
[toc] | [prev] | [next] | [standalone]
| From | "Ed" <invalid@nospam.com> |
|---|---|
| Date | 2012-09-01 14:28 +1000 |
| Message-ID | <k1s2p8$n4n$1@speranza.aioe.org> |
| In reply to | #15325 |
Marcel Hendrix wrote: > "Ed" <invalid@nospam.com> writes Re: continue equivalent in Forth? > > > Marcel Hendrix wrote: > >> ... > >> > >> IF C CORE > >> Compilation: ( -- orig ) > [..] > >> I see nothing here that allows an error message. > > > "The [compilation] semantics are incomplete until orig is resolved (e.g., by THEN )." > > So? The following definition is also incomplete. > > : foo blah > > \ until we type > > blah blah ; It looks complete to me! Resolving orig is part of "standard" IF's compile-time semantics. It's specified because almost every forth produced since Fig has compiler security and would complain otherwise. If anyone is to blame it is the Dutch :) According to Bill Ragsdale (FD 5V6) he gave variable 31 character names to Utrecht University and they gave him compiler security ... "We took the compiler security from their code; until that time, none of the USA versions had that".
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@yahoo.com |
|---|---|
| Date | 2012-08-21 22:59 -0700 |
| Message-ID | <25aaedcf-9962-42e3-8a05-96bac4e27b92@googlegroups.com> |
| In reply to | #15069 |
On Tuesday, August 21, 2012 4:40:16 AM UTC-7, Anton Ertl wrote: > "Rod Pemberton" <do_not_have@notemailnot.cmm> writes: > >AIUI, most Forths don't have a control-flow stack separate from the > >parameter or data stack. They use the data stack for both. Such a simple > >definition for CONTINUE will not work in such a case since BEGIN's address > >could be below other stacked data. > > What other stacked data? The only data usually on the stack above > colon-sys during compilation are control-flow stack items. That's why > it's practical to use the data stack as control-flow stack. If people > put data on the stack during compilation that lived across > control-flow words, not just CONTINUE would be in trouble, but every > other control-flow word, too. But they don't. Are you for real? You don't understand what :NAME does at all, do you? You apparently never write colon words that generate other colon words, but you just hand-write all of your code --- why don't you give up on Forth and just stick with C programming, as that seems to much more your style? If you look at my novice package, you can see that I routinely pass data into colon definitions at their compile-time and give it to LITERAL. Look at <1ARRAY> etc. for example. I can't pass this data on the stack however, because the control-flow words are also using the stack. I typically use local variables, although sometimes I use the return stack --- this is an awkward way to pass data though, as the more Forth-like way to pass data is on the data stack.
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2012-08-21 20:49 +0200 |
| Message-ID | <5042720.VCH2aBU8Gs@sunwukong.fritz.box> |
| In reply to | #15064 |
Rod Pemberton wrote:
> AIUI, most Forths don't have a control-flow stack separate from the
> parameter or data stack. They use the data stack for both. Such a
> simple definition for CONTINUE will not work in such a case since
> BEGIN's address
> could be below other stacked data. I.e., how do you locate which
> stack location has BEGIN's address?
Search for it? In Gforth, it's a dest-like control-sys, so it is
identified by the constant "dest" for the top-most element.
: continue ( dest-sys j*sys -- dest-sys j*sys )
depth 0 ?DO I pick dest = IF
I cs-item-size / cs-pick postpone AGAIN
UNLOOP EXIT THEN
cs-item-size +LOOP
true abort" no BEGIN found" ;
immediate compile-only
should do it. I'm not using CS-PICK for the search, since Gforth
implements a check for the standard's "CS-PICK can only pick dests"
condition - and well, it's faster that way, too.
This will jump to the next-outer BEGIN. You can theoretically stack and
clean up other data in between, but normally, you don't (and it's not
adviced to do so), and if you actually do, and CONTINUE breaks, you get
what you deserve.
--
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <do_not_have@notemailnot.cmm> |
|---|---|
| Date | 2012-08-22 07:46 -0400 |
| Message-ID | <k12gmn$tp5$1@speranza.aioe.org> |
| In reply to | #15072 |
"Bernd Paysan" <bernd.paysan@gmx.de> wrote in message news:5042720.VCH2aBU8Gs@sunwukong.fritz.box... > Rod Pemberton wrote: ... > > AIUI, most Forths don't have a control-flow stack separate from the > > parameter or data stack. They use the data stack for both. Such a > > simple definition for CONTINUE will not work in such a case since > > BEGIN's address > > could be below other stacked data. I.e., how do you locate which > > stack location has BEGIN's address? > > Search for it? That seems valid, although to be avoided for it's overhead. > In Gforth, it's a dest-like control-sys, so it is > identified by the constant "dest" for the top-most element. > > : continue ( dest-sys j*sys -- dest-sys j*sys ) > depth 0 ?DO I pick dest = IF > I cs-item-size / cs-pick postpone AGAIN > UNLOOP EXIT THEN > cs-item-size +LOOP > true abort" no BEGIN found" ; > immediate compile-only > > should do it. I'm not using CS-PICK for the search, since Gforth > implements a check for the standard's "CS-PICK can only pick dests" > condition - and well, it's faster that way, too. > > This will jump to the next-outer BEGIN. You can theoretically stack and > clean up other data in between, but normally, you don't (and it's not > adviced to do so), and if you actually do, and CONTINUE breaks, you get > what you deserve. My concern with searching for special values, e.g., "dest", is that it's possible that a non-special value is recognized as a special value. I'll have to assume it's not an issue for Gforth. I'm not sure "adviced" is a word. You want "advised". The words "advice" and "advise" are different. One is an action of providing information. The other is the provided information content. Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | Bernd Paysan <bernd.paysan@gmx.de> |
|---|---|
| Date | 2012-08-22 16:24 +0200 |
| Message-ID | <14790334.HYE3mgjgux@sunwukong.fritz.box> |
| In reply to | #15094 |
Rod Pemberton wrote: >> Search for it? > > That seems valid, although to be avoided for it's overhead. This is a moderate compile-time overhead. How many sys-elements on the stack do you expect? > My concern with searching for special values, e.g., "dest", is that > it's > possible that a non-special value is recognized as a special value. > I'll have to assume it's not an issue for Gforth. No, it's just as simple as with any other control-sys: If you want your control structure to work, *don't mess with the stack*. > I'm not sure "adviced" is a word. You want "advised". The words > "advice" > and "advise" are different. One is an action of providing > information. The other is the provided information content. About 20 million search results on Google (compared to 277 for advised), which means that even native speakers have their troubles. English is not my native language, a typo here or there is not really a problem. This is not alt.learn.english, this is comp.lang.forth. -- Bernd Paysan "If you want it done right, you have to do it yourself" http://bernd-paysan.de/
[toc] | [prev] | [next] | [standalone]
| From | programmingkidx@gmail.com |
|---|---|
| Date | 2012-08-19 14:37 -0700 |
| Message-ID | <44be344f-7c0d-41aa-aaab-362c2ff14f9b@googlegroups.com> |
| In reply to | #15030 |
On Sunday, August 19, 2012 7:07:12 AM UTC-4, Ed wrote:
>
>
> > When I am in a begin-while-repeat loop, I sometimes would like to go to the top of the loop.
>
> > The "continue" keyword in C is what would help me perfectly here. Is there a "continue" like
>
> > word in Forth?
>
>
>
> No, as generally it can be avoided. Provide a sample of what it
>
> is that you wish to do and someone should be able to help.
>
>
>
> That said, some forths have tools that allow one to implement
>
> features found in other languages e.g.
>
>
>
>
>
> : BEGIN
>
> postpone begin 0 cs-pick cs-push ; immediate
>
>
>
> : REPEAT
>
> cs-pop cs-drop postpone repeat ; immediate
>
>
>
> : CONTINUE
>
> cs-pop 0 cs-pick postpone again cs-push ; immediate
>
>
>
>
>
> : test ( -- )
>
> cr cr ." Chars b d f will be ignored, ESC quits." cr
>
> begin
>
> cr ." Enter character> " key dup 27 -
>
> while ( not ESC )
>
> dup [char] b = if drop continue then
>
> dup [char] d = if drop continue then
>
> dup [char] f = if drop continue then
>
> ( char ) emit
>
> repeat drop ;
>
>
>
> test
>
>
>
> Chars b d f will be ignored, ESC quits.
>
>
>
> Enter character> a
>
> Enter character>
>
> Enter character> c
>
> Enter character>
>
> Enter character> e
>
> Enter character>
>
> Enter character> g
>
> Enter character> h
>
> Enter character> i
>
> Enter character> j
>
> Enter character> ok
Unfortunately my Forth implementation does not have a cs-push, or a cs-pop word. What exactly do they do?
What I am trying to do is to alter the INTERPRET word so it calls another kind of FIND word. The job of my FIND word is to locate local variables in definitions and substitute local variable symbols with words that are used in place of the symbol. I call it LFIND. I set the mydefer defer to LFIND's execution token because I am still testing LFIND. When I am done testing, mydefer will be replaced with LFIND. usingLocals acts like a flag to prevent mydefer from executing before it is ready. Here is the source code:
false value usingLocals
Defer mydefer
: interpret
0 >in !
begin
parse-word dup 0> \ was there a word at all?
while
usingLocals if
mydefer
if
CONTINUE \ no need to continue to $FIND or $NUMBER.
then
then
$find
if
dup flags? 0<> state @ 0= or if
execute
else
, \ compile mode && !immediate
then
else \ word is not known. maybe it's a number
2dup $number
if
span @ >in ! \ if we encountered an error, don't continue parsing
type 3a emit
-13 throw
else
-rot 2drop 1 handle-lit
then
then
depth 200 >= if -3 throw then
depth 0< if -4 throw then
rdepth 200 >= if -5 throw then
rdepth 0< if -6 throw then
repeat
2drop
;
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2012-08-20 05:17 -0500 |
| Message-ID | <Q_GdnculvMk3k6_NnZ2dnUVZ8sqdnZ2d@supernews.com> |
| In reply to | #15044 |
programmingkidx@gmail.com wrote: > What I am trying to do is to alter the INTERPRET word so it calls > another kind of FIND word. The job of my FIND word is to locate > local variables in definitions and substitute local variable symbols > with words that are used in place of the symbol. I call it LFIND. I > set the mydefer defer to LFIND's execution token because I am still > testing LFIND. When I am done testing, mydefer will be replaced with > LFIND. usingLocals acts like a flag to prevent mydefer from > executing before it is ready. Here is the source code: > > false value usingLocals > Defer mydefer > > : interpret > 0 >in ! > begin > parse-word dup 0> \ was there a word at all? > while > usingLocals if > mydefer > if > CONTINUE \ no need to continue to $FIND or $NUMBER. > then > then > $find > if > dup flags? 0<> state @ 0= or if > execute > else > , \ compile mode && !immediate > then > else \ word is not known. maybe it's a number > 2dup $number > if > span @ >in ! \ if we encountered an error, don't continue parsing > type 3a emit > -13 throw > else > -rot 2drop 1 handle-lit > then > then > depth 200 >= if -3 throw then > depth 0< if -4 throw then > rdepth 200 >= if -5 throw then > rdepth 0< if -6 throw then > repeat > 2drop > ; This is an example of the problem I was talking about. Forth words should, ideally, be one or two lines long. However, that assumes a horizontal layout, rather than the vertical layout you've used here. So, that would correspond to about five or six lines with a vertical layout. I'm fairly sure that if you refactor this word into sub-words your need for CONTINUE will go away. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | "Ed" <invalid@nospam.com> |
|---|---|
| Date | 2012-08-20 22:34 +1000 |
| Message-ID | <k0tamr$m03$1@speranza.aioe.org> |
| In reply to | #15044 |
programmingkidx@gmail.com wrote: > ... > > Unfortunately my Forth implementation does not have a cs-push, or a cs-pop word. What > exactly do they do? The spec may be found here http://dxforth.webhop.org/cfsext.html
[toc] | [prev] | [next] | [standalone]
| From | "Ed" <invalid@nospam.com> |
|---|---|
| Date | 2012-08-20 23:01 +1000 |
| Message-ID | <k0tc9a$pp0$1@speranza.aioe.org> |
| In reply to | #15044 |
programmingkidx@gmail.com wrote:
> ...
> What I am trying to do is to alter the INTERPRET word so it calls another kind of FIND word.
> The job of my FIND word is to locate local variables in definitions and substitute local
> variable symbols with words that are used in place of the symbol. I call it LFIND. I set the
> mydefer defer to LFIND's execution token because I am still testing LFIND. When I am done
> testing, mydefer will be replaced with LFIND. usingLocals acts like a flag to prevent
> mydefer from executing before it is ready. Here is the source code:
> ...
Arrange the code so that mydefer falls through to REPEAT e.g.
...
usingLocals if
mydefer
else
$find
....
then
repeat
[toc] | [prev] | [next] | [standalone]
| From | stephenXXX@mpeforth.com (Stephen Pelc) |
|---|---|
| Date | 2012-08-21 08:34 +0000 |
| Message-ID | <50334359.453419869@192.168.0.50> |
| In reply to | #15044 |
On Sun, 19 Aug 2012 14:37:37 -0700 (PDT), programmingkidx@gmail.com
wrote:
>What I am trying to do is to alter the INTERPRET word so it calls another k=
>ind of FIND word. The job of my FIND word is to locate local variables in d=
>efinitions and substitute local variable symbols with words that are used i=
>n place of the symbol. I call it LFIND. I set the mydefer defer to LFIND's =
>execution token because I am still testing LFIND. When I am done testing, m=
>ydefer will be replaced with LFIND. usingLocals acts like a flag to prevent=
> mydefer from executing before it is ready. Here is the source code:=20
Let's redo the loop a bit:
> false value usingLocals
>Defer mydefer
>
>: interpret=20
> 0 >in !
> begin
> parse-word dup 0> \ was there a word at all?
> while
> usingLocals if
> mydefer
> if
> CONTINUE \ no need to continue to $FIND or $NUMBER.
> then
> then
> $find=20
if foo else bar then
checks
> repeat
> 2drop
> ;
Now we can refactor again:
false value usingLocals
Defer mydefer
: dolocal \ ??? -- ???
usingLocals dup if
drop mydefer
then
;
: interpret \ ??? -- ???
0 >in !
begin
parse-word dup 0>
while
dolocal 0= if
$find
if foo else bar then
checks
then
repeat
2drop
;
You can probably usefully move CHECKS to just before the REPEAT. Now
you do not need CONTINUE. Factoring is the key because it allows you
to see easy solutions. You can also usefully refactor the DEFERred
word so that dolocal is the DEFERred. Factor it, refactor it and
refactor it again and then you may have a solution.
Personally, I would ask why you do not handle locals by adding to the
search order. This replaces the CONTINUE problem with the problem of
having a transient dictionary area. With a bit of factoring, the
transient dictionary problem is not difficult either.
Stephen
--
Stephen Pelc, stephenXXX@mpeforth.com
MicroProcessor Engineering Ltd - More Real, Less Time
133 Hill Lane, Southampton SO15 5AF, England
tel: +44 (0)23 8063 1441, fax: +44 (0)23 8033 9691
web: http://www.mpeforth.com - free VFX Forth downloads
[toc] | [prev] | [next] | [standalone]
| From | Gerry Jackson <gerry@jackson9000.fsnet.co.uk> |
|---|---|
| Date | 2012-08-21 15:53 +0100 |
| Message-ID | <k107d8$vki$1@dont-email.me> |
| In reply to | #15066 |
On 21/08/2012 09:34, Stephen Pelc wrote:
> On Sun, 19 Aug 2012 14:37:37 -0700 (PDT), programmingkidx@gmail.com
> wrote:
>
> Personally, I would ask why you do not handle locals by adding to the
> search order.
>
You need to be careful how you implement this idea e.g.
VFX Forth for Windows IA32
© MicroProcessor Engineering Ltd, 1998-2011
Version: 4.44 [build 3245]
Build date: 1 November 2011
Free dictionary = 7557646 bytes [7380kb]
get-order wordlist swap 1+ set-order ok
ok
: foo { x } x [ previous ] x ;
Err# -13 ERR: Undefined word.
-> : foo { x } x [ previous ] x ;
^
This is a greatly simplified version of code where the bug bit me a long
time ago. I reported it so, of course, you may have fixed this in a
later version. It's the same if LOCALS| is used.
Similarly:
wordlist constant wl ok
get-current wl set-current ok-1
1234 value x ok-1
set-current ok
: foo { x } cr x . [ get-order wl swap 1+ set-order ] x . ; ok
9876 foo
9876 1234 ok
This also violates the ANS Forth requirement that "... none of the
Search-Order words shall change the locals' privileged position in the
search order."
--
Gerry
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <do_not_have@notemailnot.cmm> |
|---|---|
| Date | 2012-08-19 11:00 -0400 |
| Message-ID | <k0quu1$jca$1@speranza.aioe.org> |
| In reply to | #15025 |
<programmingkidx@gmail.com> wrote in message news:8cbd2bb8-ed3d-4fab-a1da-af77293ecbb9@googlegroups.com... > When I am in a begin-while-repeat loop, I sometimes > would like to go to the top of the loop. From which section of the loop would you "like to go to the top of the loop"? 1) begin-while 2) while-repeat I'm surprised no one else asked that ... Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | Coos Haak <chforth@hccnet.nl> |
|---|---|
| Date | 2012-08-19 20:29 +0200 |
| Message-ID | <krgrlza60czr$.zq0hfu8qh13x.dlg@40tude.net> |
| In reply to | #15035 |
Op Sun, 19 Aug 2012 11:00:40 -0400 schreef Rod Pemberton: > <programmingkidx@gmail.com> wrote in message > news:8cbd2bb8-ed3d-4fab-a1da-af77293ecbb9@googlegroups.com... > >> When I am in a begin-while-repeat loop, I sometimes >> would like to go to the top of the loop. > > From which section of the loop would you > "like to go to the top of the loop"? > > 1) begin-while > 2) while-repeat > > I'm surprised no one else asked that ... > > > Rod Pemberton It doesn't matter, the control items of BEGIN are on the top in the first part, and WHILE puts it items under them. Times have changed since FigForth ;-) -- Coos CHForth, 16 bit DOS applications http://home.hccnet.nl/j.j.haak/forth.html
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <do_not_have@notemailnot.cmm> |
|---|---|
| Date | 2012-08-21 00:04 -0400 |
| Message-ID | <k0v17t$ig4$1@speranza.aioe.org> |
| In reply to | #15040 |
"Coos Haak" <chforth@hccnet.nl> wrote in message news:krgrlza60czr$.zq0hfu8qh13x.dlg@40tude.net... > Op Sun, 19 Aug 2012 11:00:40 -0400 schreef Rod Pemberton: > > <programmingkidx@gmail.com> wrote in message > > news:8cbd2bb8-ed3d-4fab-a1da-af77293ecbb9@googlegroups.com... ... > >> When I am in a begin-while-repeat loop, I sometimes > >> would like to go to the top of the loop. > > > > From which section of the loop would you > > "like to go to the top of the loop"? > > > > 1) begin-while > > 2) while-repeat > > > > I'm surprised no one else asked that ... > > > > It doesn't matter, the control items of BEGIN are on the top > in the first part, and WHILE puts it items under them. > Yes, you're correct. BEGIN's address is on top for both sections. WHILE SWAPs or 1 CS-ROLLs. I was thinking BEGIN's address wasn't the 1st stack item in the while-repeat section... If that had been true, it would've required two definitions for CONTINUE. But, I still think it does matter for another reason. I've posted the reason in the reply to your post with your definition of CONTINUE. Rod Pemberton
[toc] | [prev] | [next] | [standalone]
Page 4 of 5 — ← Prev page 1 2 3 [4] 5 Next page →
Back to top | Article view | comp.lang.forth
csiph-web