Liste des Groupes | Revenir à cl forth |
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.
Les messages affichés proviennent d'usenet.