Re: [stack] GUI's in concatenative languages

stevan apter — 2004-11-16 01:12:49

a month or two (or more) ago, i tried to sketch the outlines
of a data-driven GUI which has been used successfully in A+
and K.

here's the idea.

pick a widget - say, a table.

a table could look like this:

f g h
- - -
: : :

now design a data-model for the widget. e.g.

[['f [..]]
['g [..]]
['h [..]]]

a list of name-value pairs.

suppose t is table data. then

't show

has the side-effect of creating an appropriate widget and
binding it to t. initially, the side-effect includes pushing
some or all of the data out to the screen.

when you edit a cell in the widget, the string is converted
to the appropriate type and pushed back into t.

when you update a cell in t, the data is converted to a string
and pushed out to the widget.

let every bound variable (like t) have a shadow variable
companion - call it t. (t-dot). t. is a list of name-value
pairs. in my design, t. contains attributes for t:

[["bg" [['f [..]]
['g [..]]
['h [..]]]]
:

for example, the background attribute is a list of name-
value pairs, each of which corresponds to a field in t.
the [..] in this case is a list of colors (or a single
color, if you want to color the whole field uniformly.

alternatively, the bg attribute could be a quotation, which
is called whenever the gui wants to paint the background of
a cell. in that case, you need to develop a protocol to
tell the bg function which cell in which object you're
coloring. attributes such as these i call "call-forwards."

events like clicks can also be attributes in t.: quotations
which are executed when the event happens, and which have
side-effects. these are classic call-backs.

the beauty of a scheme like this is that it consists of just
two functions: show and hide. everything else is driven by
the structure of the data, and by attributes.

a minimal widget/data-model schema might have:

atom
list
table
slot
text
string
button
radiobox
checkbox
menu
canvas

From: "Chris Double" <chris.double@...>



>
> Are there any graphical user interface libraries for any of the
> concatenative languages out there? What sort of programmatic API would a
> concatenative GUI have? I'm currently building a component/OO based API
> for a continuation based web server in Factor and am curious if perhaps
> there's an approach that's more in the concatenative spirit than the
> current approach I'm taking.
>
> Chris.
> --
> Chris Double
> chris.double@...
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>

Daniel Ehrenberg — 2004-11-16 03:42:19

I don't fully understand. I like the idea of copying
K's model -- it leads to very clear and concise
programs in my opinion -- but I'm not sure how this
will work in a concatenative language. Particularly,
I'm unsure how local mutable state will work. Could
you translate roughly the K code into this new model:

gui.num:0
gui.inc:"num+:1"
gui.inc..c:`button
gui..c:`form
`show$`gui

Daniel Ehrenberg

> a month or two (or more) ago, i tried to sketch the
> outlines
> of a data-driven GUI which has been used
> successfully in A+
> and K.



__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com

stevan apter — 2004-11-16 12:10:26

good point - i keep forgetting that mutable state
is the exception, and not the rule.

as i think about things, gui.num is both a variable
with an integer value and a certain rendering on
the screen. the update of gui.num can happen via
ordinary assignment or by editing the display.


----- Original Message -----
From: "Daniel Ehrenberg" <littledanehren@...>
To: <concatenative@yahoogroups.com>
Sent: Monday, November 15, 2004 10:42 PM
Subject: Re: [stack] GUI's in concatenative languages


>
> I don't fully understand. I like the idea of copying
> K's model -- it leads to very clear and concise
> programs in my opinion -- but I'm not sure how this
> will work in a concatenative language. Particularly,
> I'm unsure how local mutable state will work. Could
> you translate roughly the K code into this new model:
>
> gui.num:0
> gui.inc:"num+:1"
> gui.inc..c:`button
> gui..c:`form
> `show$`gui
>
> Daniel Ehrenberg
>
> > a month or two (or more) ago, i tried to sketch the
> > outlines
> > of a data-driven GUI which has been used
> > successfully in A+
> > and K.
>
>
>
> __________________________________
> Do you Yahoo!?
> Meet the all-new My Yahoo! - Try it today!
> http://my.yahoo.com
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>

William Tanksley, Jr — 2004-11-16 16:03:19

Daniel Ehrenberg <littledanehren@...> wrote:
> I don't fully understand. I like the idea of copying
> K's model -- it leads to very clear and concise
> programs in my opinion -- but I'm not sure how this
> will work in a concatenative language. Particularly,
> I'm unsure how local mutable state will work. Could
> you translate roughly the K code into this new model:

It doesn't have to involve variables; instead, it can use data items.

> gui.num:0
> gui.inc:"num+:1"
> gui.inc..c:`button
> gui..c:`form
> `show$`gui

create-new-dictionary
dup 0 'num set
dup [1 num +] 'inc set
dup 'button 'inc..c set
dup 'form '..c set
show

Alternately, more in the style of an immutable language:

[ -- the dictionary
[ -- the dictionary's data list
['num 0]
['inc [1 num +] ['c 'button]]
]
[ -- the dictionary's attributes
['c 'form]
]
] to-dictionary show

> Daniel Ehrenberg

-Billy

Daniel Ehrenberg — 2004-11-16 22:58:31

> > gui.num:0
> > gui.inc:"num+:1"
> > gui.inc..c:`button
> > gui..c:`form
> > `show$`gui
>
> create-new-dictionary
> dup 0 'num set
> dup [1 num +] 'inc set
> dup 'button 'inc..c set
> dup 'form '..c set
> show

But how does this change the value of num? And where
did the word num come from?

Daniel Ehrenberg



__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com

William Tanksley, Jr — 2004-11-17 16:26:49

Daniel Ehrenberg <littledanehren@...> wrote:
> > create-new-dictionary
> > dup 0 'num set
> > dup [1 num +] 'inc set
> > dup 'button 'inc..c set
> > dup 'form '..c set
> > show

> But how does this change the value of num?

That's what the word "set" does.

> And where did the word num come from?

There is no word named num. There's a symbol 'num, which is looked up
in the dictionary on the stack.

> Daniel Ehrenberg

-Billy

Daniel Ehrenberg — 2004-11-18 01:11:13

> > > create-new-dictionary
> > > dup 0 'num set
> > > dup [1 num +] 'inc set
> > > dup 'button 'inc..c set
> > > dup 'form '..c set
> > > show
>
> > But how does this change the value of num?
>
> That's what the word "set" does.

But what I wanted to be done was increment num when
inc was pressed.
>
> > And where did the word num come from?
>
> There is no word named num. There's a symbol 'num,
> which is looked up
> in the dictionary on the stack.

But you use [1 num +]; isn't that using a num word and
not just a symbol? BTW, in XY (and X), ' makes a
character, not a symbol.

Daniel Ehrenberg



__________________________________
Do you Yahoo!?
The all-new My Yahoo! - Get yours free!
http://my.yahoo.com

stevan apter — 2004-11-18 14:57:39

the action of the inc button should be to increment the
value of num. that is, it should update num. if so,
inc needs to be something like

[2dup 'num get 1 + 'num set]

with the dictionary on the stack.

----- Original Message -----
From: "Daniel Ehrenberg" <littledanehren@...>
To: <concatenative@yahoogroups.com>
Sent: Wednesday, November 17, 2004 8:11 PM
Subject: Re: [stack] GUI's in concatenative languages


>
> > > > create-new-dictionary
> > > > dup 0 'num set
> > > > dup [1 num +] 'inc set
> > > > dup 'button 'inc..c set
> > > > dup 'form '..c set
> > > > show
> >
> > > But how does this change the value of num?
> >
> > That's what the word "set" does.
>
> But what I wanted to be done was increment num when
> inc was pressed.
> >
> > > And where did the word num come from?
> >
> > There is no word named num. There's a symbol 'num,
> > which is looked up
> > in the dictionary on the stack.
>
> But you use [1 num +]; isn't that using a num word and
> not just a symbol? BTW, in XY (and X), ' makes a
> character, not a symbol.
>
> Daniel Ehrenberg
>
>
>
> __________________________________
> Do you Yahoo!?
> The all-new My Yahoo! - Get yours free!
> http://my.yahoo.com
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>

William Tanksley, Jr — 2004-11-18 16:15:50

Daniel Ehrenberg <littledanehren@...> wrote:
> > > And where did the word num come from?
> > There is no word named num. There's a symbol 'num,
> > which is looked up
> > in the dictionary on the stack.

> But you use [1 num +]; isn't that using a num word and
> not just a symbol?

Yes, and it also isn't a correct implementation of increment. I should
have used +set, not +. Or something. I don't know, I only spent a
couple of seconds on that, and I wasn't writing it in any real
language anyhow.

The point remains: you don't need named variables in order to use
K-style GUIs. You only need dictionaries and arrays.

> Daniel Ehrenberg

-Billy