This is a blog about Rebol, it's a fantastic free programming language, it permits easily to create complete software with few lines of code. It's cross-platform, so if you write it on Windows, it will work on Linux and Mac, and vice-versa. You can produce also wonderful GUI with just 3 lines of code!

I just imported all most important wiki about Rebol (2 and 3) in it, forum is already divided in sub-forum, support links, images, attachments and flash videos. Image gallery already contains Rebol 2 examples, Rebol 3 examples and the original Rebol 3 GUI images form Carl S. The blog at the moment is just a copy of this one, but you can register and send articles.

I ask to all rebol users in the world to start use it, because at the present every developer is inside his little cave, without any communication with the external world. Rebol 3 is open source now, but it's missing all most important features of Rebol 2 (VID, sound, ...). We must organize and decide what to do, all other communication channels are too closed, slow or disorganized.
Come on join the portal, you'll find only friends abroad.

Now, do you understand the importance of "invisible" new-lines in block? They make files human readable!
Rebol has the new-line function to switch or insert new lines in blocks, let's see how it works.
First of all new-line has a refinement called /all that add or remove all newlines from block, setting the newline value true or false, example:
new-line/all address-book false
? address-book
new-line/all address-book true
? address-book

Moreover you can set the new-line on o off also only in a specific point (use at:
new-line at address-book 2 off
>> ? address-book
ADDRESS-BOOK is a block of value: [
Michelle ["+3906500000" "S. Mary St." "Rome" "Italy"]
Carl
["+155500000" "Sassenrath Ranch" "San Francisco" "USA"]
]

I remember you also that ON, TRUE and YES are the same thing on rebol, and OFF, FALSE, NO are the same thing on rebol.

Monday, 28 January 2013

Mr. Brett Handley has a great site about Rebol: http://www.codeconscious.com
and he made a lot of useful scripts. Today we will discover three of them about PARSE. I contacted him and he was so kind to answer to my email and writing the following examples and concepts.
If this post seems too complicated, jump to the examples and all will become clear (otherwise post your questions on the comments :-) )
First of all let's see the scripts:

Brett says about this script: "My first insight was to realize a script I could track parse rules by modifying them to call tracking code. In this way I could have some functions help me debug complex parse rules.
I used the concept of hooking into existing parse rules. This allows tracing of parse rules that you may have downloaded or even the parse rules used by REBOL's mezzanine functions (e.g REBOL's parse-xml function)."

Here is the script:

