Rebol - Dialects, Spreadsheets

Gregg Irwin just sent an interesting email (about Rebol) to the pragprog mailing list. I can't work out how to access the Yahoo archives so instead I'll post chunks here. But first I'll give some background links (there's also two links at the very end of this post to a two part article on an implementation of a spreadsheet in Rebol - I'm not sure how the cells communicate, but that might be interesting):

  1. Rebol dialects - blocks that carry condensed meaning through the use of a different grammar (ordering) of values and words. Dialects are usually unique and well-suited to the problems they are designed to solve. (DSLs)
  2. Tutorial
  3. License - a bit odd/worrying (how can you not modify a language that expressly encourages DSLs?)

Fragments of the email inside...

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Email Fragments and Spreadsheet Links

[...]

I'm a DSL guy; not the graphical DSLs that MS, Intentional, and JetBrains are doing, but simple text-based DSLs. I specialize in a language called REBOL, that has features making it ideal for this task. It can be used as a general purpose language (it's heritage comes from Lisp, Forth, and Logo) and it is also a data language, like XML, and is strictly interpreted, so my view is quite different from the world of XML, Java, and byte-codes.

DSLs in REBOL are called "dialects". A true dialect in REBOL uses the REBOL lexicon--though not necessarily its syntax, but you can also write char level parsers to implement DSLs that aren't true dialects.

[...]

A [...] dialect, for another project, controls Excel. Basically a simpler macro programming tool for high-level developers:

    ; dialect sample code (just shows various commands)
    x: 100
    Excel compose [
        start
        show
        open file (test-file)
        ;alerts on
        alerts off
        ;remove worksheet
        ;close workbook
        ;goto workbook 1
        ;go to worksheet #2
        ;quit
        add a new worksheet
        ;goto cell "B3"
        ;select rows "1:3"
    
        select "B4"
        set value to x
        goto cell "B6"
        change to "Testing"
        select "B7"
        set to "=B4 * B5"
        select "A5:A9"
        change to "=$B$5 * PI()"
    
        set cell 10 2 to 222.22
        set 11 2 to 333.33
        set cells "C2:C6" to 123
        set "D3:E4" "Yeah!"
        change "A1" "=B10"
    
        copy "A1:A9" to "B21"
        cut "B21:B29" to "A18"
    
        select "A5:A9"
        copy
        goto cell "C15"
        paste
        goto cell "D15"
        paste values
        goto cell "E15"
        paste no borders
    
        go to worksheet "Sheet4"
        autofilter "A5" on
    
        open file (test-file-2)
    
        copy workbook "pbtest.xls" "A1:C5"
          to workbook "test-b.xls" "B2"

        goto workbook "test-b.xls"
    
        goto cell "F1"
        cur-cell: current column
        repeat i 3 [
            repeat j 4 [
                goto cell j (cur-cell + i - 1)
                set to (i * j)
            ]
        ]
    ]

What if you need to express a solution as a Finite State Machine. Will users even know what that means? Could they understand this model of a stopwatch/timer?

    when stopped
        click causes start then running
        reset causes reset-counter
    when running
        click causes stop then stopped
        reset causes reset-counter
        tick  causes increment-counter

[...]

