Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Rebol
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Design== ===Ease of use=== One of the Rebol design principles is "to do simple things in simple ways".<ref name="RD" /> In the following example the ''Visual interface dialect'' is used to describe a simple [[Hello world program]] with a graphical user interface: <syntaxhighlight lang="smalltalk">view layout [text "Hello world!" button "Quit" [quit]]</syntaxhighlight> This is how a similar example looks in R3-GUI: <syntaxhighlight lang="smalltalk">view [text "Hello world!" button "Quit" on-action [quit]]</syntaxhighlight> [[File:R3-GUIHelloWorld.png|R3-GUI Hello world example]] ===Dialects=== Rebol [[domain-specific language]]s, called ''dialects'', are micro-languages optimized for a specific purpose. Dialects can be used to define business rules, graphical user interfaces or sequences of screens during the installation of a program. Users can define their own dialects, reusing any existing Rebol word and giving it a specific meaning in that dialect.<ref name="RD" /> Dialects are [[interpreted language|interpreted]] by functions processing Rebol blocks (or parsing strings) in a specific way. An example of Rebol's dialecting abilities can be seen with the word <code>''return''</code>. In the ''data exchange dialect'' <code>''return''</code> is just a word not having any specific meaning. In the ''do dialect'', <code>''return''</code> is a [[global variable]] referring to a native [[Function (computer science)|function]] passing back a function result value.<ref name="OG">Goldman, E., Blanton, J. (2000). ''REBOL: The Official Guide.'' McGraw-Hill Osborne Media. {{ISBN|0-07-212279-X}}.</ref> In the ''visual interface dialect (VID)'', <code>''return''</code> is a [[Keyword (computer programming)|keyword]] causing the layout engine to simulate a [[carriage return]], moving the "rendering pen" down to the beginning of the next line.<ref name="RP" /> A Rebol interpreter with graphical abilities must understand and interpret many dialects. The table below lists the most important ones in order of significance. {| class="wikitable" |- ! Dialect name ! Interpreted by ! Purpose |- | Data exchange dialect | <code>load</code> function | represents data and metadata; common platform for Rebol dialects |- | Do dialect | <code>do</code> function | programming |- | Parse dialect | <code>parse</code> function | [[pattern matching]] |- | Function specification dialect | <code>make</code> function | [[function (computer science)|function]] definition; [[functional programming]] |- | Object specification dialect | <code>make</code> function | [[object (computer science)|object]] definition/inheritance; [[prototype-based programming]] |- | Visual interface dialect (VID)<br>or<br>RebGUI | <code>layout</code> function<br>or<br><code>display</code> function | specifies [[graphical user interface]] |- | Draw dialect | <code>view</code> function | defines graphical elements (lines, polygons, etc.) |- | Script specification dialect | <code>do</code> function | script definition |- | Security policy dialect | <code>secure</code> function | specifies security policy |} ===Syntax=== Rebol [[syntax (programming languages)|syntax]] is [[free-form language|free-form]], not requiring specific positioning. However, [[indent style|indentation]] is often used to better convey the structure of the text to human readers. Syntactic properties of different dialects may differ. The common platform for all Rebol dialects is the ''data exchange dialect''; other dialects are usually derived from it. In addition to being the common platform for all dialects, the ''data exchange dialect'' is directly used to represent data and metadata, populate data structures, send data over Internet, and save them in data storage. In contrast to programming languages like [[C (programming language)|C]], the ''data exchange dialect'' does not consist of [[declaration (computer science)|declarations]], [[statement (programming)|statement]]s, [[expression (programming)|expressions]] or keywords. A valid ''data exchange dialect'' text stream is a [[tree data structure]] consisting of blocks (the root block is implicit, subblocks are [[delimiter|delimited]] by [[bracket|square brackets]]), parens (delimited by [[bracket|round brackets]]), [[string (computer science)|strings]] (delimited by [[quotation mark|double quotes]] or [[bracket|curly brackets]] suitable for multi-line strings; [[caret notation]] is used for unprintable characters), [[Uniform Resource Locator|URLs]], e-mail addresses, files, paths or other [[scalar (computing)|composite values]]. Unlike [[ALGOL]] [[block (programming)|blocks]], Rebol blocks are composite values similar to quoted [[s-expression]]s in [[Lisp (programming language)|Lisp]]. The fact that code is written in the form of Rebol blocks makes the language [[homoiconicity|homoiconic]].<ref name="OG" /> Blocks as well as parens may contain other composite values (a block may contain subblocks, parens, strings, ...) or [[scalar (computing)|scalar values]] like words, set-words (words suffixed by the [[colon (punctuation)|colon]]), get-words (words prefixed by the colon), lit-words (words prefixed by the [[apostrophe (mark)|apostrophe]]), numbers, money, [[character encoding|characters]], etc., separated by [[whitespace (computer science)|whitespace]]. Special characters are allowed in words, so <code>a+b</code> is a word unlike <code>a + b</code>, which is a sequence of three words separated by spaces. [[Comment (computer programming)|Comment]]s may appear following the [[semicolon]] until the end of the line. Multi-line comments or comments not ignored by the lexical parser can be written using "ordinary" datatypes like multi-line strings.<ref name="OG" /> ===Semantics=== Blocks containing domain-specific language can be submitted as [[argument (computer science)|arguments]] to specific ''evaluator'' functions.<ref name="RD" /> ====do==== The most frequently used evaluator is the <code>do</code> function. It is used by default to interpret the text input to the interpreter [[command line interface|console]]. The ''do dialect'' interpreted by the <code>do</code> function, is an [[expression-oriented programming languages|expression-oriented]] sublanguage of the ''data exchange dialect''. The main semantic unit of the language is the [[expression (programming)|expression]]. In contrast to imperative programming languages descending from [[ALGOL]], the ''do dialect'' has neither keywords, nor statements. Words are used as [[case sensitivity|case-insensitive]] [[variable (programming)|variables]]. Like in all [[dynamically typed language]]s, variables don't have an associated type, type is associated with values. The result, i.e. the evaluation of a word is returned, when a word is encountered by the <code>do</code> function. The set-word form of a word can be used for [[assignment (computer science)|assignment]]. While not having statements, assignment, together with [[side-effect (computer science)|functions with side-effects]] can be used for [[imperative programming]].<ref name="OG" /> Subblocks of the root block evaluate to themselves. This property is used to handle data blocks, for [[structured programming]] by submitting blocks as arguments to [[control flow|control]] functions like <code>if</code>, <code>either</code>, <code>loop</code>, etc., and for dialecting, when a block is passed to a specific interpreter function.<ref name="RD" /> A specific problem worth noting is that composite values, assigned to variables, are not copied. To make a copy, the value must be passed to the <code>copy</code> function.<ref name="OG" /> The <code>do</code> function normally follows a [[polish notation|prefix style of evaluation]], where a function processes the arguments that follow it. However, [[infix notation|infix evaluation]] using infix [[operator (programming)|operator]]s exists too. Infix evaluation takes precedence over the prefix evaluation. For example, [[absolute value|abs]] -2 + 3 returns 1, since the infix addition takes precedence over the computation of the absolute value. When evaluating infix expressions, the order of evaluation is left to right, no operator takes [[Order of operations|precedence]] over another. For example, <syntaxhighlight lang="smalltalk"> 2 + 3 * 4 </syntaxhighlight> returns 20, while an evaluation giving precedence to multiplication would yield 14. All operators have prefix versions. <code>Do</code> usually evaluates arguments before passing them to a function. So, the below expression: <div class="plainlinks"> print read http://en.wikipedia.org/wiki/Rebol </div> first reads the Wikipedia Rebol page and then passes the result to the <code>print</code> function. Parentheses can be used to change the order of evaluation. Using [[Polish notation|prefix notation]], the usage of parentheses in expressions can be avoided.<ref name="OG" /> The simple precedence rules are both an advantage: * No need to "consult" precedence tables when writing expressions * No need to rewrite precedence tables when a new operator is defined * Expressions can be easily [[transliteration|transliterated]] from infix to prefix notation and vice versa as well as a disadvantage: * Users accustomed to more conventional precedence rules may easily make a mistake<ref name="RD" /> ====parse==== The <code>parse</code> function is preferably used to specify, validate, transform and interpret dialects. It does so by matching ''parse expressions'' at run time.<ref name="RD" /> ''Parse expressions'' are written in the ''parse dialect'', which, like the ''do dialect'', is an expression-oriented sublanguage of the ''data exchange dialect''. Unlike the ''do dialect'', the ''parse dialect'' uses keywords representing operators and the most important [[terminal symbol|nonterminals]], infix parsing operators don't have prefix equivalents and use precedence rules (''sequence'' has higher precedence than ''choice'').<ref name="RD" /> Actions can be included to be taken during the parsing process as well and the <code>parse</code> function can be used to process blocks or strings. At the ''string parsing'' level <code>parse</code> must handle the "low level" parsing, taking into account [[character (computing)|characters]] and delimiters. ''Block parsing'' is higher level, handling the scanning at the level of Rebol values.<ref name="RD" /> The parse dialect belongs to the family of grammars represented by the [[top-down parsing language]] or the [[parsing expression grammar]] (PEG). The main similarity is the presence of the ''sequence'' and ''choice'' operators all the family members have. Parse dialect syntax and the similarities between the parse dialect and the PEG are illustrated by this transliteration of a [[Parsing expression grammar#Examples|PEG example]] that parses an arithmetic expression: <syntaxhighlight lang="smalltalk"> Digit: charset [#"0" - #"9"] Value: [some Digit | "(" Expr ")"] Product: [Value any [["*"| "/"] Value]] Sum: [Product any [["+"| "-"] Product]] Expr: Sum parse/all "12+13" Expr</syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)