[REBOL] Re: Dialects - Bane or Blessing? (was: Teaching Rebol)
From: greggirwin:mindspring at: 27-Sep-2002 9:46
I have a few I've done as well, and let's not forget about make-doc and it's
relatives! Here are some examples of a few of mine.
===REBOLogo, which is just a very basic version of Logo:
box-tri-procs [
to box
pen-down
set-pen-color any
repeat 4 [fd 100 rt 90]
end
to triangle
pen-down
set-pen-color any
repeat 3 [fd 100 rt 120]
end
box
triangle
to tri-box
box
triangle
end
repeat 3 [
left 90
tri-box
]
pen-up
fd 200
set-heading 180
tri-box
]
===FSM (and the FSM for a turnstile):
when locked
coin causes unlock then unlocked
pass causes alarm
when unlocked
coin causes thank-you
pass causes lock then locked
The FSM engine does all the action triggering and state changing for you
given a spec like this. All you have to do is feed it events.
===RMake. Similar to MAKE, with an engine that processes the rules and
performs the actions based on dependency evaluation:
spec-1: [
target %xxx.bld
depends on [%xxx-0.txt %xxx-1.txt]
made by [
print ["rebuilding" _target "from" _source]
write _target rejoin [now/time/precise newline read _source]
]
target %xxx-1.txt
depends on %xxx-2.txt
made by [
print ["rebuilding" _target "from" _source]
write _target rejoin [_target tab now/time/precise newline read
_source]
]
target %xxx-2.txt
depends on %xxx-3.txt
made by [
print ["rebuilding" _target "from" _source]
write _target rejoin [_target tab now/time/precise newline read
_source]
]
]
rmake/build spec-1
===RAWK (REBOL AWK):
test-prog: [
begin [print "begin"]
end [print "end"]
begin-file [print ["begin-file" _filename]]
end-file [print ["end-file" _filename]]
every-line [line-ct: line-ct + 1]
(find rawk/_ "[") [print ["found line with bracket:" rawk/_fnr rawk/_]]
[_/1 = "lng"] [print ["found line with _/1 = Lng:" _fnr _]]
[(field 1) = "lng"] [print ["found line with _/1 = Lng:" _fnr _]]
[(length? __) = 21][print "found line exactly 21 chars long"]
[_nr = 1] [print "record 1"]
[_fnr = 1] [print ["file record 1" _filename]]
[all [(_nr >= first-line)(_nr <= 12)]] [print ["record from 10 to 12"
tab _nr]]
[_nr // 1000 = 0] [prin "."]
]
===Send-keys (for sending keystrokes to other applications):
win-send-keys compose [
"Gregg" return tab F5
alt #"f" #"o" wait 0:0:0.1 alt "n" wait .5 escape
{^/This is some more text (with a "quote")...
no less. }
divide return
shift ["i" shift-up "rwin"] return
shift "i" "rwin" return
"Irwin" return
"0" 10 return
(s: copy "" repeat i 10 [append s form i]) return
(do func [/local s] [s: copy "" repeat i 10 [append s to char! add i 64]
s]) return
ctrl "s" wait .5 escape return
]
Something to note about these dialects is that some allow you to embed REBOL
code directly in them. REBOLogo is just Logo, and Send-keys is just what it
is, but you can still use COMPOSE to create dynamic content with REBOL of
course. FSM, RMAKE, and RAWK all perform actions, which is to say that they
execute REBOL statements - so there is a definite and direct link to REBOL.
I have some others that I've just sketched out a bit. Some of them use REBOL
directly but others are "pure" dialects.
--Gregg