I did a couple little articles last year, with Steve Shireman. We used a REBOL sample script, called REBOLCalc, and made it a fairly functional spreadsheet utility. The dialect part of it is the file format. You could create the files manually, programmatically, or save them from the UI.

    ; The DO block is just REBOL code; you can do whatever you want.
    ; It's a good place to set up custom worksheet functions.
    do [
        right-now: does [now/time/precise]
        ; Precedence in REBOL is strictly left-to-write without parens
        circle-area: func [diameter] [diameter / 2 ** 2 * pi]
    ]
    ; The BUTTONS block is used to create buttons in cells. You give
    ; each one a cell (location), the text, and an action block.
    buttons [
        A5  "Check"  [print "check"]
        A10 "Random-test" [set-cell 'a11 circle-area random 10 1E-2] 
        C10 "test-2" [set-cell 'c11 right-now] 
        F16 "Done"   [quit]
    ]
    ; The rest of the data is just cell-content data. If the content
    ; contains a block, it's treated as a formula (you can edit it
    ; interactively from the UI).
    A1 ["test"] C1 [[now/date]] D1 [3] E1 [$200.00] F1 [1x2]
    E2 [[d1 * e1]]
    A11 [19.63]
    C11 [0:46:00.171] C12 [[c11 + 1]]

Here are the articles about it:

  1. http://www.devx.com/opensource/Article/27454
  2. http://www.devx.com/opensource/Article/27969

REBOL Internals

Now I can finally clear the REBOL internals article off my desk. Pay attention to the ending bit.

REBOL is an interesting re-marketing of Lisp, and successful by all appearances. I wish it did not use so much market-speak ("dialects"), but still. Also noteworthy is the large number of built-in types. REBOL is a sort of DSL for the Internet.

oh! i didn't realise it was

oh! i didn't realise it was a lisp. stupid me... thanks.

(why doesn't this post appear in the forum topics box on the right?)

Good point about Rebol's license

Yes, there is a bit of a conflict there (a closed-source language encouraging DSLs).

Anyway - just a couple of quick links to two open-source Rebol "clones" , for those who haven't seen them -

R-sharp -
http://sourceforge.net/projects/r-sharp

Freebell -
http://sourceforge.net/projects/freebell

and http://freebell.sourceforge.net/

Both projects are "dead", but R-sharp still manages to get an 88% activity rating and 10-20 downloads a month - not bad for a dead project. R-sharp definitely works - I've tried it.

Freebell (which is coded in Java) does not have a direct download (as R-sharp has), but it has *lots* of code in its CVS, and the Frebell home page has a "status" page which says that Freebell is "58% complete".

Anyway, for anyone interested in really getting into a Rebol-clone, both are worth a look.

- obsidian

My primary complaint about Rebol

My primary complaint about Rebol is that parsing depends on function arities. You must know almost all words in a given sequence of words in order to determine what is an argument of what.

A side effect of this is that there are no functions which can be called with different arities. There is separate func and function, return and exit, if and when etc.

ah. so that's how they put t

ah. so that's how they put the parentheses back in? :o)

Free ranging evaluation

This is one of the more common issues programmers bring up, but I'm not sure your examples are the best. e.g. FUNC is just handy a shortcut for FUNCTION. It's a bit ironic that FUNC is simpler both internally and externally--mapping directly to the args it takes to make a function--so FUNCTION is almost never used. I know one guru who uses it though. It can make it easier to generate code, create higher order functions, etc., because the locals you define are a separate block.

Some other functions, like RETURN and EXIT, are words chosen specifically for their meaning; they don't exist because of the arity issue. You can make RETURN act like exit if you want, because it can take any type of argument, including unset!.

> test: func [flag [logic!]] [if flag [return] false]
>> test true
>> test false
== false

The Forth influence in REBOL drives the importance of words, their selection, and building up vocabularies to write your program in.

Now, I'll be the first to admit that I've been bitten by this design feature more than once, but I wouldn't want to give it up when I think about what it would mean to the fundamental design of the language.

Refinements

Refinements are another feature that alleviate the pain of fixed arity for some people. e.g.

> round 2.5
== 3
>> round/even 2.5
== 2
>> round/to 2.345 .25
== 2.25
>> round/to 2.375 .25
== 2.5

You have a point

Previous replies focused on the single-arity of functions, which misses the point. The issue is that, because there is nothing to show when a function's arglist ends, and because each argument can itself be a heavily nested function invocation, you can't understand a piece of code until you know the arity of EVERY function, you can't even tell which words are (used as) functions and which are values. Compare these two:

f a x y b 12 c foo "bar" baz
f (a(x,y), b(12), c(foo,"bar",baz))

There's a lot more information in the second line above.

One way to think of this problem is, "You don't know anything until you know everything." That syndrome makes a system hard to learn -- even if that system may be quite easy to use after it's mastered.

That said, I still wholeheartedly agree with the previous poster who wrote that, although it has created difficulties he wouldn't want to give it up. Ditto. It's a darned elegant language, and quite concise.

What I would prefer is a better editing and visualization tool which can show me, in some way, which words are functions and for each, which expressions are its arguments. But there's a problem here. REBOL-as-code is just one dialect of the language, albeit an important one. The rules which govern the meaning of a block (including the top-level implied block), and therefore how it should be highlighted, is dependent on how it's used, which we don't truly know for sure until runtime. I don't really know how to solve that problem in a general way.

Active Clone Project

Orca is the only clone that is actively developed at the moment.

http://wsrebol.sourceforge.net/

License versus DSLs

"a bit odd/worrying (how can you not modify a language that expressly encourages DSLs?)"

It has never seemed odd to me. Does it seem odd that you can extend certain IDEs with plug-ins, but you can't modify the IDE?

The hard part is where you want to add a new datatype for your DSL, but you don't want to drop down to string parsing. This has been discussed, but lexical space in REBOL is very tight as it is, so it's a tough call, and I don't know that having that ability would help the language overall, or at least nobody has proposed a great solution to the problem yet.

Heck, I still struggle with how best to combine DSLs on top of languages. :)

World Domination

REBOL's plan for world domination is the Semantic Web in colored wrapping paper. The conceptual match is close to exact. Instead of RDF ontologies, you have declarative "dialects" traversing the WWW in Carl's Lisp variant.

Dialect invention falls to the REBOL hacker. That assignment is not a good thing. Think about industry coalitions and standard terminology for data automation. Is REBOL the way? Whether Carl knows about RDF or the SemWeb, his marketing about industry-specific "dialects" is identical in spirit. He invites Joe Java to write English-style declarative programs in a modified Lisp. As a personal tool that is fine. As world domination it is awful.

To focus the point here's an example of someone else doing REBOL's job without REBOL, Internet Business Logic. This tool enables, in its own words, "Open Vocabulary English Business Rules for Semantic Integration of Networked Databases." It's pretty much RDF style inference based on predicates established through open, but strict, English vocabulary. The user defines actual semantic predicates, not REBOL "dialects" which require a programmer. So we write down actual statements about the real world and run queries and inferences against them. This arrangement is much better.

Defined vocabulary appeals to me. Long ago I did a database upgrade associated with production. The data were parts, drawings, sub-drawings, manufacturing and maintenance schedules, etc. The data entry people would sometimes make up their own variant spellings for certain things. That was very long ago on legacy equipment considered old even then, so we had no way to prevent the breaches, except by company policy directives which were faithfully ignored. Software vocabulary rules prevent that kind of problem.

A fresh thread for Internet Business Logic

...has opened here for non-REBOL-related discussions of their work.

REBOL is not RDF

REBOL is much closer, in spirit, to XML than RDF. i.e. it's a general data format, while RDF is based on the idea of identifying things using Web identifiers, properties, and values. There are big differences between XML and REBOL of course. REBOL was designed from the outset to be interpreted (evaluated) and it has no ties to SGML.

What is it that makes REBOL seem like RDF to you?

I agree that defined vocabularies for industry are a wonderful thing, but there's nothing preventing organizations or industry groups from doing this with REBOL. Dialects are not necessarily industry specific, though, they are domain specific; and they aren't about being declarative in nature, though they can be of course. Look at what MS is targeting with their approach to DSLs and software factories.

I'm not sure if world domination is the goal either; maybe being a personal tool is REBOL's target.

okay, then how do I

get a webpage and write it to my local disk with Internet Business Logic, with Rebol it's

write %result.html read http:/lambda-the-ultimate.org/

----------------------------------------------------------

"The user defines actual semantic predicates, not REBOL "dialects" which require a programmer."

Unfortunately it has been my experience that when someone uses phrases like "semantic predicates" (actually anything with semantic in it will do), what will actually be required is for someone more highly paid than most programmers to write these things, and then it may require a programmer to make them work.

Expensive programmers

Pantagruel,

I wish LtU would grow up sometimes. Before issuing snide remarks, inspect the bio of your target. Personally I do not work in "semantics."

To address your baited technical content, I suppose an IBL equivalent might possibly read, with vocab so defined, get webpage X and write it to my local disk

Gregg,

You make several wrong assertions and comparisons but, mainly, misinterpret what I said. I meant that Carl and SemWeb share a dream of inter-networked bots sharing information (semantics), not that their respective software compares. Juxtapose Carl's vision statements against SemWeb's to see that point. They sound a lot alike.

Carl fails in separation of concerns. We probably don't want business semantics buried in custom REBOL code all over the net (Carl's idea of big success), but explicitly defined in a general-purpose way, using RDF or something better like IBL. To the extent that REBOL does only Internet programming, and does not trap business logic in REBOL dialects a/k/a Lisp macros, then REBOL doesn't have to compete with SemWeb.

We already have masses of business logic trapped in custom code -- talk of expensive programmers! Fulfilling Carl's dream just re-creates the problem, albeit with Internet savvy. IBL permits "normal humans" to push/pull data for themselves. I think REBOL is a wonderful tool and well done, but Carl's version of the semantic dream is dangerous. One system is a step forward, the other is a step sideways.