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 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
| From | mhx@iae.nl |
|---|---|
| Date | 2012-08-24 22:51 -0700 |
| Message-ID | <9de50da8-abf6-4781-9c0e-9f7eb40d33d5@googlegroups.com> |
| In reply to | #15143 |
On Friday, August 24, 2012 10:47:04 PM UTC+2, Mark Wills wrote: [..] > CONTCASE ? In Dutch it might have connotations that are a little bit embarassing. -marcel
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-08-25 08:55 +0000 |
| Message-ID | <2012Aug25.105523@mips.complang.tuwien.ac.at> |
| In reply to | #15143 |
Mark Wills <markrobertwills@yahoo.co.uk> writes:
>CONTCASE
would suggest to me that it pairs with CASE.
- 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 | hughaguilar96@yahoo.com |
|---|---|
| Date | 2012-08-25 20:47 -0700 |
| Message-ID | <4de58c99-d87e-4851-9f94-0d7e9576d71a@googlegroups.com> |
| In reply to | #15143 |
On Friday, August 24, 2012 1:47:04 PM UTC-7, Mark Wills wrote: > > CONTCASE > > ? Wasn't that the heroine in The Hunger Games? Seriously, abbreviating words is a bad idea, and pasting words together without benefit of a hyphen is another bad idea --- although that is done in the German language all the time, which is the PERL of human languages. I don't like CASE at all. You tend to get gigantic functions that do several different things depending upon a code number that is passed into them that they check at run-time --- a complete violation of the Forth principle of having each function be short and do only one thing (remember the "universal processor" in the "Thinking Forth" book?). It is very difficult to test functions like that. Whenever I see programs featuring a big CASE, they are almost always C programs that have been ported to Forth and/or they were written by recalcitrant C programmers (which is pretty much what Anton Ertl is) --- the SWITCH statement is the foundation of C programming, where it is common to see a single SWITCH statement spanning hundreds of lines of source-code. When I worked at Testra my boss liked to use CASE. He was a hardware designer and he tended to think in terms of state-machines, which is what hardware is all about. This doesn't work very well for software though. P.S. --- Another thing that recalcitrant C programmers do is ignore compile-time altogether and just treat Forth like C with RPN syntax. Recently Anton Ertl argued against my suggestion that the control-flow stack be separate from the data stack. He said that it is "convenient" to use the data stack for control-flow stuff because nobody ever uses it for passing parameters into colon words at compile-time that will be picked up by LITERAL. It is obvious that he has never written colon words that execute at compile-time and generate other colon words --- but that is the essence of Forth programming! If you are not going to do that, then you might as well just program in C.
[toc] | [prev] | [next] | [standalone]
| From | "Rod Pemberton" <do_not_have@notemailnot.cmm> |
|---|---|
| Date | 2012-08-26 06:20 -0400 |
| Message-ID | <k1ct4q$4pa$1@speranza.aioe.org> |
| In reply to | #15165 |
<hughaguilar96@yahoo.com> wrote in message news:4de58c99-d87e-4851-9f94-0d7e9576d71a@googlegroups.com... > [...] Whenever I see programs featuring a big CASE, they are > almost always C programs that have been ported to Forth > and/or they were written by recalcitrant C programmers [...] > --- the SWITCH statement is the foundation of C programming, > where it is common to see a single SWITCH statement spanning > hundreds of lines of source-code. Well, it's definately not "the foundation" of C programming. Switches are not as common in C code as other control-flow. However, it's definately true some C programmers seem to embrace C's switch() much more than they ever should. I see excessively switched programs from time to time too. I also see programmers embrace C's for() too much. etc. FYI, ANSI C89/90 allows 257 and ISO C99 allows 1023 items in a switch. So, switches were designed to allow easy selection of a relatively "large" number of items (at the time). Personally, I think it's far more common to see a switch() with just a handful of items, followed by maybe 20 to 50 items. From what I've seen, the truly large switches are used with a large input set of non-contiguous integer values. If the set of input integer values is contiguous, you don't need a switch. You can use an array. The largest switch I have in C has 356 items. Why so many? Well, there are 356 different valid input text strings. The switch is given an integer from a hash function on the input string. This produces 356 different 32-bit integers. The integer values are not adjacent to each other. There are no hash collisions on that set of strings. That makes the switch() ideal. Otherwise, you're using many if's. That large switch is relatively recent. Most of mine are much smaller. What I think is my next largest switch has 100 items. That's still many. It too is tasked with separating strings from each other. It uses a simple hash function which has a few collisions that must be corrected. Another option in C is similar, switch based on the first character of the string which reduces you to 26 or 52 switch items, but then you need to do a bunch of string compares using if's, e.g., if you switched on 'r', you still need to separate "return" from "register". 356/26=14. So, if the strings were evenly distributed, which they aren't, you'd need an average of 14 if's per case. Obviously, that means you're likely to see one case with 28 or similar larger set of strings ... That would encourage using a hash function in the first place. The "worst" option in C is to loop through a string array and compare every string until the one you're looking for is found. I.e., like searching the dictionary in a simple interpreted Forth. The loop is to equate the string to a sequential integer index, i.e., one value from a contiguous set of integer values. The need to determine one string from another and take action for a specific string is needed for parsers and interpreters. How would you handle code selection for 356 different input strings in Forth? Rod Pemberton
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2012-08-26 11:04 -0500 |
| Message-ID | <QKCdnXJmkImb1KfNnZ2dnUVZ8vudnZ2d@supernews.com> |
| In reply to | #15172 |
Rod Pemberton <do_not_have@notemailnot.cmm> wrote: > > How would you handle code selection for 356 different input strings in > Forth? If you want an exact string match followed by an action, FIND and EXECUTE is probably a good choice. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-08-26 16:06 +0000 |
| Message-ID | <2012Aug26.180654@mips.complang.tuwien.ac.at> |
| In reply to | #15177 |
Andrew Haley <andrew29@littlepinkcloud.invalid> writes:
>Rod Pemberton <do_not_have@notemailnot.cmm> wrote:
>>
>> How would you handle code selection for 356 different input strings in
>> Forth?
>
>If you want an exact string match followed by an action, FIND and
>EXECUTE is probably a good choice.
SEARCH-WORDLIST is a better choice than FIND: No need to worry about
additional words in other wordlists.
- 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 | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2012-08-26 15:32 -0500 |
| Message-ID | <sZCdnQaRcvN9GqfNnZ2dnUVZ8nWdnZ2d@supernews.com> |
| In reply to | #15178 |
Anton Ertl <anton@mips.complang.tuwien.ac.at> wrote: > Andrew Haley <andrew29@littlepinkcloud.invalid> writes: >>Rod Pemberton <do_not_have@notemailnot.cmm> wrote: >>> >>> How would you handle code selection for 356 different input strings in >>> Forth? >> >>If you want an exact string match followed by an action, FIND and >>EXECUTE is probably a good choice. > > SEARCH-WORDLIST is a better choice than FIND: No need to worry about > additional words in other wordlists. True enough, but it makes no difference to the core point about Forth design: use the tools that are already there. I've seen programs that re-invent the dictionary, which shows this advice is not obvious! Andrew.
[toc] | [prev] | [next] | [standalone]
| From | Hugh Aguilar <hughaguilar96@yahoo.com> |
|---|---|
| Date | 2012-08-27 22:58 -0700 |
| Message-ID | <c5f3c16d-7be7-4ae7-b7f5-76b96ebad707@qa3g2000pbc.googlegroups.com> |
| In reply to | #15179 |
On Aug 26, 1:32 pm, Andrew Haley <andre...@littlepinkcloud.invalid> wrote: > Anton Ertl <an...@mips.complang.tuwien.ac.at> wrote: > > Andrew Haley <andre...@littlepinkcloud.invalid> writes: > >>Rod Pemberton <do_not_h...@notemailnot.cmm> wrote: > > >>> How would you handle code selection for 356 different input strings in > >>> Forth? > > >>If you want an exact string match followed by an action, FIND and > >>EXECUTE is probably a good choice. > > > SEARCH-WORDLIST is a better choice than FIND: No need to worry about > > additional words in other wordlists. > > True enough, but it makes no difference to the core point about Forth > design: use the tools that are already there. I've seen programs that > re-invent the dictionary, which shows this advice is not obvious! > > Andrew. My ASSOCIATION in the novice package does pretty much the same thing that the dictionary does. The advantage is that allows you to do an in- order traversal of the nodes within a particular region. If the ordering of your data isn't important though, then you don't need this feature so you might as well use the dictionary. Another advantage of ASSOCIATION is that it can use key data other than strings, such as floats for example --- once again, if you are just using strings, then the dictionary should work. Another advantage of ASSOCIATION is that it can be used in cross-compiled code in which the dictionary is not available at run-time. I've used the dictionary as an associative array myself in the past --- in my 65c02 source-level debugger for example.
[toc] | [prev] | [next] | [standalone]
| From | Gerry Jackson <gerry@jackson9000.fsnet.co.uk> |
|---|---|
| Date | 2012-08-26 22:07 +0100 |
| Message-ID | <k1e379$1k5$1@dont-email.me> |
| In reply to | #15141 |
On 24/08/2012 17:50, Anton Ertl wrote:
> Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes:
>> On 22/08/2012 15:26, Anton Ertl wrote:
>>
>>> BTW, the next version of Gforth will have a cute feature that's
>>> relevant in that context: It extends CASE to be a general control flow
>>> construct that can also loop in various ways:
>>>
>>> case
>>> ... ?of ... endof \ continues after ENDCASE/NEXTCASE
>>> ... ?of ... contof \ continues at CASE
>>> ... ?of ... endof \ continues after ENDCASE/NEXTCASE
>>> ...
>>> nextcase \ loop back to CASE
>>>
>> I like the idea, similar to an IT ... TI discussed in c.l.f archives but
>> merged into the existing CASE structure.
>>
>> Will NEXTCASE have the run-time stack effect (x -- ) like ENDCASE and
>> VFX Forth's NEXTCASE
>
> Yes, it has ( x -- ) to be compatible with VFX. Probably not that
> sensible when used with ?OF (which will usually be the case when using
> NEXTCASE).
>
>> or will it be ( -- ) like VFX Forth's NEXT-CASE
>
> Maybe we should provide NEXT-CASE *instead of* NEXTCASE.
>
>> Presumably ?OF run-time will be ( f -- )
>
> Yes.
>
>> Isn't there a better name than CONTOF e.g. REPEATCASE or even CONTINUE
>
> As usual, everyone will have their own idea for a better name; If you
> reach consensus on a good name, I'll happily adopt it. The reason for
> CONTOF is: The OF part indicates that this ends an OF (like ENDOF).
> The CONT part indicates that we continue at the start (like C's
> continue).
To experiment with your extended CASE I have implemented it in ANS
Forth, the code with tests is below. All CASE words have to be rewritten
because the new CASE has to leave a dest on the control flow stack
(CFS). It is a modified version of the code in section A.3.2.2.2 of the
ANS Forth standard. It is quite straightforward, words have to deal with
the extra dest on the CFS. The only messy bit is how ENDCASE handles
that extra dest as ANS Forth doesn't have a CS-DROP. The only way I
could think of was to compile a jump back to the dest but hide it by
placing a forward jump in front of it to skip over it, which is
inefficient. Perhaps optimising compilers will detect this dead code.
I've kept to the name CONTOF but still don't like it, I'm not very keen
on NEXTCASE either. I've introduced ?BREAK to avoid the empty ?OF ENDOF
which simply exits the CASE structure.
The tests work on GForth, VFX Forth, SwiftForth, Win32 Forth and
BigForth but fails with a 'structure not balanced' error on iForth 4.0.380
-------------------------------------------------------
: case ( -- dest 0 ) postpone begin 0 ; immediate
: cs-swap ( orig1/dest1 orig2/dest2 -- orig2/dest2 orig1/dest1 )
1 cs-roll
;
: of ( dest #of -- orig #of+1 ) \ run-time ( x1 x2 -- | x1 )
>r
postpone over postpone = postpone if postpone drop
cs-swap r> 1+
; immediate
: ?of ( dest #of -- orig dest #of+1 ) \ run-time ( f -- )
>r postpone if cs-swap r> 1+
; immediate
: endof ( orig dest #of -- orig2 dest #of ) \ run-time ( -- )
>r cs-swap postpone else cs-swap r>
; immediate
\ ?break is equivalent to an empty ?OF ENDOF
: ?break ( dest #of -- orig dest #of+1 ) \ run-time ( f -- )
>r postpone 0= postpone if cs-swap r> 1+
; immediate
: contof ( orig dest #of -> dest #of-1 ) \ run-time ( -- )
>r
0 cs-pick postpone again cs-swap postpone then
r> 1-
; immediate
: resolve-origs ( orig1 ... orign n -- )
0 ?do postpone then loop
;
: endcase ( orig1 ... orign dest #of -- ) \ run-time ( x -- )
>r postpone drop postpone ahead cs-swap postpone again
r> 1+ resolve-origs
; immediate
: nextcase ( orig1 ... orign dest #of -- ) \ run-time ( x -- )
>r postpone drop postpone again r> resolve-origs
; immediate
\ Tests require the Hayes tester or derivatives of it
testing CASE OF ENDOF ENDCASE
t{ : cs1 case 1 of 111 endof
2 of 222 endof
3 of 333 endof
>r 999 r>
endcase
; -> }t
t{ 1 cs1 -> 111 }t
t{ 2 cs1 -> 222 }t
t{ 3 cs1 -> 333 }t
t{ 4 cs1 -> 999 }t
\ Nested CASE's
t{ : cs2 >r case -1 of case r@ 1 of 100 endof
2 of 200 endof
>r -300 r>
endcase
endof
-2 of case r@ 1 of -99 endof
>r -199 r>
endcase
endof
>r 299 r>
endcase r> drop
; -> }t
t{ -1 1 cs2 -> 100 }t
t{ -1 2 cs2 -> 200 }t
t{ -1 3 cs2 -> -300 }t
t{ -2 1 cs2 -> -99 }t
t{ -2 2 cs2 -> -199 }t
t{ 0 2 cs2 -> 299 }t
testing ?of
t{ : cs3 ( n1 -- n2 )
case dup 1 = ?of 11 endof
dup 2 = ?of 22 endof
dup 3 = ?of 33 endof
44 over
endcase nip
; -> }t
t{ 1 cs3 -> 11 }t
t{ 2 cs3 -> 22 }t
t{ 3 cs3 -> 33 }t
t{ 9 cs3 -> 44 }t
testing nextcase
t{ : cs4 ( n1 -- n+ )
case 1 of 11 endof
2 of 22 endof
3 of 33 endof
44 swap 3 + dup
nextcase
; -> }t
t{ 0 cs4 -> 44 33 }t
t{ -1 cs4 -> 44 22 }t
t{ -2 cs4 -> 44 11 }t
t{ -3 cs4 -> 44 44 33 }t
testing contof
t{ : cs5 ( n1 -- n2 )
case 1 of 11 2 contof
dup 2 = ?of drop 22 4 contof
3 of 33 endof
44 3 rot
nextcase
; -> }t
t{ 1 cs5 -> 11 22 44 33 }t
testing ?break
t{ : cs6 ( n1 -- n ... n )
case 1+
dup 3 > ?break
dup 1 of 11 swap contof
2 of 22 swap contof
3 of 33 swap contof
44 -rot
nextcase drop
; -> }t
t{ 0 cs6 -> 11 22 33 }t
t{ -1 cs6 -> 44 11 22 33 }t
t{ -2 cs6 -> 44 44 11 22 33 }t
t{ : cs7 ( n1 -- n ... n )
case 1+
dup 3 > ?break
dup >r
0> ?of case r@ 1 of 11 endof
2 of 22 endof
3 of 33 endof
endcase r>
contof
44 r> dup
nextcase drop
; -> }t
t{ 0 cs7 -> 11 22 33 }t
t{ -1 cs7 -> 44 11 22 33 }t
t{ -2 cs7 -> 44 44 11 22 33 }t
--
Gerry
[toc] | [prev] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2012-08-27 18:14 +0200 |
| Message-ID | <61891708958435@frunobulax.edu> |
| In reply to | #15180 |
Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes Re: continue equivalent in Forth? > On 24/08/2012 17:50, Anton Ertl wrote: >> Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes: >>> On 22/08/2012 15:26, Anton Ertl wrote: [..] > The tests work on GForth, VFX Forth, SwiftForth, Win32 Forth and > BigForth but fails with a 'structure not balanced' error on iForth 4.0.380 [..] With the following extra lines at the top of gerry.frt: ----- ANEW -gerry NEEDS -ttester SECURE OFF VERBOSE ON ---- ... we can do FORTH> in c:/idfwforth/examples/internet/idata/gerry Creating --- John Hopkins TESTER Version 2.00 --- Redefining case Redefining of Redefining endof Redefining endcase testing CASE OF ENDOF ENDCASE testing ?of testing nextcase testing contof testing ?break I don't recommend turning of SECURE . -marcel
[toc] | [prev] | [next] | [standalone]
| From | Gerry Jackson <gerry@jackson9000.fsnet.co.uk> |
|---|---|
| Date | 2012-08-27 18:22 +0100 |
| Message-ID | <k1gaca$vu1$1@dont-email.me> |
| In reply to | #15195 |
On 27/08/2012 17:14, Marcel Hendrix wrote: > Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes Re: continue equivalent in Forth? > >> On 24/08/2012 17:50, Anton Ertl wrote: >>> Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes: >>>> On 22/08/2012 15:26, Anton Ertl wrote: > [..] > >> The tests work on GForth, VFX Forth, SwiftForth, Win32 Forth and >> BigForth but fails with a 'structure not balanced' error on iForth 4.0.380 > [..] > > With the following extra lines at the top of gerry.frt: > > ----- > ANEW -gerry > > NEEDS -ttester > SECURE OFF VERBOSE ON > ---- > > .... we can do > > FORTH> in c:/idfwforth/examples/internet/idata/gerry > Creating --- John Hopkins TESTER Version 2.00 --- > Redefining case > Redefining of > Redefining endof > Redefining endcase > testing CASE OF ENDOF ENDCASE > testing ?of > testing nextcase > testing contof > testing ?break > > I don't recommend turning of SECURE . > That's interesting, I now see that is mentioned in the manual. Why is this necessary for iForth but not for other ANS Forth systems? Only origs and a dest are on the CFS when CS-PICK and CS-ROLL are used so ISTM that SECURE on makes iForth non-compliant with ANS Forth when manipulating the control flow stack. -- Gerry
[toc] | [prev] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2012-08-27 20:45 +0200 |
| Message-ID | <56581508958435@frunobulax.edu> |
| In reply to | #15197 |
Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes Re: continue equivalent in Forth? > On 27/08/2012 17:14, Marcel Hendrix wrote: >> Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes Re: continue equivalent in Forth? [..] > I don't recommend turning off SECURE . [..] > That's interesting, I now see that is mentioned in the manual. Why is > this necessary for iForth but not for other ANS Forth systems? Only > origs and a dest are on the CFS when CS-PICK and CS-ROLL are used so > ISTM that SECURE on makes iForth non-compliant with ANS Forth when > manipulating the control flow stack. [..] Well, it is (obviously) not necessary for iForth to have SECURE on. The reason SECURE is on is painful memories of trying to compile large NOVIX block files. The SECURE feature can be permanently turned off by editing the iforth.prf file. Why don't other Forths have SECURE? They may have a fail-safe mechanism to catch silly errors that does not interfere with their CS-PICK etc. But ... -- ------------------------------- VFX Forth for Windows IA32 © MicroProcessor Engineering Ltd, 1998-2012 Version: 4.50 [build 3327] Build date: 17 April 2012 Free dictionary = 7561806 bytes [7384kb] : test begin 1 2 + else 3 then ; ok -- -------------------------------------- -- ---------------------------------------------------- SwiftForth i386-Win32 3.2.2 08-Jul-2010 base @ hex : testing again 10 20 + begin ; decimal ok -- ---------------------------------------------------- ... apparently passes unnoticed. (gForth can't be caught that easily.) Another reason for iForth's SECURE is that the compiler uses extra items on the CS stack to remember when registers should be spilled/loaded to/from the stacks for control flow nodes. Yet another reason is the somewhat complicated parallel programming structures. These extra CS items can be used to give better messages, but as that is not ANS compatible, there must be a way to turn them off. I am not claiming that having extra items on the CS stack is the only way to get the mentioned features. -marcel
[toc] | [prev] | [next] | [standalone]
| From | Gerry Jackson <gerry@jackson9000.fsnet.co.uk> |
|---|---|
| Date | 2012-08-27 21:43 +0100 |
| Message-ID | <k1gm5u$ien$1@dont-email.me> |
| In reply to | #15199 |
On 27/08/2012 19:45, Marcel Hendrix wrote: > Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes Re: continue equivalent in Forth? > >> On 27/08/2012 17:14, Marcel Hendrix wrote: >>> Gerry Jackson <gerry@jackson9000.fsnet.co.uk> writes Re: continue equivalent in Forth? > [..] >> I don't recommend turning off SECURE . > [..] >> That's interesting, I now see that is mentioned in the manual. Why is >> this necessary for iForth but not for other ANS Forth systems? Only >> origs and a dest are on the CFS when CS-PICK and CS-ROLL are used so >> ISTM that SECURE on makes iForth non-compliant with ANS Forth when >> manipulating the control flow stack. > > [..] > > Why don't other Forths have SECURE? They may have a fail-safe mechanism > to catch silly errors that does not interfere with their CS-PICK etc. > > But ... > > -- ------------------------------- > VFX Forth for Windows IA32 > © MicroProcessor Engineering Ltd, 1998-2012 > > Version: 4.50 [build 3327] > Build date: 17 April 2012 > > Free dictionary = 7561806 bytes [7384kb] > > > : test begin 1 2 + else 3 then ; ok > -- -------------------------------------- > > -- ---------------------------------------------------- > SwiftForth i386-Win32 3.2.2 08-Jul-2010 > base @ hex : testing again 10 20 + begin ; decimal ok > -- ---------------------------------------------------- > > .... apparently passes unnoticed. > > > (gForth can't be caught that easily.) Heh, even my system rejects rubbish like that, still I don't suppose those systems often encounter code like that. > > Another reason for iForth's SECURE is that the compiler uses > extra items on the CS stack to remember when registers should > be spilled/loaded to/from the stacks for control flow nodes. > > Yet another reason is the somewhat complicated parallel > programming structures. > > These extra CS items can be used to give better messages, but as > that is not ANS compatible, there must be a way to turn them off. > Thanks for that, I assumed there must be good reasons and I was interested to know what they were. -- Gerry
[toc] | [prev] | [next] | [standalone]
| From | "Elizabeth D. Rather" <erather@forth.com> |
|---|---|
| Date | 2012-08-27 12:15 -1000 |
| Message-ID | <mPudnZMuj5oNbKbNnZ2dnUVZ_qednZ2d@supernews.com> |
| In reply to | #15199 |
On 8/27/12 8:45 AM, Marcel Hendrix wrote: ... > > Why don't other Forths have SECURE? They may have a fail-safe mechanism > to catch silly errors that does not interfere with their CS-PICK etc. > > But ... > > -- ------------------------------- > VFX Forth for Windows IA32 > © MicroProcessor Engineering Ltd, 1998-2012 > > Version: 4.50 [build 3327] > Build date: 17 April 2012 > > Free dictionary = 7561806 bytes [7384kb] > > > : test begin 1 2 + else 3 then ; ok > -- -------------------------------------- > > -- ---------------------------------------------------- > SwiftForth i386-Win32 3.2.2 08-Jul-2010 > base @ hex : testing again 10 20 + begin ; decimal ok > -- ---------------------------------------------------- > > ... apparently passes unnoticed. Hmmm: SwiftForth i386-Mac OS X 3.4.2 11-Feb-2012 : test begin 1 2 + else 3 then ; Control structure mismatch Cheers, Elizabeth -- ================================================== Elizabeth D. Rather (US & Canada) 800-55-FORTH FORTH Inc. +1 310.999.6784 5959 West Century Blvd. Suite 700 Los Angeles, CA 90045 http://www.forth.com "Forth-based products and Services for real-time applications since 1973." ==================================================
[toc] | [prev] | [next] | [standalone]
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Date | 2012-08-28 20:43 +0200 |
| Message-ID | <56601507958435@frunobulax.edu> |
| In reply to | #15207 |
"Elizabeth D. Rather" <erather@forth.com> writes Re: continue equivalent in Forth? > On 8/27/12 8:45 AM, Marcel Hendrix wrote: [..] >> -- ---------------------------------------------------- >> SwiftForth i386-Win32 3.2.2 08-Jul-2010 >> base @ hex : testing again 10 20 + begin ; decimal ok >> -- ---------------------------------------------------- >> ... apparently passes unnoticed. > Hmmm: > SwiftForth i386-Mac OS X 3.4.2 11-Feb-2012 > : test begin 1 2 + else 3 then ; Control structure mismatch Hmmm? That is the VFX bug. What about the SwiftForth example above: SwiftForth i386-Win32 3.4.2 11-Feb-2012 base @ hex : testing again 10 20 + begin ; decimal ok Or do you imply that the OSX version of SwiftForth doesn't have the bug? -marcel
[toc] | [prev] | [next] | [standalone]
| From | "Ed" <invalid@nospam.com> |
|---|---|
| Date | 2012-08-29 17:10 +1000 |
| Message-ID | <k1kf2h$hd6$1@speranza.aioe.org> |
| In reply to | #15224 |
Marcel Hendrix wrote: > .. > Hmmm? That is the VFX bug. What about the SwiftForth example > above: > > SwiftForth i386-Win32 3.4.2 11-Feb-2012 > base @ hex : testing again 10 20 + begin ; decimal ok > > Or do you imply that the OSX version of SwiftForth doesn't have > the bug? Nice. Even DX-Forth swallows it :) Idiot-proofing has not been necessary in Forth. Are you saying it's time to reconsider?
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-08-28 15:56 +0000 |
| Message-ID | <2012Aug28.175604@mips.complang.tuwien.ac.at> |
| In reply to | #15199 |
mhx@iae.nl (Marcel Hendrix) writes:
>Why don't other Forths have SECURE?
What does SECURE do? Why should we have it?
>: test begin 1 2 + else 3 then ; ok
...
>(gForth can't be caught that easily.)
: test begin 1 2 + else 3 then ;
:1: expected orig
: test begin 1 2 + >>>else<<< 3 then ;
So Gforth usually notices when it does not get an orig, but something
else, and likewise it will complain if you pass it an orig while it
expects a dest. And every Forth-94 system is allowed to do this kind
of checking, as well as checking for unbalanced control flow stack,
e.g.:
: foo if ;
:2: unstructured
: foo if >>>;<<<
What does SECURE add? Is it worth the price of not being able to run
standard programs like Josh Grams implementation of CASE etc.?
>Another reason for iForth's SECURE is that the compiler uses
>extra items on the CS stack to remember when registers should
>be spilled/loaded to/from the stacks for control flow nodes.
Gforth uses larger CS items to remember which locals are alive at a
branch (orig) or branch target (dest); can be done nicely in a
Forth-94 compatible way, and I guess that's also true for your
register information. What do you do if SECURE is OFF?
>These extra CS items can be used to give better messages, but as
>that is not ANS compatible, there must be a way to turn them off.
Yes the error messages of Gforth could be better, e.g., the first one
could be "control structure mismatch, expected orig".
- 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-28 20:35 +0200 |
| Message-ID | <87681507958435@frunobulax.edu> |
| In reply to | #15221 |
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: continue equivalent in Forth?
> mhx@iae.nl (Marcel Hendrix) writes:
>>Why don't other Forths have SECURE?
> What does SECURE do? Why should we have it?
[..]
> : foo if ;
> :2: unstructured
> : foo if >>>;<<<
[..]
Why is gForth complaining?
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.
iForth:
FORTH> secure off ok
FORTH> : test if ; ok
[3]FORTH>
How to do this in gForth?
-marcel
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2012-08-30 12:32 +0000 |
| Message-ID | <2012Aug30.143252@mips.complang.tuwien.ac.at> |
| In reply to | #15223 |
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:
>>>Why don't other Forths have SECURE?
>
>> What does SECURE do? Why should we have it?
>[..]
>> : foo if ;
>> :2: unstructured
>> : foo if >>>;<<<
>[..]
>
>Why is gForth complaining?
>
>IF C CORE
...
>I see nothing here that allows an error message.
You are looking in the wrong place. If you look closely, you will
notice that it's the ";" that complained, not the IF. So let's look
at ";":
|6.1.0460 ;
|[...]
| Compilation: ( C: colon-sys -- )
So it is complaining, because there is something other than a
colon-sys on top of the control-flow stack.
>iForth:
>
>FORTH> secure off ok
>FORTH> : test if ; ok
>[3]FORTH>
>
>How to do this in gForth?
Do what? What is this supposed to mean? I can make something like
this piece of code compile without the compiler complaining with:
: test if [ 2drop drop ] ;
but somehow
: test drop ;
will work for the same cases (and one more) and seems more
straightforward.
- 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-30 22:39 +0200 |
| Message-ID | <61641305958435@frunobulax.edu> |
| In reply to | #15265 |
anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: continue equivalent in Forth? > mhx@iae.nl (Marcel Hendrix) writes: >>anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: continue equivalent in Forth? [..] > You are looking in the wrong place. If you look closely, you will > notice that it's the ";" that complained, not the IF. So let's look > at ";": > |6.1.0460 ; > |[...] > | Compilation: ( C: colon-sys -- ) > So it is complaining, because there is something other than a > colon-sys on top of the control-flow stack. >>iForth: >>FORTH> secure off ok >>FORTH> : test if ; ok >>[3]FORTH> >>How to do this in gForth? > Do what? What is this supposed to mean? I can make something like > this piece of code compile without the compiler complaining with: > : test if [ 2drop drop ] ; > but somehow > : test drop ; > will work for the same cases (and one more) and seems more > straightforward. 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 -marcel
[toc] | [prev] | [next] | [standalone]
Page 3 of 5 — ← Prev page 1 2 [3] 4 5 Next page →
Back to top | Article view | comp.lang.forth
csiph-web