Jul 2007
Natives vs. Actions vs. Mezzanines
28-Jul-2007 11:23 Filed in: REBOL
Beginners
If you're a bit curious to learn some deeper aspects
to how REBOL is built, it's practical to know the
difference between native functions
and mezzanine functions.
When you use the SOURCE function on another function, sometimes, you'll get the source code for that function and other times, you won't. Natives don't output source code:
Well, what is a native? Natives are the basic method for doing something. They are written in C, and therefore you can't see its source code in the console, because the function is part of the very core of REBOL and can't be altered directly.
Mezzanine functions are built of natives or a combination of natives and other mezzanine functions.
In the case of the native function INSERT, it's used to build other functions, like APPEND.
If you look at the output (too long to paste here) of:
...you'll find the INSERT function inside it.
This is one of the reasons that REBOL has so many functions despite having such a small executable!
You can see the complete list of native functions, by calling up:
You can do that, because native functions have their own datatype, native!, while mezzanine functions are of type function!.
A third type called action! also exists, which is similar to natives, except that they are internally implemented differently as methods, where natives are more like normal C functions. For you, the REBOL programmer, there's no real need to know the difference between actions and natives.
Thanks to John Niclasen and Gabriele Santilli with helping with this blog post via AltME!
When you use the SOURCE function on another function, sometimes, you'll get the source code for that function and other times, you won't. Natives don't output source code:
>> source insert
insert: native [
{Inserts a value into a series and returns the series after the insert.}
series [series! port! bitset!] "Series at point to insert"
value [any-type!] "The value to insert"
/part "Limits to a given length or position."
range [number! series! port! pair!]
/only "Inserts a series as a series."
/dup "Duplicates the insert a specified number of times."
count [number! pair!]
]
Well, what is a native? Natives are the basic method for doing something. They are written in C, and therefore you can't see its source code in the console, because the function is part of the very core of REBOL and can't be altered directly.
Mezzanine functions are built of natives or a combination of natives and other mezzanine functions.
In the case of the native function INSERT, it's used to build other functions, like APPEND.
If you look at the output (too long to paste here) of:
>> source append
...you'll find the INSERT function inside it.
This is one of the reasons that REBOL has so many functions despite having such a small executable!
You can see the complete list of native functions, by calling up:
>> help native!
You can do that, because native functions have their own datatype, native!, while mezzanine functions are of type function!.
A third type called action! also exists, which is similar to natives, except that they are internally implemented differently as methods, where natives are more like normal C functions. For you, the REBOL programmer, there's no real need to know the difference between actions and natives.
Thanks to John Niclasen and Gabriele Santilli with helping with this blog post via AltME!
|
LIST-VIEW 0.0.51 released
26-Jul-2007 18:51 Filed in: LIST-VIEW
A few critical bugfixes are fixed in the latest
0.0.51, particularly with regards to SET-FACE and
CLEAR-FACE. It can be downloaded, as always, from the
downloads section.
REBOL 3 progress
25-Jul-2007 10:49 Filed in: REBOL 3
People are working very hard on various parts of
REBOL 3. One of these things is the prototype for the
next version of VID, which already now can do some
things easily, which are difficult to do in the old
VID.
Two of these things are:
- Resizing of window will make the elements adapt to the new window size automatically.
- The look of the UI will be separate from the feel code, so it's much simpler to redesign the skin.
The obligatory screenshot:
Two of these things are:
- Resizing of window will make the elements adapt to the new window size automatically.
- The look of the UI will be separate from the feel code, so it's much simpler to redesign the skin.
The obligatory screenshot:
OK, back to work!
![]()
Loading Configuration Data
20-Jul-2007 21:18 Filed in: REBOL
Beginners
I’m always pleased at how REBOL allows you to
skip work that you’d normally have to do in
other languages, such as loading configuration data
and making use of this data in your programs.
Normally, you might have to:
- Invent a configuration file format.
- Decide on a method to store configuration data in a file.
- Decide on a method to load and parse configuration data and use it in the program.
or if you are a former XML fan, you’d find a bigarse library to parse XML files, written out with an XML generator. Bloated. Slow.
If you like a challenge, you can do all that in REBOL. REBOL has a fine parser, that will easily parse strings of text read from disk.
But REBOL can do all of this without you writing a lot of boring code.
The magic trick to use here is LOAD. LOAD is pretty good at loading data and you can use LOAD on files, internal data and network resources.
If you create a file, say, %config.r, which contains:
and nothing else, you can LOAD this file into a block in one go:
Now what REBOL does here is more than just reading the data off disk; It creates a block of valid REBOL elements of the correct datatypes. You now actually have a valid piece of data that is ready to be further processed or run. Yes, run!
Because when you DO the loaded data, the data is suddenly code that is executed. The items "name:" "address:" and "registration-number:" become variables in the system, with their respective values assigned to them.
The full piece of code would be:
This is actually all you need to do! Ridiculously simple!
You can do this, because data and code are the same thing in REBOL. Imagine the possibilities...
Normally, you might have to:
- Invent a configuration file format.
- Decide on a method to store configuration data in a file.
- Decide on a method to load and parse configuration data and use it in the program.
or if you are a former XML fan, you’d find a bigarse library to parse XML files, written out with an XML generator. Bloated. Slow.
If you like a challenge, you can do all that in REBOL. REBOL has a fine parser, that will easily parse strings of text read from disk.
But REBOL can do all of this without you writing a lot of boring code.
The magic trick to use here is LOAD. LOAD is pretty good at loading data and you can use LOAD on files, internal data and network resources.
If you create a file, say, %config.r, which contains:
name: "My Name"
address: "My Address"
registration-number: 123456789
and nothing else, you can LOAD this file into a block in one go:
>> load %config.r
== [name: "My Name" address: "My Address"...
Now what REBOL does here is more than just reading the data off disk; It creates a block of valid REBOL elements of the correct datatypes. You now actually have a valid piece of data that is ready to be further processed or run. Yes, run!
Because when you DO the loaded data, the data is suddenly code that is executed. The items "name:" "address:" and "registration-number:" become variables in the system, with their respective values assigned to them.
The full piece of code would be:
do load %config.r
This is actually all you need to do! Ridiculously simple!
You can do this, because data and code are the same thing in REBOL. Imagine the possibilities...
New LIST-VIEW Demo Section
13-Jul-2007 01:24 Filed in: LIST-VIEW
The old Demo lab is gone now, since it was not useful
since version 0.0.15, which is quite a long time ago.
This has now been replaced with a demo section, which can be seen here.
This has now been replaced with a demo section, which can be seen here.
LIST-VIEW 0.0.50 released
12-Jul-2007 18:12 Filed in: LIST-VIEW
It's been a long time, but LIST-VIEW 0.0.50 is
available now! There's a ton of fixes and a few new
features.
Check the downloads section to see more.
Check the downloads section to see more.
Checking block structures
06-Jul-2007 18:43 Filed in: REBOL
Beginners
Do you have a large block of data that you want to
check the structure of?
PARSE is a good way to do that, since it returns TRUE if it can parse the entire block properly. PARSE happens also to be very fast.
Our data should be a block of blocks:
data-block: [
[1 2 3]
[4 5 6]
[7 8 9]
]
So you can simply check that each entry is a block:
>> parse data-block [any block!]
== true
Let's sabotage our data block:
data-block: [
[1 2 3]
none ; oops!
[4 5 6]
[7 8 9]
]
>> parse data-block [any block!]
== false
Simple!
PARSE is a good way to do that, since it returns TRUE if it can parse the entire block properly. PARSE happens also to be very fast.
Our data should be a block of blocks:
data-block: [
[1 2 3]
[4 5 6]
[7 8 9]
]
So you can simply check that each entry is a block:
>> parse data-block [any block!]
== true
Let's sabotage our data block:
data-block: [
[1 2 3]
none ; oops!
[4 5 6]
[7 8 9]
]
>> parse data-block [any block!]
== false
Simple!