Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: First attempt at Rebol - 16 hours later

From: carl:cybercraft at: 30-Sep-2007 9:51

On Sunday, 30-September-2007 at 11:38:39 greg.schofield wrote,
>Carl I have just read through your script. I think my main problem is not > always seeing the relation between blocks clearly. I need to progress a >few steps further before I can be clear about this, but it is something t >o do with blocks and words implying "sentences", when I tend to read them > as different "commands" and get confused as to how the blocks relate to >one another.
Layouts can be a bit confusing, since they're written in a dialect of REBOL, (known as VID), and so aren't standard REBOL. Thus we can have stuff like so... layout [b: btn "A Button" [do something when button is clicked] red] layout [b: btn [do something when button is clicked] "A Button" red] layout [b: btn red "A Button" [do something when button is clicked]] Those will all function the same, since when REBOL parses the layout it doesn't usually care about the order of what's after a style (BTN in this case.) In the BTN cases above, if it encounters a string, it will store that string in B/TEXT, a block will be stored somewhere else as it's assumed to contain standard REBOL code to be evaluated should the button be clicked, and RED (which is a tuple datatype which are used for colors) will be stored in its appropriate place. So a layout is best thought of as data, not sentences or code. They're parsed (from beginning to end and style to style, I assume), and end up as an object which VIEW (meaning the REBOL function) then uses to decide how a window will look and behave. In standard REBOL though, a block can be thought of as a container that's used when you need to store 2 or more values. An example...
>> blk: [a 1 b 2 c 3]
== [a 1 b 2 c 3]
>> foreach n blk [print n]
a 1 b 2 c 3
>> foreach [a b] blk [print a]
a b c
>> foreach [a b] blk [print b]
1 2 3
>> foreach [a b] blk [print [a b]]
a 1 b 2 c 3 With FOREACH and PRINT there, just by replacing words with blocks of words, they become more useful. (Obviously FOREACH and PRINT had to be written so they can handle such an option.) Now you can think of REBOL functions and the like as commands, but until they're evaluated, they're really just data. ie...
>> blk: [print 1 print 2 print 3]
== [print 1 print 2 print 3]
>> foreach [a b] blk [print [a b]]
print 1 print 2 print 3
>> do blk
1 2 3 In that case, the PRINTSs in BLK are just REBOL words with no meaning until the block they're in is evaluated by DO. Umm - I hope this has helped and not just confused you more! :-) -- Carl Read.