Deutsch   English   Français   Italiano  
<2025Feb1.095441@mips.complang.tuwien.ac.at>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: SELECT (was: Back & Forth - Co-routines)
Date: Sat, 01 Feb 2025 08:54:41 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 85
Message-ID: <2025Feb1.095441@mips.complang.tuwien.ac.at>
References: <nnd$2fb29a8e$298ef3f8@23fe4f00fa62d734> <9c16141dfe3c785e316678770e965566@www.novabbs.com> <87plk2y6yf.fsf@nightsong.com> <2025Feb1.082611@mips.complang.tuwien.ac.at> <6efc4fec918d6d2bc29250159bafb5de@www.novabbs.com>
Injection-Date: Sat, 01 Feb 2025 11:20:28 +0100 (CET)
Injection-Info: dont-email.me; posting-host="e73d87433ea6af5c12faf5c290261c8e";
	logging-data="62539"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19aRa267gcIpCCOOKJFS3Zm"
Cancel-Lock: sha1:C2NpIMZjWgmz4hk2YUd4dPtDlfs=
X-newsreader: xrn 10.11
Bytes: 4467

melahi_ahmed@yahoo.fr (ahmed) writes:
>On Sat, 1 Feb 2025 7:26:11 +0000, Anton Ertl wrote:
>> [undefined] select [if]
>> : select ( u1 u2 f -- u )
>>   if swap then nip ;
>> [then]
>>
>> : tri_mf3.1 { x a b c -- mf }
>>     x a c within if
>>       b x  x b < a c select  blend
>>     else
>>       0
>>     then ;
....
>I think it must be:
>(the true/false flag must on tos for select as you defined it)
>
>: tri_mf3.1 { x a b c -- mf }
>    x a c within if
>      b x a c x b < select  blend
>    else
>      0
>    then ;

Yes, thank you.  Why did I make this bug?  I originally wrote

x b < if a else c then

then replaced the IF ELSE THEN with SELECT, but did not change the
order of arguments accordingly.

It's an interesting question of whether the ordering of arguments in
SELECT is optimal.  Let's look at the existing uses of SELECT in
Gforth (only one line given, this comes from WHERE):

Flag last preferable:
cell [ 2 cells ] Literal I cell- 2@ <> select \ skip double entries              
0 [: over defers addr>view dup 0= select ;] sections-execute nip ;                   
i dup >cfa swap name>string drop cell negate and dup 0= select                           
2>r $substitute over r@ u<= -78 swap select -rot                                  
dup name>compile >r swap name>interpret state @ select                                 

Flag first preferable:
dup 0< 'A' 'B' rot select  hold abs #n #esc[                                            
dup 0< 'D' 'C' rot select  hold abs #n #esc[                                            
dup $80 $20 vt100-modifier @ 2 and select                                            
cells altkeys ctrlkeys vt100-modifier @ 2 and select                                 
: .s/d ( -- ) 's' 'd' s? IF ss? ELSE length @ 0= THEN select emit ;        
: .d/s ( -- ) 'd' 's' s? IF ss? ELSE length @ 0= THEN select emit ;        

Does not matter:
replace-sourceview current-sourceview over select ;                              
dup 7 <= IF  'r' 'e' w? select emit  ELSE  'r' emit  THEN  ;               
"breg2 "breg p? select  ELSE  "wregs ( " ) THEN  THEN                      
: .s/p ( -- ) 's' 'p' s? select emit ;                                     
: .p/s ( -- ) 'p' 's' s? select emit ;                                     
: .ssereg ( n -- n ) 'y' 'x' l? select emit ." mm" #.r ;                   

Unclear:
0 [: over in-dictionary1? section-start @ and over select ;]                         

In the case that someone wants to implement a flag-first SELECT-like
word, please do not call it SELECT.

The .S/D and .D/S case is interesting, because it shows a missed
opportunity for SELECT:

: .s/d ( -- ) 's' 'd' ss? length @ 0= s? select select emit ;        

This is still preferable flag-first IMO:

: .s/d ( -- ) s? ss? length @ 0= ffselect 's' 'd' ffselect emit ;

OTOH, if you consider both .S/D and .D/S, you can factor that further,
and then flags-last is preferable.

Anyway, it's water down the river, we won't change it.

- 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: https://forth-standard.org/
EuroForth 2023 proceedings: http://www.euroforth.org/ef23/papers/
EuroForth 2024 proceedings: http://www.euroforth.org/ef24/papers/