Sujet : Re: quotations
De : no.email (at) *nospam* nospam.invalid (Paul Rubin)
Groupes : comp.lang.forthDate : 09. Feb 2025, 11:36:04
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87o6zbwgkr.fsf@nightsong.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
dxf <
dxforth@gmail.com> writes:
IMO it does nothing for readability to see a definition interrupted by
another. My reaction is one of WTF.
Maybe it looks weird in Forth, but similar things were present in
languages as old as Fortran, which had "statement functions" (idk when
those were introduced though). Algol had them, and lambda calculus
(invented in the 1920's, before computers existed) had them. It's not
inherently bad, though it can make code confusing if over-used. node.js
uses the style heavily in a deeply nested and painful way.
: make-action ( n -- xt ) [n:d ." You pressed " . ] ;
I don't understand make-action at all. What is it meant to be doing?
Imagine this function:
: action-5 ( -- ) ." you pressed 5" ;
That does the obvious thing: prints a fixed message, nothing else.
Similarly you want action-1, action-2, and so on.
How to generalize that? How about just having something that takes
a numeric argument, and gives you an xt that runs that action?
: make-action-n ( n -- xt ) ( need some magic here! ) ... ;
So, "5 make-action-n" gives an xt that is equivalent to ' action-5,
but you can make independent xt's for other values of n.
That's what I called make-action in the example I showed, and for the
"magic" it used a quotation. Maybe there is some reasonably easy
alternative way to do the same thing in traditional Forth. The only
ones that occur to me right now are pretty messy though.
Call me boring but I don't like inventing new syntax only to have to
Well, it's a one-time addition of new syntax, not something re-learned
in every new program. Like 'x' is new syntax for [char] x, but once
you've used it a few times you remember it and it seems to me like an
improvement.
So are quotations worth it for Forth? I don't know. I see some uses
for them but I'd tend to say that style is more common in GC'd
languages.
the antithesis of Forth - the opposite of being simple.
Forth is simple in some ways, complicated (or at least non-intuitive) in
others ;).