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
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/
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)