|
|
|
|
|
by swah
4151 days ago
|
|
I think so sir - I had only a couple beers and can't parse the function below. : <color-picker> ( -- gadget )
vertical <track>
{ 5 5 } >>gap
<color-sliders>
[ f track-add ]
[
[ <color-model> <color-preview> 1 track-add ]
[
[
vtruncate v>integer
first3 3dup "%d %d %d #%02x%02x%02x" sprintf
] <arrow> <label-control>
f track-add
] bi
] bi* ;
|
|
In this case there is a word called '<color-picker>' being defined. It takes no arguments off the stack and leaves one, gadget, on it.
Now working from left to right, 'vertical' is a constant. '<track>' creates a new GUI object called a track that requires the orientation to be on the stack. That what 'vertical' is. It's the orientation.
Now that there is a track object there we fill in the slots of that object. That's what '>>foo' does. It stores something in the 'foo' slot of the object on the stack. So "{ 5 5 } >>gap" stores the 2 element vector containing the integer 5 twice, into the 'gap' slot.
'<color-sliders>' creates a gadget and a model that is left on the stack. This is what 'bi-star' is now operating on.
'bi-star' is a combinator. It requires two objects and two quotations (quotations are factors term for anonymous functions or closures). It applies the first quotation to the first object, and the second to the second object. This system of combinators is described in the Joy language writings, although I think under different names.
"[ ... ]" is the syntax for the quotation. So "[ f track-add ]" is the first quotation. "bi-star" call this with the 'track' on the stack since that's the first object that "bi-star" gets access to.
The rest of the code can be worked through in a similar manner. In general you learn to recognise things like "<...>" for creating objects, ">>foo" for setting slots, "[ ... ]" for quotations and combinators to reduce stack management (like dup, rot, pick, etc).