Piping and translating data from one point to the other is all fine and dandy, but I wanted to test solving messier and more statefull problems using Rye constructs.
One example of such code are GUI-s. I tried to write a simple GTK example in multiple ways, to see where it gets me.
Rye GTK binding uses generic functions. set-title, set-text, add-to ..., show are all words that dispatch on the kind of first argument and not ordinary "global" words.
- First (top left) example uses an ordinary polish notation and "variables". It's very similar to something you could write in plain Rebol or some other function based language (otherwise, rebol has a well "known" GUI dialect)
- Second (bottom left) uses variables and a lot of op-words. Words that take first argument from the left. This makes the structure look somewhat like it would look in a classical object oriented language. Like Python if you would add few parenthesis to the right spots.
- Third relies less on variables and uses pipe-words to create 2 forward flows. But this also relies on the fact that set-* words return the object
- Fourth uses injected block mechanism. It can support more inline computation and doesn't rely on set-* words returning the main object at all.
- Fifth (bottom right) example uses some pipe-words in between. It has less symmetry and I IMHO worse than fourth example.
I've started writing an intro to the language not long ago ... I have partially written pages about op-words and pipe-words and I wrote a page about injected blocks today, so if you want to know more about these language features please look there.
Komentarji
Objavite komentar