Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #50446 > unrolled thread
| Started by | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| First post | 2016-08-24 15:27 +0000 |
| Last post | 2016-08-29 16:04 +0000 |
| Articles | 20 on this page of 75 — 19 participants |
Back to article view | Back to comp.lang.forth
Rosetta Code: Catamorphism "WJ" <w_a_x_man@yahoo.com> - 2016-08-24 15:27 +0000
Rosetta Code: Catamorphism Julian Fondren <julian.fondren@gmail.com> - 2016-08-24 12:43 -0700
Re: Rosetta Code: Catamorphism anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-25 09:53 +0000
Re: Rosetta Code: Catamorphism Julian Fondren <julian.fondren@gmail.com> - 2016-08-25 06:41 -0700
Re: Rosetta Code: Catamorphism Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-08-25 16:06 -0500
Re: Rosetta Code: Catamorphism foxaudioresearch@gmail.com - 2016-08-25 20:40 -0700
Rosetta Code ( was Re: Rosetta Code: Catamorphism) "HAA" <someone@microsoft.com> - 2016-08-29 12:06 +1000
Re: Rosetta Code ( was Re: Rosetta Code: Catamorphism) Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-08-29 01:41 -0500
Re: Rosetta Code: Catamorphism anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-27 10:01 +0000
Re: Rosetta Code: Catamorphism hughaguilar96@gmail.com - 2016-08-29 01:21 -0700
Re: Rosetta Code: Catamorphism hughaguilar96@gmail.com - 2016-08-29 01:36 -0700
Re: Rosetta Code: Catamorphism Julian Fondren <ayrnieu@gmail.com> - 2016-08-29 07:23 -0700
Re: Rosetta Code: Catamorphism anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-29 16:58 +0000
Re: Rosetta Code: Catamorphism peter.m.falth@gmail.com - 2016-08-29 13:15 -0700
Re: Rosetta Code: Catamorphism anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-29 20:53 +0000
Re: Rosetta Code: Catamorphism peter.m.falth@gmail.com - 2016-08-30 04:47 -0700
Re: Rosetta Code: Catamorphism anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-09-05 07:13 +0000
Re: Rosetta Code: Catamorphism "HAA" <someone@microsoft.com> - 2016-08-30 11:54 +1000
Re: Rosetta Code: Catamorphism "HAA" <someone@microsoft.com> - 2016-08-31 12:34 +1000
Re: Rosetta Code: Catamorphism "HAA" <someone@microsoft.com> - 2016-08-29 18:44 +1000
Re: Rosetta Code: Catamorphism hughaguilar96@gmail.com - 2016-09-01 23:47 -0700
Re: Rosetta Code: Catamorphism Coos Haak <htrofhc@gmail.com> - 2016-09-02 12:42 +0200
Re: Rosetta Code: Catamorphism anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-09-02 11:45 +0000
Re: Rosetta Code: Catamorphism Coos Haak <htrofhc@gmail.com> - 2016-09-02 15:01 +0200
Re: Rosetta Code: Catamorphism anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-09-02 16:04 +0000
Re: Rosetta Code: Catamorphism albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-09-02 16:23 +0200
Re: Rosetta Code: Catamorphism Bruce Axtens <bruce.axtens@gmail.com> - 2016-08-29 18:29 +0800
Re: Rosetta Code: Catamorphism Ron Aaron <rambamist@gmail.com> - 2016-08-29 13:41 +0300
Re: Rosetta Code: Catamorphism Bruce Axtens <bruce.axtens@gmail.com> - 2016-08-31 09:24 +0800
Standard or Forth? "HAA" <someone@microsoft.com> - 2016-09-01 13:45 +1000
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-02 21:54 -0700
Re: Standard or Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-09-04 07:35 +0100
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-04 00:41 -0700
Re: Standard or Forth? Julian Fondren <julian.fondren@gmail.com> - 2016-09-04 02:55 -0700
Re: Standard or Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-09-04 13:26 +0100
Re: Standard or Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-09-04 13:59 +0000
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-04 23:09 -0700
Re: Standard or Forth? Ron Aaron <rambamist@gmail.com> - 2016-09-05 09:55 +0300
Re: Standard or Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-09-05 08:39 +0100
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-04 01:25 -0700
Re: Standard or Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-09-04 14:13 +0100
Re: Standard or Forth? Coos Haak <htrofhc@gmail.com> - 2016-09-04 23:16 +0200
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-04 22:33 -0700
Re: Standard or Forth? Ron Aaron <rambamist@gmail.com> - 2016-09-05 09:03 +0300
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-06 23:23 -0700
Re: Standard or Forth? Ron Aaron <rambamist@gmail.com> - 2016-09-07 10:14 +0300
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-07 01:01 -0700
Re: Standard or Forth? Ron Aaron <rambamist@gmail.com> - 2016-09-07 11:18 +0300
Re: Standard or Forth? Cecil Bayona <cbayona@cbayona.com> - 2016-09-07 08:47 -0500
Re: Standard or Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-09-05 09:20 +0100
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-05 02:21 -0700
Re: Standard or Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-09-05 08:10 +0000
Re: Standard or Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-09-05 10:51 +0100
Re: Standard or Forth? "Elizabeth D. Rather" <erather@forth.com> - 2016-09-03 08:05 +0200
Re: Standard or Forth? Andrew Haley <andrew29@littlepinkcloud.invalid> - 2016-09-03 03:00 -0500
Re: Standard or Forth? "HAA" <someone@microsoft.com> - 2016-09-03 22:48 +1000
Re: Standard or Forth? Alex <alex@rivadpm.com> - 2016-09-03 15:05 +0100
Re: Standard or Forth? Julian Fondren <julian.fondren@gmail.com> - 2016-09-03 07:46 -0700
Re: Standard or Forth? "Elizabeth D. Rather" <erather@forth.com> - 2016-09-03 23:53 +0200
Re: Standard or Forth? stephen@mpeforth.com (Stephen Pelc) - 2016-09-03 22:37 +0000
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-03 21:17 -0700
Re: Standard or Forth? "HAA" <someone@microsoft.com> - 2016-09-05 02:35 +1000
Re: Standard or Forth? albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-09-05 03:18 +0200
Re: Standard or Forth? "HAA" <someone@microsoft.com> - 2016-09-08 22:04 +1000
Re: Standard or Forth? Paul Rubin <no.email@nospam.invalid> - 2016-09-08 12:41 -0700
Re: Standard or Forth? "HAA" <someone@microsoft.com> - 2016-09-09 12:51 +1000
Re: Standard or Forth? Paul Rubin <no.email@nospam.invalid> - 2016-09-08 21:50 -0700
Re: Standard or Forth? "HAA" <someone@microsoft.com> - 2016-09-12 17:16 +1000
Re: Standard or Forth? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-09-12 16:59 +0000
Re: Standard or Forth? "HAA" <someone@microsoft.com> - 2016-09-15 13:38 +1000
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-08 23:33 -0700
Re: Standard or Forth? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-09-05 08:41 +0100
Re: Standard or Forth? hughaguilar96@gmail.com - 2016-09-05 01:42 -0700
Re: Rosetta Code: Catamorphism albert@cherry.spenarnc.xs4all.nl (Albert van der Horst) - 2016-08-29 16:03 +0200
Re: Rosetta Code: Catamorphism anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-08-29 16:04 +0000
Page 1 of 4 [1] 2 3 4 Next page →
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Date | 2016-08-24 15:27 +0000 |
| Subject | Rosetta Code: Catamorphism |
| Message-ID | <npkec6$gnu$1@dont-email.me> |
> Reduce is a function or method that is used to take the values
> in an array or a list and apply a function to successive
> members of the list to produce (or reduce them to), a single
> value.
>
> Show how reduce (or foldl or foldr etc), work (or would be
> implemented) in your language.
Ruby:
["eeny-meeny", 'teeny-tiny', 'flip-flop', 'willy-nilly', "about-face",
'well-worn', "mass-produced", 'in-basket'].
reduce([[[],[]],[[],[]]]){|result,word|
result.zip([:min,:max]).map{|a_b,method|
a_b.zip(word.split("-")).map{|s1,s2| [*s1,s2].send(method)}}
}.map{|array| array.join "-"}
==>["about-basket", "willy-worn"]
In Forth?
--
[T]he broadcast media ... create a separate and caustic virtual reality, then
broadcast that ideologically driven reality into the homes of millions of
people.... theoccidentalobserver.net/authors/Connelly-Gaza2.html
[toc] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2016-08-24 12:43 -0700 |
| Message-ID | <c3dd18a9-e76d-4260-bc20-a530d6abf2f0@googlegroups.com> |
| In reply to | #50446 |
https://rosettacode.org/wiki/Catamorphism#Forth
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-08-25 09:53 +0000 |
| Message-ID | <2016Aug25.115318@mips.complang.tuwien.ac.at> |
| In reply to | #50453 |
Julian Fondren <julian.fondren@gmail.com> writes:
>https://rosettacode.org/wiki/Catamorphism#Forth
Do you want to say anything?
The discussion is fine, but it's probably better to illustrate the
points with examples right away. I have used smaller examples for
this kind of stuff in the Gforth tutorial, and I think that smaller
examples are better, because the additional stuff in the longer
example obscures the point.
E.g., higher-order words (map-array)
<https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Execution-Tokens-Tutorial.html>:
: map-array ( ... addr u xt -- ... )
\ executes xt ( ... x -- ... ) for every element of the array starting
\ at addr and containing u elements
{ xt }
cells over + swap ?do
i @ xt execute
1 cells +loop ;
create a 3 , 4 , 2 , -1 , 4 ,
a 5 ' . map-array .s
0 a 5 ' + map-array .
s" max-n" environment? drop .s
a 5 ' min map-array .
Macros (slide 5 of
<https://www.complang.tuwien.ac.at/anton/lvas/stack-sprachen/slides.pdf>).
: (map) ( a n -- a a') cells over + swap ;
: map< ( -- ) postpone (map) postpone ?do postpone i postpone @ ; immediate
: >map ( -- ) 1 cells postpone literal postpone +loop ; immediate
: .array ( addr u -- )
map< . >map ;
: sum-array ( addr u -- n )
0 rot rot map< + >map ;
I leave it to you to do the corresponding example for an explicit loop.
- 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 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | Julian Fondren <julian.fondren@gmail.com> |
|---|---|
| Date | 2016-08-25 06:41 -0700 |
| Message-ID | <0db03101-1891-4b65-b444-c31941b48294@googlegroups.com> |
| In reply to | #50466 |
On Thursday, August 25, 2016 at 5:12:50 AM UTC-5, Anton Ertl wrote: > Julian Fondren <julian.fondren@gmail.com> writes: > >https://rosettacode.org/wiki/Catamorphism#Forth > > Do you want to say anything? Alright, WJ's hit a new low, pointing out such omissions is just noise. Of that RC page: In other languages, a catamorphism requires a zoo of similar functions with subtle differences. Do you want to thread a value through things? How about multiple values? Or no values, as you're only interested in side effects? Would you like to populate a new list with each value? In other languages: reduce, reduce2, foreach, map. In Forth you only need one 'function'. And it's not because you're choosing to wear a hair shirt, or because some linguistic feature is lost in translation, but because the data stack removes the distinctions between these functions that matter so much to other languages. Additionally, the data stack makes it much easier to *think* about what's going on, especially vs. folds. Forth is a nice language but this is a rare moment of Forth supremacy. Forth calls snow 'snow' and plows it effortlessly into piles wherever it's found; poverty demands that other languages have 15 different words for 'snow' because they need to know whether to bring salt, their hands in mittens, a hand shovel, a long shovel, a horse-drawn plow, a flamethrower, etc., to deal with the snow deposit's precise conditions. "Oh no, I brought a flamethrower but this is actually *medium-thick snow on grass*, so I need to go back to the shed and get a *flat-head broad long-shovel*." > : (map) ( a n -- a a') cells over + swap ; > : map< ( -- ) postpone (map) postpone ?do postpone i postpone @ ; immediate > : >map ( -- ) 1 cells postpone literal postpone +loop ; immediate > > : .array ( addr u -- ) > map< . >map ; > > : sum-array ( addr u -- n ) > 0 rot rot map< + >map ; The avoidance of BOUNDS and -ROT and ]] ... [[ make me think that this is tutorial code. That's fine, but Rosetta Code isn't a tutorial. Idiomatic code is better, even if a listing must then have several sub-listings due to competing idioms. -- Julian
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2016-08-25 16:06 -0500 |
| Message-ID | <rLKdnatXicdAwCLKnZ2dnUU78LudnZ2d@supernews.com> |
| In reply to | #50474 |
Julian Fondren <julian.fondren@gmail.com> wrote: > > The avoidance of BOUNDS and -ROT and ]] ... [[ make me think that > this is tutorial code. FWIW, I wouldn't use any of those words either. I like OVER + SWAP. :-) Andrew.
[toc] | [prev] | [next] | [standalone]
| From | foxaudioresearch@gmail.com |
|---|---|
| Date | 2016-08-25 20:40 -0700 |
| Message-ID | <87d95deb-2d13-4970-a432-7d147fefea1a@googlegroups.com> |
| In reply to | #50477 |
On Thursday, August 25, 2016 at 5:06:39 PM UTC-4, Andrew Haley wrote: > Julian Fondren <julian.fondren@gmail.com> wrote: > > > > The avoidance of BOUNDS and -ROT and ]] ... [[ make me think that > > this is tutorial code. > > FWIW, I wouldn't use any of those words either. I like > OVER + SWAP. :-) > > Andrew. And arguably one needs to be a little more tutorial with Forth on Rosetta since for most viewers it is already incomprehensible. BF
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-08-29 12:06 +1000 |
| Subject | Rosetta Code ( was Re: Rosetta Code: Catamorphism) |
| Message-ID | <nq05av$1kj8$1@gioia.aioe.org> |
| In reply to | #50483 |
foxaudioresearch@gmail.com wrote: > On Thursday, August 25, 2016 at 5:06:39 PM UTC-4, Andrew Haley wrote: > > Julian Fondren <julian.fondren@gmail.com> wrote: > > > > > > The avoidance of BOUNDS and -ROT and ]] ... [[ make me think that > > > this is tutorial code. > > > > FWIW, I wouldn't use any of those words either. I like > > OVER + SWAP. :-) > > > > Andrew. > > And arguably one needs to be a little more tutorial with Forth on Rosetta since for > most viewers it is already incomprehensible. > > BF You are assuming non-Forthers are going to be interested enough to read it. That's unlikely. Unlike the artifact from which it took its name, Rosetta Code doesn't say 'translate this psuedo-code into your language'. It says 'get this result'. So it becomes a contest of languages where the object is to win (or at least be in the game). A comparison or educational tool requires you to explain the steps, whereas a contest only requires you to play by the rules.
[toc] | [prev] | [next] | [standalone]
| From | Andrew Haley <andrew29@littlepinkcloud.invalid> |
|---|---|
| Date | 2016-08-29 01:41 -0500 |
| Subject | Re: Rosetta Code ( was Re: Rosetta Code: Catamorphism) |
| Message-ID | <tKSdnUnNEPqJRF7KnZ2dnUU7-T2dnZ2d@supernews.com> |
| In reply to | #50535 |
HAA <someone@microsoft.com> wrote: > foxaudioresearch@gmail.com wrote: >> And arguably one needs to be a little more tutorial with Forth on >> Rosetta since for most viewers it is already incomprehensible. > > You are assuming non-Forthers are going to be interested enough to > read it. That's unlikely. No it isn't. I know that because I am interested in what other lanaguages' code looks like, and it would be extraordinary if it didn't work that way for all languages. Andrew.
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-08-27 10:01 +0000 |
| Message-ID | <2016Aug27.120140@mips.complang.tuwien.ac.at> |
| In reply to | #50474 |
Julian Fondren <julian.fondren@gmail.com> writes:
>On Thursday, August 25, 2016 at 5:12:50 AM UTC-5, Anton Ertl wrote:
>> Julian Fondren <julian.fondren@gmail.com> writes:
>> >https://rosettacode.org/wiki/Catamorphism#Forth
>>
>> Do you want to say anything?
>
>Alright, WJ's hit a new low, pointing out such omissions is just
>noise.
I still don't get it. Ah, after trying "Goto Parent" another time,
despite the posting looking like a thread-opening posting (no "Re:",
no cited text), I actually find that it is a followup to a WJ posting.
>In other languages: reduce, reduce2, foreach, map.
>
>In Forth you only need one 'function'.
Yes, mostly. One exception: If you want to update the entries, you
probably want another one that gives the address of the entry instead
of the value.
>> : (map) ( a n -- a a') cells over + swap ;
>> : map< ( -- ) postpone (map) postpone ?do postpone i postpone @ ; immediate
>> : >map ( -- ) 1 cells postpone literal postpone +loop ; immediate
>>
>> : .array ( addr u -- )
>> map< . >map ;
>>
>> : sum-array ( addr u -- n )
>> 0 rot rot map< + >map ;
>
>The avoidance of BOUNDS and -ROT and ]] ... [[ make me think that
>this is tutorial code.
Yes, it's from my lecture notes. It's also standard code.
>That's fine, but Rosetta Code isn't a
>tutorial. Idiomatic code is better, even if a listing must then
>have several sub-listings due to competing idioms.
I guess "Works with Gforth" is enough if you want to use these
features. If you update the entry, it's up to you what you use.
My take on these things is this:
* For people who don't know Forth, and don't want to learn it, I guess
the shorter versions are more impressive (one more reason to avoid
weighing down the example with unrelated stuff).
* For people who don't know Forth, and for which you want to explain
it, it depends on what you want to explain to them (standard code in
the example above).
* For people who know Forth, it depends on what they know. POSTPONE
might be wider known than ]]...[[. However, I find it interesting
that you consider ]]...[[ more idiomatic. That may well be the
case: The Forth community seems to be divided into two groups: Those
who write this kind of macros, and I guess that many of us use
]]...[[; those who write EVALUATE-based macros, so no POSTPONE,
either; and those who think that macros are for gurus, and they
don't use POSTPONE, either.
Anyway, let's see what the code above looks like with ]]...[[ and BOUNDS:
: map< ( -- ) ]] cells bounds ?do i @ [[ ; immediate
: >map ( -- ) ]] 1 +loop [[ ; immediate
\ .array and sum-array look the same
- 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 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-08-29 01:21 -0700 |
| Message-ID | <836dda04-3aea-4e2f-83b1-574930d88525@googlegroups.com> |
| In reply to | #50505 |
On Saturday, August 27, 2016 at 3:53:59 AM UTC-7, Anton Ertl wrote:
> Anyway, let's see what the code above looks like with ]]...[[ and BOUNDS:
>
> : map< ( -- ) ]] cells bounds ?do i @ [[ ; immediate
> : >map ( -- ) ]] 1 +loop [[ ; immediate
This is how they look with MACRO: from the novice-package (it is ANS-Forth, as is everything in the novice-package):
macro: map< ( -- )
cells bounds ?do i @ ;
macro: >map ( -- )
1 +loop ;
Personally, I find ]] and [[ to be very hard to read, mostly because they are being used as brackets but they are backwards (pointing outward rather than pointing inward).
I'm not familiar with ]] and [[ --- are these ANS-Forth? --- or are these Forth-200x?
[toc] | [prev] | [next] | [standalone]
| From | hughaguilar96@gmail.com |
|---|---|
| Date | 2016-08-29 01:36 -0700 |
| Message-ID | <2c7a5c2a-ff8b-42fc-86cf-41887efce07a@googlegroups.com> |
| In reply to | #50545 |
On Monday, August 29, 2016 at 1:21:48 AM UTC-7, hughag...@gmail.com wrote:
> On Saturday, August 27, 2016 at 3:53:59 AM UTC-7, Anton Ertl wrote:
> > Anyway, let's see what the code above looks like with ]]...[[ and BOUNDS:
> >
> > : map< ( -- ) ]] cells bounds ?do i @ [[ ; immediate
> > : >map ( -- ) ]] 1 +loop [[ ; immediate
>
> This is how they look with MACRO: from the novice-package (it is ANS-Forth, as is everything in the novice-package):
>
> macro: map< ( -- )
> cells bounds ?do i @ ;
>
> macro: >map ( -- )
> 1 +loop ;
Actually, this is completely screwed up. Here it is again --- I think this is correct:
macro: map< ( a n -- )
cells bounds ?do I @ ;
macro: >map ( -- )
1 cells +loop ;
I haven't tested this --- you didn't test your code either though --- I'm not actually paying attention to the problem that we are supposedly solving, but I'm just showing how MACRO: works as compared to your macros.
This is a WJ thread --- just a lot of nonsense anyway.
[toc] | [prev] | [next] | [standalone]
| From | Julian Fondren <ayrnieu@gmail.com> |
|---|---|
| Date | 2016-08-29 07:23 -0700 |
| Message-ID | <cbdcd712-4fc3-4aa5-b647-221e43fc12a5@googlegroups.com> |
| In reply to | #50546 |
On Monday, August 29, 2016 at 3:21:48 AM UTC-5, hughag...@gmail.com wrote: > On Saturday, August 27, 2016 at 3:53:59 AM UTC-7, Anton Ertl wrote: > > Anyway, let's see what the code above looks like with ]]...[[ and BOUNDS: > > > > : map< ( -- ) ]] cells bounds ?do i @ [[ ; immediate > > : >map ( -- ) ]] 1 +loop [[ ; immediate > > This is how they look with MACRO: from the novice-package (it is ANS-Forth, as is everything in the novice-package): > > macro: map< ( -- ) > cells bounds ?do i @ ; > > macro: >map ( -- ) > 1 +loop ; > And here's how they look with EVALUATE: : map< ( -- ) S" CELLS BOUNDS ?DO I @" EVALUATE ; IMMEDIATE : >map ( -- ) S" 1 CELLS +LOOP" EVALUATE ; IMMEDIATE Which looks no worse, really, and which makes it explicit that this word uses EVALUATE and therefore requires a certain search order to make a certain sense. > I'm not familiar with ]] and [[ --- are these ANS-Forth? --- or are these Forth-200x? it's a gforth extension. I don't mind POSTPONE POSTPONE POSTPONE in my own code, where I generally use case and extra comments, but it's damned ugly and if I were showing Forth off it's the first thing that'd go. On Monday, August 29, 2016 at 3:43:57 AM UTC-5, HAA wrote: > > A possible implementation is > > : ]] \ multiple POSTPONE handler > begin > >in @ bl word count ?dup if > s" [[" compare if > >in ! postpone postpone true > else drop false then > else 2drop refill then 0= > until ; immediate Special treatment is needed for literals. If you have a recognizer stack, this is easier to implement and will work with user-created literals. On Monday, August 29, 2016 at 3:36:18 AM UTC-5, hughag...@gmail.com wrote: > > This is a WJ thread --- just a lot of nonsense anyway. By the way, when you mark his threads spam, you're training the filter to consider code to be spam, and *actual* spam to be less as spammy as before. You're abusing a public good for personal reasons, and are making it worse, when it would be less work to avert your eyes and less of a chore to get a real Usenet client with a kill list. You deserve an inbox filled with penis pills and Nigerian princes. -- Julian
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-08-29 16:58 +0000 |
| Message-ID | <2016Aug29.185823@mips.complang.tuwien.ac.at> |
| In reply to | #50553 |
Julian Fondren <ayrnieu@gmail.com> writes:
>And here's how they look with EVALUATE:
>
> : map< ( -- ) S" CELLS BOUNDS ?DO I @" EVALUATE ; IMMEDIATE
> : >map ( -- ) S" 1 CELLS +LOOP" EVALUATE ; IMMEDIATE
>
>Which looks no worse, really, and which makes it explicit that this
>word uses EVALUATE and therefore requires a certain search order to
>make a certain sense.
Not just a search order, but also no other definitions of these words
in these wordlists.
As for why the direction of
]]...[[
is in this direction: It's because
] ... [
switches from interpretation to compilation and back; likewise, ]]
switches from compilation to postponing and [[ switches back.
--
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 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | peter.m.falth@gmail.com |
|---|---|
| Date | 2016-08-29 13:15 -0700 |
| Message-ID | <2fd53f27-16d9-431c-bf39-ec16c6be9f38@googlegroups.com> |
| In reply to | #50558 |
On Monday, 29 August 2016 19:24:46 UTC+2, Anton Ertl wrote: > Julian Fondren <ayrnieu@gmail.com> writes: > >And here's how they look with EVALUATE: > > > > : map< ( -- ) S" CELLS BOUNDS ?DO I @" EVALUATE ; IMMEDIATE > > : >map ( -- ) S" 1 CELLS +LOOP" EVALUATE ; IMMEDIATE > > > >Which looks no worse, really, and which makes it explicit that this > >word uses EVALUATE and therefore requires a certain search order to > >make a certain sense. > > Not just a search order, but also no other definitions of these words > in these wordlists. > > As for why the direction of > > ]]...[[ > > is in this direction: It's because > > ] ... [ > > switches from interpretation to compilation and back; likewise, ]] > switches from compilation to postponing and [[ switches back. This is why I think you got it backwards. I see it as [ switches from compilation to interpretation and ] back to compiling therefore [[ should switch from compilation to postponing and ]] back to compiling it really looks backwards now! or it could be post[ ... ]pone for extra clarity BR Peter Fälth > -- > 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 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-08-29 20:53 +0000 |
| Message-ID | <2016Aug29.225348@mips.complang.tuwien.ac.at> |
| In reply to | #50559 |
peter.m.falth@gmail.com writes:
>On Monday, 29 August 2016 19:24:46 UTC+2, Anton Ertl wrote:
>> As for why the direction of
>>=20
>> ]]...[[
>>=20
>> is in this direction: It's because
>>=20
>> ] ... [
>>=20
>> switches from interpretation to compilation and back; likewise, ]]
>> switches from compilation to postponing and [[ switches back.
>=20
>This is why I think you got it backwards. I see it as
>[ switches from compilation to interpretation and ] back to compiling
>
>therefore=20
>
>[[ should switch from compilation to postponing and ]] back to compiling
>=20
If you see it as different things, and compilation as the normal mode,
you have a point.
The basic idea behind ]]...[[ is that ] switches to the next more
delaying state (from interpretation to compilation, from compilation
to postponing), and [ to the next less delaying state (from postponing
to compiling, from compiling to interpreting); however, unfortunately,
the standard specifies "]" in a way that does not allow working the
way envisioned above, so "]]" was introduced instead, and "[[" to go
with it. And the current implementation only do the switching from
compilation to postponing, and back, not the full monty.
It may be more obvious why the brackets have this direction, if you
want to have some intermediate compilation action in the middle of the
postponeing, e.g.:
: derivative { xt1 F: r -- xt2 }
:noname ]]
fdup [[ r ]] fliteral f+ [[ xt1 compile, ]] fswap [[ xt1 compile, ]] f-
[[ r ]] fliteral f/ ;
[[ ;
>it really looks backwards now!
Looking at the DERIVATIVE example, do you still think so?
>or it could be post[ ... ]pone for extra clarity
Or use that for DERIVATIVE?
- 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 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | peter.m.falth@gmail.com |
|---|---|
| Date | 2016-08-30 04:47 -0700 |
| Message-ID | <c76b775f-d3e6-44f8-a601-3fa83e1c2172@googlegroups.com> |
| In reply to | #50560 |
On Monday, 29 August 2016 23:16:15 UTC+2, Anton Ertl wrote:
> peter.m.falth@gmail.com writes:
> >On Monday, 29 August 2016 19:24:46 UTC+2, Anton Ertl wrote:
> >> As for why the direction of
> >>=20
> >> ]]...[[
> >>=20
> >> is in this direction: It's because
> >>=20
> >> ] ... [
> >>=20
> >> switches from interpretation to compilation and back; likewise, ]]
> >> switches from compilation to postponing and [[ switches back.
> >=20
> >This is why I think you got it backwards. I see it as
> >[ switches from compilation to interpretation and ] back to compiling
> >
> >therefore=20
> >
> >[[ should switch from compilation to postponing and ]] back to compiling
> >=20
>
> If you see it as different things, and compilation as the normal mode,
> you have a point.
>
> The basic idea behind ]]...[[ is that ] switches to the next more
> delaying state (from interpretation to compilation, from compilation
> to postponing), and [ to the next less delaying state (from postponing
> to compiling, from compiling to interpreting); however, unfortunately,
> the standard specifies "]" in a way that does not allow working the
> way envisioned above, so "]]" was introduced instead, and "[[" to go
> with it. And the current implementation only do the switching from
> compilation to postponing, and back, not the full monty.
>
> It may be more obvious why the brackets have this direction, if you
> want to have some intermediate compilation action in the middle of the
> postponeing, e.g.:
>
> : derivative { xt1 F: r -- xt2 }
> :noname ]]
> fdup [[ r ]] fliteral f+ [[ xt1 compile, ]] fswap [[ xt1 compile, ]] f-
> [[ r ]] fliteral f/ ;
> [[ ;
>
> >it really looks backwards now!
>
> Looking at the DERIVATIVE example, do you still think so?
Yes and it looks real horrible. I would have written
: derivative { xt1 F: r -- xt2 }
:noname
postpone fdup r postpone fliteral postpone f+ xt1 compile,
postpone fswap xt1 compile, postpone f-
r postpone fliteral postpone f/ postpone ;
;
> >or it could be post[ ... ]pone for extra clarity
>
> Or use that for DERIVATIVE?
make it shorter as p[ and ]p and it does look somewhat better
: derivative { xt1 F: r -- xt2 }
:noname
p[ fdup ]p r p[ fliteral f+ ]p xt1 compile, p[ fswap ]p xt1 compile,
p[ f- ]p
r p[ fliteral f/ ; p]
;
BR
Peter
> - 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 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | anton@mips.complang.tuwien.ac.at (Anton Ertl) |
|---|---|
| Date | 2016-09-05 07:13 +0000 |
| Message-ID | <2016Sep5.091302@mips.complang.tuwien.ac.at> |
| In reply to | #50569 |
peter.m.falth@gmail.com writes:
>On Monday, 29 August 2016 23:16:15 UTC+2, Anton Ertl wrote:
>> The basic idea behind ]]...[[ is that ] switches to the next more
>> delaying state (from interpretation to compilation, from compilation
>> to postponing), and [ to the next less delaying state (from postponing
>> to compiling, from compiling to interpreting); however, unfortunately,
>> the standard specifies "]" in a way that does not allow working the
>> way envisioned above, so "]]" was introduced instead, and "[[" to go
>> with it. And the current implementation only do the switching from
>> compilation to postponing, and back, not the full monty.
>>
>> It may be more obvious why the brackets have this direction, if you
>> want to have some intermediate compilation action in the middle of the
>> postponeing, e.g.:
>>
>> : derivative { xt1 F: r -- xt2 }
>> :noname ]]
>> fdup [[ r ]] fliteral f+ [[ xt1 compile, ]] fswap [[ xt1 compile, ]] f-
>> [[ r ]] fliteral f/ ;
>> [[ ;
>>
>> >it really looks backwards now!
>>
>> Looking at the DERIVATIVE example, do you still think so?
>
>Yes and it looks real horrible. I would have written
>
>: derivative { xt1 F: r -- xt2 }
> :noname
> postpone fdup r postpone fliteral postpone f+ xt1 compile,
> postpone fswap xt1 compile, postpone f-
> r postpone fliteral postpone f/ postpone ;
> ;
I find the bracketed variant much more readable. It's hard to follow
the logic with all the POSTPONEs in between.
One thing I forgot to mention: The idea is also to be able to take the
code out of the colon definition for testing. In this case this would
look like:
1e-6 fvalue r
' fsin value xt1
:noname
fdup [ r ] fliteral f+ [ xt1 compile, ] fswap [ xt1 compile, ] f-
[ r ] fliteral f/ ;
Unfortunately, we cannot use [ and ] for postpone state; what could
work is to let [[ work in compile state and ]] in interpret state,
with the meanings of [ and ] in these states, but there is no
implementation for that yet; with that we could cut and paste most of
the code from DERIVATIVE for interpretation.
The remaining difference is that we have ":noname ]]" in DERIVATIVE,
but just ":noname" interpretively; If we have a factor (say, :NONAME[)
that does not switch to compile state at its run-time, we could use
":noname[ ]]" in both cases.
- 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 2016: http://www.euroforth.org/ef16/
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-08-30 11:54 +1000 |
| Message-ID | <nq2ouu$1p4g$1@gioia.aioe.org> |
| In reply to | #50559 |
peter.m.falth@gmail.com wrote: > On Monday, 29 August 2016 19:24:46 UTC+2, Anton Ertl wrote: > > ... > > As for why the direction of > > > > ]]...[[ > > > > is in this direction: It's because > > > > ] ... [ > > > > switches from interpretation to compilation and back; likewise, ]] > > switches from compilation to postponing and [[ switches back. > > This is why I think you got it backwards. I see it as > [ switches from compilation to interpretation and ] back to compiling > > therefore > > [[ should switch from compilation to postponing and ]] back to compiling > > it really looks backwards now! > > or it could be post[ ... ]pone for extra clarity > > BR > Peter Fälth A solution should befit the problem. If the only problem is that POSTPONE is too onerous to type because you need a lot of them (as in Bernd's regex) then what's wrong with temporarily assigning another name *just for that application* e.g. aka POSTPONE ~ POSTPONE is a low level compiler word and most applications will never even see it. OTOH a short-cut for VARIABLE could be tempting :) aka VARIABLE VAR
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-08-31 12:34 +1000 |
| Message-ID | <nq5fn0$25k$1@gioia.aioe.org> |
| In reply to | #50553 |
Julian Fondren wrote: > On Monday, August 29, 2016 at 3:43:57 AM UTC-5, HAA wrote: > > > > A possible implementation is > > > > : ]] \ multiple POSTPONE handler > > begin > > >in @ bl word count ?dup if > > s" [[" compare if > > >in ! postpone postpone true > > else drop false then > > else 2drop refill then 0= > > until ; immediate > > Special treatment is needed for literals. If you have a recognizer > stack, this is easier to implement and will work with user-created > literals. Ok I missed that because I never encountered the need. Where only words need to be postponed, something simpler would do: : POSTPONE| begin >in @ bl word count 1- swap c@ [char] | - or while >in ! postpone postpone repeat drop ; immediate
[toc] | [prev] | [next] | [standalone]
| From | "HAA" <someone@microsoft.com> |
|---|---|
| Date | 2016-08-29 18:44 +1000 |
| Message-ID | <nq0ska$ktc$1@gioia.aioe.org> |
| In reply to | #50545 |
hughaguilar96@gmail.com wrote:
> On Saturday, August 27, 2016 at 3:53:59 AM UTC-7, Anton Ertl wrote:
> > Anyway, let's see what the code above looks like with ]]...[[ and BOUNDS:
> >
> > : map< ( -- ) ]] cells bounds ?do i @ [[ ; immediate
> > : >map ( -- ) ]] 1 +loop [[ ; immediate
>
> This is how they look with MACRO: from the novice-package (it is ANS-Forth, as is
> everything in the novice-package):
>
> macro: map< ( -- )
> cells bounds ?do i @ ;
>
> macro: >map ( -- )
> 1 +loop ;
>
> Personally, I find ]] and [[ to be very hard to read, mostly because they are being
> used as brackets but they are backwards (pointing outward rather than pointing inward).
>
> I'm not familiar with ]] and [[ --- are these ANS-Forth? --- or are these Forth-200x?
As they're not standard, they could be anything. But since they're in GForth
and GForth has a presence on 200x, they may become standard :)
]] xx yy zz [[ is equivalent to POSTPONE xx POSTPONE yy POSTPONE zz
A possible implementation is
: ]] \ multiple POSTPONE handler
begin
>in @ bl word count ?dup if
s" [[" compare if
>in ! postpone postpone true
else drop false then
else 2drop refill then 0=
until ; immediate
[toc] | [prev] | [next] | [standalone]
Page 1 of 4 [1] 2 3 4 Next page →
Back to top | Article view | comp.lang.forth
csiph-web