Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Remember: use logout to logout.


devel / comp.lang.forth / Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;

SubjectAuthor
* Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;Gerry Jackson
`- Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;none

1
Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;

<ttj5rm$3batb$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22588&group=comp.lang.forth#22588

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: do-not-...@swldwa.uk (Gerry Jackson)
Newsgroups: comp.lang.forth
Subject: Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;
Date: Mon, 27 Feb 2023 21:03:50 +0000
Organization: A noiseless patient Spider
Lines: 103
Message-ID: <ttj5rm$3batb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 27 Feb 2023 21:03:50 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f2580f1f959a6af99680e92b47893a5e";
logging-data="3517355"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KS3k+xuXGf70fNxkO7c1DFIVzHR+c9P8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:ao9aBa0xt5MkFhDASC4oFrGXGxE=
 by: Gerry Jackson - Mon, 27 Feb 2023 21:03 UTC

On Friday, January 29, 2016 at 7:19:28 AM UTC, humptydumpty wrote:

: YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;

> : xt latestxt postpone literal ; immediate
>
> \ Use: : wordname .... test-sequence IF xt dup ELSE 0 THEN ;
> \ Kick into action: ' wordname dup YC
>
> \ Example:
> : downcount dup . 1- dup 0 >= IF xt dup ELSE 0 THEN ;
> 10 ' downcount dup YC drop
>
> ---
> *Factored* loop. Small. Beautiful. Deserves to be a primitive.
>
> Enjoying forth,
> humptydumpty

I've been experimenting with humptydumpty's (HD's) YC as defined above
and like the way it separates out the loop from the processing. However
LATESTXT is not a standard word and using YC is a bit messy.

A way around LATESTXT is to use a quotation, for example using HD's
DOWNCOUNT we can do:
: yc ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;

: (dc) ( n -- n-1 f ) dup . 1- dup 0 >= ;

0 value downcount-xt

: downcount
[: ['] (dc) execute if downcount-xt dup else 0 then ;]
dup dup to downcount-xt yc
;

10 downcount drop \ displays 10 9 8 7 6 5 4 3 2 1 0 ok

Still rather messy but shows the idea. Much of the body of DOWNCOUNT
would be common with other uses of YC and can be auto compiled so an
improved syntax is:

' (dc) iterator downcount
or of course
:noname dup . 1- dup 0 >= ; iterator downcount

where ITERATOR is a parsing word that compiles the equivalent of the
above code

A definition of ITERATOR using GForth's ]] ... [[ multi-postponer is:

: iterator ( "name" xt -- )
>in @ 2>r ( R: -- xt n )
variable r@ >in !
: r> >in ! ' ( -- xt2 ) ( R: -- xt )
>r ]] [: [[ r> r> compile, ( R: -- ) \ compile xt
dup >r compile, \ compile xt2
]] @ and ?dup [[ ( -- xt3 xt3|0 ) ( R: -- xt2 )
]] ;] dup dup [[
r> compile,
]] ! yc ; [[
;

1. A variable is used instead of a value as TO can't be postponed
2. downcount is parsed 3 times for the name of the variable, the name of
the iterating word and access to the variable
3. The stack diagram of the processing word e.g. (dc) is
(i*x -- j*y 0|-1), 0|-1 so that the IF statement can be replaced with
an AND

5 downcount drop 5 4 3 2 1 0 ok

The YC loops can be effectively nested and a processing pipeline formed
by code such as this simple example that replaces spaces in the input
stream with a '|' character. CATCH THROW are used simply to avoid the
verbose error messages Gforth displays when ABORT" is used.

: .word ( ca u -- 0|-1 )
dup if
2dup s" stop" compare 0=
if cr 99 throw then
type '|' emit
else
2drop
then
; : (word) parse-name dup if .word -1 else 2drop cr 0 then ;
' (word) iterator next-word

: (line) refill if next-word -1 else 0 then ;
' (line) iterator next-line

: x cr ['] next-line catch 99 <> abort" Failed" ." Succeeded" ;
x qwerty f hj asd qwerty|f|hj|asd|
'stop' will exit NEXT-LINE stop 'stop'|will|exit|NEXT-LINE|
Succeeded ok

I don't know why HD called it YC as it isn't a Y combinator but I don't
know what else is a good name.

--
Gerry

Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;

<nnd$3907efcd$3411aee6@c99f342c291f7b49>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22591&group=comp.lang.forth#22591

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
References: <ttj5rm$3batb$1@dont-email.me>
Subject: Re: : YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
From: alb...@cherry (none)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$3907efcd$3411aee6@c99f342c291f7b49>
Organization: KPN B.V.
Date: Tue, 28 Feb 2023 13:55:11 +0100
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 141
Injection-Date: Tue, 28 Feb 2023 13:55:11 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
X-Received-Bytes: 5415
 by: none - Tue, 28 Feb 2023 12:55 UTC

In article <ttj5rm$3batb$1@dont-email.me>,
Gerry Jackson <do-not-use@swldwa.uk> wrote:
>On Friday, January 29, 2016 at 7:19:28 AM UTC, humptydumpty wrote:
>
>: YC ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;
>
>> : xt latestxt postpone literal ; immediate
>>
>> \ Use: : wordname .... test-sequence IF xt dup ELSE 0 THEN ;
>> \ Kick into action: ' wordname dup YC
>>
>> \ Example:
>> : downcount dup . 1- dup 0 >= IF xt dup ELSE 0 THEN ;
>> 10 ' downcount dup YC drop
>>
>> ---
>> *Factored* loop. Small. Beautiful. Deserves to be a primitive.
>>
>> Enjoying forth,
>> humptydumpty
>
>I've been experimenting with humptydumpty's (HD's) YC as defined above
>and like the way it separates out the loop from the processing. However
>LATESTXT is not a standard word and using YC is a bit messy.
>
>A way around LATESTXT is to use a quotation, for example using HD's
>DOWNCOUNT we can do:
>: yc ( .. xt xt |0 -- .. ) BEGIN WHILE execute REPEAT ;
>
>: (dc) ( n -- n-1 f ) dup . 1- dup 0 >= ;
>
>0 value downcount-xt
>
>: downcount
> [: ['] (dc) execute if downcount-xt dup else 0 then ;]
> dup dup to downcount-xt yc
>;
>
>10 downcount drop \ displays 10 9 8 7 6 5 4 3 2 1 0 ok
>
>Still rather messy but shows the idea. Much of the body of DOWNCOUNT
>would be common with other uses of YC and can be auto compiled so an
>improved syntax is:
>
>' (dc) iterator downcount
>or of course
>:noname dup . 1- dup 0 >= ; iterator downcount
>
>where ITERATOR is a parsing word that compiles the equivalent of the
>above code
>
>A definition of ITERATOR using GForth's ]] ... [[ multi-postponer is:
>
>: iterator ( "name" xt -- )
> >in @ 2>r ( R: -- xt n )
> variable r@ >in !
> : r> >in ! ' ( -- xt2 ) ( R: -- xt )
> >r ]] [: [[ r> r> compile, ( R: -- ) \ compile xt
> dup >r compile, \ compile xt2
> ]] @ and ?dup [[ ( -- xt3 xt3|0 ) ( R: -- xt2 )
> ]] ;] dup dup [[
> r> compile,
> ]] ! yc ; [[
>;
>
>1. A variable is used instead of a value as TO can't be postponed
>2. downcount is parsed 3 times for the name of the variable, the name of
>the iterating word and access to the variable
>3. The stack diagram of the processing word e.g. (dc) is
> (i*x -- j*y 0|-1), 0|-1 so that the IF statement can be replaced with
> an AND
>
>5 downcount drop 5 4 3 2 1 0 ok
>
>The YC loops can be effectively nested and a processing pipeline formed
>by code such as this simple example that replaces spaces in the input
>stream with a '|' character. CATCH THROW are used simply to avoid the
>verbose error messages Gforth displays when ABORT" is used.
>
>: .word ( ca u -- 0|-1 )
> dup if
> 2dup s" stop" compare 0=
> if cr 99 throw then
> type '|' emit
> else
> 2drop
> then
>;
>: (word) parse-name dup if .word -1 else 2drop cr 0 then ;
>' (word) iterator next-word
>
>: (line) refill if next-word -1 else 0 then ;
>' (line) iterator next-line
>
>: x cr ['] next-line catch 99 <> abort" Failed" ." Succeeded" ;
>x
>qwerty f hj asd qwerty|f|hj|asd|
>'stop' will exit NEXT-LINE stop 'stop'|will|exit|NEXT-LINE|
>Succeeded ok
>
>I don't know why HD called it YC as it isn't a Y combinator but I don't
>know what else is a good name.

As long as we're inventing syntax for loops,
the whole shebang of DO LOOP ?DO +LOOP has to be junked.
Remember in mathematics that [ .. ] and ( .. ) indicate an inclusive versus
an exclusive range.
[ 1 2 3 ] includes 1 and 3, ( 1 2 3 ) does not.

( n xt -- ) DO) \ Execute xt n times, lowest limit is default 0
( n xt -- ) DO] \ Execute xt n times, lowest limit is default 1
( l h xt -- ) DO[) \ Execute xt l-h times, with lowest and highest limits.
( l d h xt -- ) DO[..] \ Execute xt, as DO[] with increment d
Replace I with IX. Same number of words as previous, but more easy
to remember.
In order to do 10 spaces:
10 'SPACE DO)
10 'SPACE DO]
0 10 'SPACE DO[)
1 1 10 'SPACE DO[..]

Having promoted { } to signify both :NONAME and [: ;] we can do
10 { SPACE } DO)

This can be implemented with a few high level returns stack
manipulations.
And by the way. It works equally well in interpret mode.

Maybe add DO[] with now obvious meaning.

>Gerry

Groetjes Albert
P.S. This comes about by at last have a lambda (denotation for
behaviour, i.e. { } ) gaining their civil rights.
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat spinning. - the Wise from Antrim -

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor