Sujet : Re: quotations
De : no.email (at) *nospam* nospam.invalid (Paul Rubin)
Groupes : comp.lang.forthDate : 09. Feb 2025, 08:41:38
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87seonwonh.fsf@nightsong.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
dxf <
dxforth@gmail.com> writes:
quotations ... strike me as being wrong in every way, not least
because they are intended to feature prominently, stuffed in one's
face. I don't understand the appeal at all.
I never got the impression they were supposed to be so prominent, though
I guess one could program in a style that uses them heavily. My first
Forth program used a lot of XT's but in retrospect, it was rather
unidiomatic.
The following sort of follows an idiom for Python GUI programs. You
have a function MAKE-BUTTON that puts a button on the screen. The
button has a label, and it calls a function when you press it. This
is using the notation from Anton's post but I haven't tested it.
: make-button ( a u xt -- ) ... ;
\ a u is the label, xt is the action
Now you want to draw buttons for a numeric keypad:
: make-action ( n -- xt ) [n:d ." You pressed " . ] ;
: make-label ( n -- a u ) \ make a string like "5" in the dictionary
here { a } 1 chars allot '0' + a c! a 1 ;
: keypad ( -- ) 10 0 do
i make-label i make-action make-button
loop ;
Now there will be buttons labelled "0", "1", ... "9", and and when you
press one, it will print "you pressed 5" or whatever for that button.
I think the idiomatic old-school Forth alternative to this would be an
OOP-like approach, but the above is probably more concise, and to some
of us more intuitive.