Home   Archive   Permalink



Why is Rebol different? About Rebol Dialects

Rebol sports some seriously concise examples which accomplish a lot with very little code. That's largely because it's designed to use dialects (DSLs, domain specific languages). The example here: http://rebolforum.com/index.cgi?f=printtopic&permalink=Brother%20Damian13-Dec-2013/2:09:33-8:00&archiveflag=new made me realize that new users might not be familiar with how dialects work, or how they're powerful.
    
In the context of a GUI code block, the code you'll see is meant only to display GUIs, and even familiar words in the core REBOL lanaguage operate differently than they do in other contexts. The word 'at for example, does something very different in VID code, than it does when manipulating series structures in the "do" dialect. And beyond that, the VID dialect isn't just made up of variables, functions, objects, etc., as you might expect - it's made of an entire grammar that is specifically tailored to be as concise as possible when dealing with that particular domain. The code inside a VID block can be of any arbitrary length, and that code is parsed by a set of rules written in Rebol so that the VID code is evaluated into lower level Rebol code. In the case of VID, the lower level code is "View" engine code meant to display graphics on the screen. The Draw dialect works in a similar way, you can use it to layout graphics, using a readable, high level grammar. Any example of Draw code can be of arbitary length and complexity, and the rules which make up the draw dialect "decompile" it into lower level instructions that can be sent to the View engine to compose images on screen. The only hitch is that any code in a block of draw code must follow the grammar rules set up only to parse draw code. You can't include code structures such as loops, if they're not part of a given grammar's parse rules.
    
In Rebol's built-in parse dialect, the grammar is specifically tailored to effectively match patterns in strings and blocks (so that that dialect itself can be used to parse other dialects). If you use Gabriele's PDF dialect, you'll see that the grammar is specifically geared towards doing things related to the domain of PDF creation. You may look at RebGUI and see that the dialect is based on the familiar VID grammar, but with lots of redesigned features. The q-plot dialect is a grammar designed to simplify the presentation of charts and graphs, using a dialect (code parsed according to specific grammar rules), which are relevant only to that specific coding domain. Anyone can create a grammar to simplify the code needed to enable routine activities, and if the dialect is designed well, you can potentially create an extraordinarily readable and concise DSL which makes work easy within any particular domain.    
    
Rebol has some core features that are designed to make dialect creation much simpler and more natural than in other languages. The versatile block/series structure - used to hold and manipulate lists of any type of data and/or code; data types, which can be complex and specialized, and which enable more simple parsing rules; and especially Rebol's powerful 'parse capabilities, provide developers the ability to build grammars which are dramatically concise at accomplishing their purpose. The fact that Rebol has all the basic building blocks used in computing - file and network access, graphics, math, logic, flow control, etc. - all built in, allows very powerful dialects to be built which provide solutions in a wide variety of problem domains.
    
A great article about actually building dialects can be found here:
    
http://rebol2.blogspot.com/2012/01/tui-dialect-dialect-to-print-ascii.html
    
It covers the basic concepts and techniques of Rebol dialect creation, with a simple example that I've used for console applications in R2 (see http://business-programming.com/business_programming.html#section-20.1 ) After reading that text, it should be more clear why you can't include, for example, a 'for loop, within a block of VID dialect code (because the rules made to parse the VID dialect do not parse that code pattern properly).

posted by:   Nick       13-Dec-2013/16:40:11-8:00



(Edit: quite a few changes)

posted by:   Nick       14-Dec-2013/23:07:17-8:00



Here are some ideas about the sorts of simple dialects that Carl imagined: http://www.rebol.com/rebolsteps.html#section-10

posted by:   Nick       14-Dec-2013/23:19:39-8:00



Another useful tutorial: http://suite101.com/a/how-to-createa-rebol-dialect-a130067

posted by:   Nick       14-Dec-2013/23:37:22-8:00



Here's a nice short example of a dialect: https://code.google.com/p/rebol/downloads/detail?name=to-do-guru.r

posted by:   Nick       14-Dec-2013/23:58:30-8:00



And parse rules for the Rebol/Flash dialect: http://rebol.desajn.net/rswf/swf-tag-rules_enczes.rb

posted by:   Nick       14-Dec-2013/23:59:15-8:00



Heck, you can build a BASIC interpreter in a few pages of Rebol code: http://rebol2.blogspot.com/2012/02/basic-intepreter.html

posted by:   Nick       15-Dec-2013/0:06:35-8:00



Thanks for all your post. They're very informative and a great help.

posted by:   Sam       12-Feb-2014/22:36:05-8:00