Liste des Groupes | Revenir à cl forth |
On Sun, 22 Jun 2025 14:35:40 +0000, Hans Bezemer wrote:You can repair such things by using new stack paradigms. I've added<snip>
several ones, most of 'em inspired by others. E.g
>
"swap 3OS with TOS" (SPIN, a b c -- c b a)
"DUP 2OS" (STOW, a b -- a a b)But of course, you have to do the work. If you're incapable or too lazy
to do the work, yeah, then you will find Forth bites you. Note that C is
a very nice language as well. Beats Forth performance wise - so, what's
there not to like :)
I mostly belong to the lazy kind. Therefore, I prefer to let the
computer
do the tedious work before spending time on premature optimizations,
such as stack ordering.
So, I made me a small extension to the locals word set. Using your
example SPIN (abc — cba), I can define it as follows:
: SPIN { a b c == c b a } ; \ no need for additional code before ;
or likewise for floats, doubles, strings, matrices
: FSPIN { f: a b c == c b a } ;
: DSPIN { d: a b c == c b a } ;
: "SPIN { s: a b c == c b a } ;
: MSPIN { m: a b c == c b a } ;
Code generation and register optimization is the computer's job.
SPIN/STOW or similar microexamples can, of course, be defined quickly
with classic Forth stack juggling too. The power of the extension
becomes more apparent with mixed parameter types and/or more parameters,
and of course, with some non-trivial algorithm to solve.
I couldn't have done this in C, but Forth allows you to modify the
compiler until it suits your work domain.
Les messages affichés proviennent d'usenet.