REBOL [
Title: "Parse Analysis Toolset"
Date: 17-Dec-2004
File: %parse-analysis.r
Purpose: "Some tools to help learn/analyze parse rules."
Version: 1.1.0
Author: "Brett Handley"
Web: http://www.codeconscious.com
license: {
Copyright (C) 2004 Brett Handley All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
May not be executed within web CGI or other server processes.
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the author nor the names of its contributors may be used to
endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
]hook-parse:func ["Hook parse rules for events: test a rule (Test), rule succeeds (Pass), rule fails (Fail). Returns hook context."
rules [block!] "Block of words. Each word must identify a Parse rule to be hooked."/local hook-context spec
] [; Check the input

hook-context:context [step:level:status:current:; State tracking variables.rule-words:; The original rules (maintaining their bindings).rule-def:; The original rule values.last-begin:; A variable to track the input position when the rule starts.last-end:; A variable to track the input position when the rule ends.pass:fail:test:; Functions called when the corresponding parse event occurs. nonereset:does [step:level:0last-begin:last-end:current: none]
]hook-context/rule-words: rules; Create a context to store the original rule definitions.

spec:makeblock!multiply2length? rulesrepeat rule rules [inserttail spec toset-word! rule]hook-context/rule-def:contextappend spec [none]; Modify the given rules to point to the; hook-context's tracking rules and save; the original rules.

Enables you to trace the execution of parse rules. It replaces rules with modified rules that track the parse state. Returns an object that represents the parse state and stores the original parse definitions. It is important to note that any rules you do not hook are not tracked and do not appear in the outputs. This is useful when you want to filter out terms that are not important to your application. On the other hand you do not want to filter out terms that are necessary to get a complete picture of the parsing. For example: If your data is described by [a b c] and you filter out b - you will miss important information. But if your data is descibed by [a b] where b: [x y z] and you filter out b OR you filter out x, y and z then there is no problem because your input is completely specified by the rules.

Unhook-Parse

Removes the calls to tracing code, to return the parse rules back to their original definitions.

Count-Parse

Counts each time rule is tested, passed or failed. The result is in the form: [rules test-counts pass-counts fail-counts] Two benefits of this function:

the results may give some insight into which rules are doing all the work.

the code shows how you can set the event functions in the hook context.

Explain-Parse

Interprets events as the parse rules are executing - useful for debugging rules. By default displays the events as they occur which can help with debugging complex parse rules. There are begin events and end events and each is numbered sequentially as they occur. Each shows the input index position after the word AT. The end event shows the number of the begin event it is paired with after the word STARTED-ON. explain-parse is used by tokenise-parse and load-parse-tree.

Tokenise-Parse

Returns a sequence of tokens where each token is a triple of the form:
rule-name length-of-input-matched input-index-position
This output form allows the result to be reversed and sorted by index positions if desired. The output from Tokenise-parse is used by make-token-highlighter of parse-analysis-view.r script.

Even in this case you must remember that output is in the form: rule-name length-of-input-matched input-index-position
so a word i length 5 chars and start at position 1; a number start at position 12 and it's 3 chars length.

Brett says about this script: "My second insight was to realize I could visualize how the rules break up text by displaying the textual input in a window and overlaying it with boxes and colors that represent the rules."

Brett says about this script: "My third insight was to realise that parse rules describe the structure of a format implicitly and that each parse rule name (a word) represents a term in the structure.
The normal way to build output with parse rules is to add actions (parens) to the rules that build up the output structure. In my mind this is a duplication, because the parse rules describe the structure, and now we build it again with output actions.
So instead of those actions and their redundancy I decided to write a function that automatically creates an output structure just by tracking which parse rules were successful as they are executed. This allows an abstract syntax tree of the input to be built automatically."

Here is the script:

REBOL [
Title: "Load-Parse-Tree (Parse-Analysis)"
Date: 17-June-2006
File: %load-parse-tree.r
Purpose: "Load a block structure representing your input as matched by Parse."
Version: 1.0.0
Author: "Brett Handley"
Web: http://www.codeconscious.com
Comment: "Requires parse-analysis.r (see rebol.org)"
license: {
Copyright (c) 2006, Brett Handley
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* This program must not be used to run websever CGI or other server processes.
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* The name of Brett Handley may not be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
}
]load-parse-tree:func ["Tokenises the input using the rule names."
body [block!] "Invoke Parse on your input. The block must return True in order to return the result."
hook-context [object!] "Hook context returned by the Hook-Parse function."/blockinput [any-block!] "For block input, supply the input block here so it can be indexed."
] [use [stack result fn-b fn-e block-list index-fn] [index-fn::index?stack:makeblock!20result:copy []fn-b:does [insert/onlytail stack resultresult:copy []
]fn-e:func [context-stack begin-context end-context /local content tk-len tk-ref] [; Restore state to parent of just completed term.content: resultresult:last stackremovebacktail stack; Term has just completed - insert it into the result or discard it.if'pass= end-context/status [either1+ begin-context/step = end-context/step [tk-len:subtractindex? end-context/last-end index? begin-context/last-begin ; Lengthtk-ref: begin-context/last-begin ; Input positioncontent:copy/part tk-ref tk-len
][new-line/all/skip content 12]inserttail result reduce [end-context/current content]
]
]
explain-parse/begin/end body hook-context :fn-b:fn-enew-line/all/skip result true 2
]
]

Friday, 25 January 2013

The script presented today is very interesting, it permits to lock a variable (so any resource), to prevent access to other users.
The script is composed of a server (lock-server)and the client functions (try-obtain-lock and free-lock). Let's see how it works:
open a rebol console do the following script:

As you noted, the first console check if some variable is locked and advice you. You can't obtain TRUE from try-to-obtain if the variable isn't freed.
Well, why is so interesting? The answer is that in a multiuser environment or working with databases, you must know if someone is working on a resource, and avoid job collisions. Just image a webshop that it has just one item to sell and two users simultaneously order the item, only with locking you avoid mistakes.
Another great feature of this script is the client server configuration, this way you can work with multiple users, across internet, and create multithreads programs!!!

Thursday, 24 January 2013

Hello world!
I'm proud to announce a brand new Rebol portal: http://rebol.informe.com/portal.html
There you can find a Forum, a Wiki, a Blog and a Gallery, all free, all open.
Give it a try and post your opinions!