In article <
2022Apr3...@mips.complang.tuwien.ac.at>,
Anton Ertl <
an...@mips.complang.tuwien.ac.at> wrote:
>albert@cherry.(none) (albert) writes:
>>I'm doing my taxes and i have to evaluate strings like "4,54"
>>resulting in a number of cents.
>>A do a precaution, I want that numbers are only recognized
>>after ONLY
>
>I assume you mean that you only want to use EVALUATE, but only
>recognize numbers.
>
>>i.e. in the minimum search order, to prevent
>>executing of arbitrary strings, such
>>" ""rm *"" SYSTEM ".
>>
>>So I begin the dotaxes word
>>
>>: dotaxes ONLY ... ;
>>
>>That works in my simple (own) Forth and also in gforth.
>
>It's not clear what's up with the quotes in the example above, but in
As long as the prefix " was not ISO anyway I adopted the ALGOL68
convention that you can insert " in a string by doubling it.
I was not prepared to invent a string denotation that doesn't
allow me to define strings of printable characters. (AD MMI that was).
>Gforth you can break out of ONLY with FORTH (ONLY is not SEAL, and
>even SEAL is not what you want). E.g.
>
>only forth
>s" evil-command" system
That was what I wanted to prevent. So no forth-wordlist in the
search-order containing the evil `SYSTEM command.
>
>You can also break out of ONLY with FORTH in iForth, lxf, SwiftForth,
>and VFX.
And ciforth. Everybody uses
`` ONLY FORTH ''
That is not the way the standard expects it apparently.
You are supposed to do
`` forth-wordlist 1 set-order ''
because it is not guaranteed that FORTH is in the minimum search order.
(Last time I looked.)
>
>If you want to remove all word lists from the search order, use
>
>0 set-order
The trick^H^H^H^H technique works in gforth and mpe forth.
: test ONLY S" 1 2 3 DROP" EVALUATE ; redefined test ok
test
*evaluated string*:-1: Undefined word
1 2 3 >>>DROP<<<
Backtrace:
...
What you recommend, works also in ciforth and gforth.
ONLY FORTH ok
: test 0 set-order S" 1 2 3 DROP" EVALUATE ; redefined test ok
test
*evaluated string*:-1: Undefined word
1 2 3 >>>DROP<<<
It works more or less in mpe forth, but you cannot recover
from `` 0 set-order '' . You can only type ^C .
`` ONLY FORTH '' doesn't help. This is certainly a
viable interpretation of the standard, making ONLY the
best portable way to have the Forth system understand numbers
("denotations") only.
>- anton
Groetjes Albert
P.S.
I'm doing my taxes, and an unbridled EVALUATE feels not right.
: doit ONLY
"ING1742206_2021.csv" SLURP-FILE TRANSACTIONS 2!
"recipients.txt" SLURP-FILE DONATIONS 2!
process-recipients ;
Making this into a turnkey, it is not a big deal that the (mpe)
interpreter is messed up, so either technique works.