looks like the new version of rebol has shell access and sound
in the free version now
People doing this are also doing these things:
Entries
rebol []
object-template: [
make object! [
(props)
(meths)
]
]; these could come from a some source,
; database schema etc
props: [ name: "fred"
age: 26]meths: [
speak: func [] [
print rejoin [name " says hi! I'm " age]
]]code: compose/deep object-templatea: do codea/speak
I think there is a lot to like about REBOL. The native datatypes are interesting. Lots of things like email@adddress.com or http://www.slashdot.org that would be represented as strings in other programming languages appear to be their own types in REBOL. Combined with REBOL blocks this makes creating a domain specific language much simpler.
It’s a pity that REBOL is a proprietary language. The free core software doesn’t have access to shell commands or databases. This makes it a little harder to compare with Perl,Python or Ruby which is what REBOL is stacked up against for competition.
I wasn’t really planning on mastering the Rebol language, but I’ve learned it well enough to feel like I can write useful code. Rebol has its place as a “smart data” language, so I’ll be keeping it in my toolkit for times in the future when I may need it.
one aspect of rebol that has taken me an embarassingly long time to get ( no pun intended ) is the use of such datatypes as get-word! and set-word!.
they’re just tools for dynamic code creation:
program: []
append program to set-word! “name”
append program “fred”
; program is just the block of words [ name: “fred”]
do program
print name
—: “fred”
name is now a word in the global context
get-word!
i was going use get-word! to create some dynamic code, but it didn’t work cough
more on this later
you can do functional style programming in rebol though:
foo: func n
apply-to-two: func [f] [
f 2]
the obvious thing fails
apply-to-two f
—: error!
but this works:
apply-to-two :f
—: 3
return a function:
make-adder: func [n] [
return function m[return m + n]] ; note function word requires a middle variables block
g: make-adder 50
g 100
—: 150
h: make-adder 100
h 100
—: 200
get-word confuses me
foo: func [n] [ return n + 1 ]
on command line:
g: :foo
g 3
—: 4
but
h: to get-word! “foo”
—: :foo
h 3
3 ; !!
hmm ok
you need
s: get h
s 3
—: 4
in the above:
apply-to-two (get to get-word! “foo”)
—: 3
Had to share a “Eureka!” moment with ya. I might end up refining it later on for an article on my site, or I might not. I just didn’t want the thoughts to disappear in air as thoughts are sometimes known to do.
Warning: It’s a very long post, and there is some formatting funkiness at the end.
My Baffling Issue
There are a lot of re- words in Rebol.
- reduce
- reform
- rejoin
- remold
- repend
There are others, but they make sense to people who are comfortable with the English language. I won’t spend too much time with them.
- recycle
- remove
- rename
- repeat
- replace
- request
- resend
These do more or less what you would expect them to. remove will remove an item from a series, rename renames a file, request requests console input from the user. Try help _word_ to get the specifics on the others. Like I said, I’m not worrying about them right now.
That first list of re- words was really standing in the way of understanding Rebol. That’s because the prefix re- doesn’t quite mean what you would expect in an English language context. I’m used to the meaning “do this thing again,” and that’s the way it gets used in words like resend and repeat. What about repend and those others?
reduce
The key for those words is in understanding reduce. reduce takes a series and evaluates every expression in that series. When it’s done, it hands you a new list consisting of the results of those evaluations. It’s easier to show than explain:
>> example: [
[ 2 + 3
[ 4 * 6
[ 4 / 2
[ ]
== [
2 + 3
4 * 6
4 / 2
]
>> reduce example
== [5 24 2]
It gets more interesting when your expressions are a little more interesting, but I’m keeping it simple so I don’t get distracted.
Those other four words which have been confusing me for months suddenly make a lot more sense when I realize that the prefix re- means “reduce these values before doing this other thing.”
reform
form takes a value and returns a stringified version of the value.
>> form example
== "2 + 3 4 * 6 4 / 2"
Now that we know what reduce does, we have a good idea what to expect out of reform.
>> reform example
== "5 24 2"
It will reduce the series, and then form a string from the values in the new series.
rejoin
join is a little funky. Now that I understand what rejoin does, I usually end up using it directly. Here’s a breakdown just the same.
join takes two arguments: a value and a series. It will reduce the value and the series, and then glue the results tightly into a string. Sounds a little bit like form, doesn’t it? Unlike form, join will not provide spaces in between the values.
>> join 3 + 2 example
== "55242"
rejoin effectively does the same thing, but it doesn’t need the first value. You can rejoin your series directly.
>> rejoin example
== "5242"
remold
mold is somewhat nifty. It will transform its argument into a string that Rebol can evaluate later. Pretty handy for generating code on the fly!
>> mold example
== {[
2 + 3
4 * 6
4 / 2
]}
remold will reduce the argument and then mold the results.
>> remold example
== "[5 24 2]"
repend
>> append example [2 + 3]
== [
2 + 3
4 * 6
4 / 2 2 + 3
]
Be careful, append actually does append the value to your original series. You may want to work on a copy if you want to leave your original series alone.
>> append copy example [2 + 3]
== [ 2 + 3
4 * 6
4 / 2
2 + 3
]
>> example
== [2 + 3 4 * 6 4 / 2]
Let’s look at repend now that we’ve got the append warning out of the way. Easy enough. repend will reduce the extra value before appending. I haven’t gotten far enough along to see why this is better or even different from just appending the raw expression:
>> append copy example 2 + 3
== [2 + 3 4 * 6 4 / 2 5]
I do feel a little smarter than I did 20 minutes ago, though. If nothing else, I feel good.
Great, now I think I’ve got a little bit better understanding of Rebol. Let’s see if I’ve gotten far enough to make truly useful programs.
Okay, so maybe Rebol isn’t that bad. Some of the stuff is starting to click after all. parse in particular is pretty nice, since you get to describe a grammar instead of assemble this bizarre puzzle of regular expressions.
Plus, having alpha releases of 1.3 for OS X and Linux makes me a little more optimistic about creating apps that my friends and familay can all make use of.
This booklet is a good introduction to Rebol. Not perfect, but good. It could stand a little bit of proofreading and editing, and I hope the author has a chance to update it for newer releases of Rebol. I kinda get the impression that this won’t happen, though, since the text was intended to accompany a class he was teaching a couple of years ago.
Maybe I should fire an email off his way asking about updates.
I mean, learning a new programming language is nearly always worth it, but something about Rebol just won’t click for me. I’ll continue putting the occasional brain cell towards learning it, but it’s just not a priority anymore.


