Downloads Products Documents Community

REBOL Language FAQ

Updated: 31-Jan-2010

FAQ related

Platforms related

Help related

System related

Datatypes related

Functions related

File-IO related

Ports related

Misc related

SDK related

Graphics related

CGI related

View related

Parse related


#068How do I submit a question to the FAQ?
 

Submit your question using our standard feedback form.

#069What should I do if I find an error in the FAQ?
 

Please let us know about it. Use the feedback form to reach us.

#075How can I hide my script within a single executable program?
 

We sell and license to a tool called REBOL/Encap that will compress, encrypt, and encapsulate your scripts (plus any data and images too) into a single executable file. This tool is fast and easy to use (runs without a GUI, like a compiler). For more information, contact us.

#077How are the FAQs ordered here?
 

FAQs on this page are ordered by their importance.

#078With the SDK how can I use the View/Pro features without encapping my files?
 

The license.key file that came with your SDK will unlock all of the /Pro features in both /Pro and /Face. To run your script without encapping it first (for testing purposes), you have two choices:

1. Add #includes into your script to include what modules you need from the REBOL source. This will let you use the console for debugging.

2. Build an encap program that has all the modules,but then loads your script as the last step. The console can be used for output, but not for interaction.

#079When does REBOL free memory?
 

The garabage collector does not free memory until it needs to. Otherwise, it would be running constantly and slowing down programs by a lot.

#081Can REBOL dynamically generate graphics for websites?
 

Yes it can, but it depends on your server and version of REBOL.

If you use Windows for your server, then REBOL/View can be used with server scripts (such as in CGI) to dynamically generate graphics. This is easly done by creating layouts then converting them to images:

    out: layout [
        image %picture.jpg
        text "This is a picture"
    ]
    img: to-image out
    save/png %image.png img

Note that only PNG output is currently available, but GIF output will be added in next release (because the patent has finally expired.) We also want to add JPEG output.

If you use Linux, BSD, etc., then the results will depend on whether your server has X Windows (graphical user interface) installed and initialized. If not, then REBOL will be able to generate images and effects (requires REBOL/Command), but not be able to generate text, because it uses the X Fonts to do so. If X Windows is running, you can use the same code as shown above.

#001How do I get REBOL to not ask me for permission to write files each time I start it?
 

If you are running REBOL on anything except Macintosh, you can launch it from the command line with the -s option.

Examples:

Windows

    rebol.exe -s

Every other system

    rebol -s

or

    ./rebol -s

If you are running it on a Macintosh (or any other system), you can put the following line in your %user.r file:

    secure none

The above will prompt the user once to lower the security for the whole session. Currently, the Mac version has not yet defined a way to start a script without security as the Mac doesn't directly support the command-line flag standard present on the other supported systems.

Windows allows for setting command line parameters for icon shortcut commands. Right click on the directory you wish you create the REBOL shortcut with the security turned off in and follow the instructions in the Windows shortcut wizard. In the commandline window include the "-s".

Amiga also allows setting parameters in the icon tooltypes. You can turn security off by adding the following lines to your REBOL executable icon Tooltypes:

    --secure
    allow

Additional information can be found in the "Setup.html" document which was packaged with the distribution.

#004When I read and write graphics files they have errors. Why?
 

Be sure to use the /BINARY refinements on READ and WRITE when dealing with binary data such as graphics, programs, compressed data, etc.

    data: read/binary http://web.page.org/pic.jpg

    write/binary %some-pic.jpg data

If you don't, the file will be read as a text string, and any bytes that appear to be line terminations (CR) will be converted or deleted.

#043My function's local data gets changed. Why?
 

This is the most common error in REBOL. If you write a function like:

    f: func [][
        x: []
        append x "a"
    ]

X points to a literal block. That block is not reinitialized with each call to the function, so if you change it, you'll see the change in subsequent calls to the function.

To get a new block each time you have to copy it:

    f: func [][
        x: copy []
        append x "a"
    ]

This is true for other literal series as well (i.e. strings).

    f: func [arg][
        append copy "prefix" arg
    ]

#071Do you support REBOL on Apple OS X?
 

Yes, we now support REBOL on OS X, both on Intel and PPC systems.

#076Can I create Windows installers for my REBOL programs?
 

Yes. If you purchase REBOL/Encap, you can access the Windows registry API and perform custom installation of your program. We provide an example Install.r script that shows how to create and modify registry entries, create file shortcuts, add uninstallers, program groups in the start menu, and more.

An example of a standard Installer graphical interface is also available at no additional charge.

Installers can also be created for other platforms, such as Linux or Unix, but they do not require special registry functions.

#083What is the difference between View and Core?
 

REBOL/View - Provides graphics, sound, GUI, and various extended features that you would use on a desktop computer (a client). We recommend you use REBOL/View. It includes all of the features of REBOL/Core.

REBOL/Core - Is a console-only system that can perform file and networking tasks or run server scripts. It is powerful and small. (Read the downloads page for more details.)

#084How do I reinstall REBOL/View?
 

I uninstalled Rebol view from my Windows XP system. I want to install rebol again but it doesn't install. Double-click works fine but it doesn't make the directory in Program Files, etc.

#Be sure you are logged in with Admin permissions.

#Run REBOL/View and open the console. Type INSTALL.

#If that did not work, type UNINSTALL and do that first. Then try INSTALL again.

#If that does not work, open the windows registry. In HKEY_CURRENT_USER/Software/REBOL delete the View entry. Run REBOL again to reinstall.

#085Do I have to install REBOL?
 

Is it really necessary to install REBOL to run REBOL scripts and programs?

#No. You don't need to.

#REBOL/Core requires no installation, ever.

#REBOL/View does installation to provide icons associations and a default location for the file cache (sandbox). But, it allows you to run without that.

#If you create a shortcut icon, and add a -i option, then REBOL will not try to install.

#009What do I have to do to get REBOL scripts to run directly as CGI's?
 

When using Apache webserver on most unix-like operating systems, add the following line to the top of the script:

    #!/path/to/REBOL -cs

Modify it to provide the correct path to your REBOL program (e.g. REBOL/Core). The -c flag indicates that CGI environment variables need to be read and put into the object:

    system/options/cgi

and the s indicates that you do not want security (if you're not modifying external files, you don't need the s).

Other platforms and/or webservers may require a different method and/or path format for sending the script to REBOL. Check with the documentation on your particular webserver for additional details.

It's a good idea to print out the content type header at the beginning of your script so you can see any errors that might occur, ie:

    #!/path/to/REBOL -cs

    REBOL [Title: "CGI Basics"]

    print ["Content-type: text/html" newline]

    ...

If your script still does not work, make sure that it does not contain improper line terminations for your OS. Although REBOL is forgiving of all types of line terminators, various shells are not.

If your script still does not work, make sure that you've set the proper permissions on the files. Often both the REBOL program and the script file will need read and execute access by all users. On Unix type systems:

    chmod 755 rebol script.r

For more information, see the CGI section of the manual.

#058Why isn't REBOL open source?
 

This is a common question, and one we take seriously.

REBOL is a mix of both closed and open source. The kernel of REBOL, which must be kept extremely consistent between hardware platforms and operating systems, is closed. This keeps platform specific variations to a minimum, allowing your programs to run on Windows, Linux, Unix, and other systems without modification. Our consistent, controlled design process also keeps REBOL very small - its core is less than 250KB.

The layers above the kernel are open. You can obtain the source to the majority of REBOL by using the SOURCE or the MOLD functions. For instance, you can obtain the source to REBOL's Internet protocols or Visual Interface functions, allowing you to better understand how they work and build better programs. The design of REBOL also lets you dynamically replace its built-in functions or objects with ones of your own design.

If what you need is to extend the functions of REBOL, that's why we made REBOL/Command. If you want to embed your REBOL code within a single executable file, that's what REBOL/Encap does.

If you have a large, costly project that will depend on REBOL, and you need the security of knowing that REBOL is not "going away", you can purchase a special REBOL license from us that will give you access to our source code escrow account.

#072Are you going to support Pocket PC, CE, EPOC/Psion, etc.?
 

We have REBOL/Core running on a variety of CE devices. However, porting REBOL/View and related products to specific platforms is accelerated when a customer or sponsor funds the porting effort.

If you have a favorite handheld platform, we encourage you to contact its manufacturer and urge them to support REBOL on the device.

#073Do you support Palm OS devices?
 

No. Palm OS does not provide a sufficient memory model to support larger run-time environments. Even though your Palm device may have 16MB or more, the OS restricts programs to less than 100KB of direct RAM space. REBOL requires more than that. Palm (3Com) controls this restriction, not us. We hope that 3Com decides to expand their Palm memory in the future.

#082Can I encapsulate other, non-REBOL program files with the SDK?
 

Yes, it you can use REBOL/SDK to encapsulate other program executable files. For instance, if you want to create a GUI in REBOL that calls a legacy program that's included with it:

    data: #include-binary %program.exe
    write/binary %program.exe data
    attempt [set-modes %program.exe [owner-execute: true]]
    call "program.exe args..."

The SET-MODES is needed for Unix-like systems such as Linux, BSD, Solaris, HP-UX, etc.

#074Where can I find a list of recent changes to REBOL?
 

The list of changes can be found at this location. This document will also provide you with the location of new beta test versions.

#059How do I keep REBOL from failing because of an error in my script?
 

User the TRY function. TRY will catch errors and return the error as a result.

    if not error? try [do it] [print "done"]

In fact, this form is so common that the ATTEMPT function was created as a shortcut:

    if attempt [do it] [print "done"]

    block: any [
        attempt [load %file.r]
        copy [1 2 3]
    ]

Evaluating an error caught with TRY will produce the error unless it is first disarmed with DISARM. DISARM creates an error object from a "live" error. The following example shows how to catch an error and print the disarmed error object:

    if error? err: try [
        do it
    ][
        probe disarm :err
    ]

#070What's the history of this FAQ?
 

This FAQ was originally created by REBOL Technologies' Jeff Kreis several years ago. Additional information was provided by the REBOL staff. Recently, the FAQ was converted into a REBOL database that gets processed and updated using REBOL. This approach allows us to update the FAQ more frequently.

#080How do I change the font attributes, like the color, for a single text face without affecting all of them?
 

To change the font attributes, create a new font object, then set the field of the face you want to change. You can use the same FONT object for as many FACES as you need.

Here is an example that changes the font for a line of text:

    out: layout [
        style button button 200 ;wide buttons by default

        tf1: text 200x30 "This is a field of text"

        button "Make it Red" [
            tf1/font: red-font
            show tf1
        ]
        button "Make it Bold and Navy" [
            tf1/font: navy-font
            show tf1
        ]
        button "Make it Large" [
            tf1/font: large-font
            show tf1
        ]
        button "Show font fields" [
            probe red-font
        ]
    ]

    red-font: make tf1/font [
        color: red
        style: none
    ]

    navy-font: make tf1/font [
        color: navy
        style: 'bold
    ]

    large-font: make tf1/font [
        size: 18
    ]

    view out

Above, the font attribute objects are inherited from above TF1 default font. Of course, this can also be done dynamically within the button code above. But the static method is more efficient, if you have the same attributes each time.

#008How do I connect REBOL to a database?
 

You need REBOL/Command. It provides ODBC and direct database connectivity.

#002How are filenames written within REBOL code and data?
 

Within REBOL code, filenames begin with a percent sign to distinguish them from other words. Here are some examples:

    %/Volume/Directory/File - subdirectory
    %/path - root of current volume
    %//path - root of system
    %path - relative file (based on the current directory)
    %../path - up one level from the current directory
    %. - current directory

If the file path starts with a slash, it is the root directory. If it doesn't, it is a subdirectory of the current path.

#003What high level directory operations are available?
 

The directory functions are WHAT-DIR, CHANGE-DIR, LIST-DIR, and MAKE-DIR.

Lower-level functions that operate on directories are READ, DELETE, QUERY, INFO?, RENAME, and MODIFIED?.

The current directory is seen by entering: WHAT-DIR

The directory REBOL is currently using can be changed using: CHANGE-DIR

To see all the files in the current directory use: LIST-DIR %./

To see a list of all the volumes available on your system, use: LIST-DIR %/

It is important to end directories with a slash.

#005How do I SEEK on a file so I don't have to read the entire file?
 

Open the file with OPEN/BINARY/DIRECT and use SKIP to go to the selected offset:

    file: open/binary/direct %myfile.txt
    skip file 2000
    data: copy/part file 80

The above skips the first 2000 bytes of the file and then copies 80 bytes starting from that location into DATA.

#006There is no /BINARY refinement available for PRINT. How do I output a binary value to stdout?
 

The REBOL console is a port, so it is actually very simple to output a binary file:

    data: read/binary %imagefile.jpg
    write-io system/ports/output data length? data

#007How can I read line-by-line from a file larger than my available memory?
 

Open the file as a port using OPEN with the /DIRECT/LINES refinements:

    file-port: open/direct/lines %file

Then access the file one line at a time with:

    line: first file-port

Each FIRST on FILE-PORT will return the next line from the file.

#010How do I change a url-encoded string back to its normal human-readable characters?
 

If what you have is a url datatype with url encoded characters you can just use TO-STRING (which is short for MAKE STRING!). If it is a string that has URL-encoded characters, see the cgidecode.r script in the script library on REBOL's website for an example.

#011When REBOL is started with --cgi, should system/ports/output be opened with CR-LF as the default line ending?
 

At present it uses the local operating system default. For example, on Unix it's just LF. On windows it's CRLF.

#012How do I use CGI POST with REBOL?
 

A REBOL CGI script can find HTTP post data in system/ports/input.

HTML page

    <HTML><FORM ACTION="testpost.r" METHOD="POST">
    <INPUT type="text" name="name" size=20 maxlength=20>
    <INPUT type="submit" value="OK">
    </HTML>

REBOL CGI page (testpost.r)

    #!/path/to/rebol -c

    REBOL [Title: "Print POST Data"]

    ;- Always print this line first
    print ["Content-type: text/html" newline newline]

    post-data: copy system/ports/input
    print [<HTML><PRE> post-data </PRE></HTML>]
    quit

END of REBOL CGI page

There is more information in the CGI section of the How-To page on REBOL's website.

You can also send POST data from REBOL to a webserver. This is done by adding the /CUSTOM refinement to your READ:

    result: read/custom http://www.example.com [post "data goes here"]

The data can also be a binary REBOL string.

#013I am trying to use the flags -c -s on the first line of my CGI script using Apache. I get a bunch of extra stuff output. Why?
 

Trying using -cs instead of -c -s. Some shells limit the number of flags.

#014Why don't some series functions work on ports?
 

A port is an abstraction of a streaming data source. The abstraction allows it to be treated as a series, however, some series operations do not always make sense with a stream data source.

#015How do I set up my proxy settings?
 

To specify a Proxy Server:

If you use a firewall with a proxy server, you can specify its settings:

    set-net [
       user@domain.dom
       mail.server.dom
       pop.server.dom
       proxy.server.dom
       1080
       socks-type
    ]

where socks-type is one of the following:

    socks   -- most recent version of SOCKS supported (currently SOCKS5)
    socks4  -- SOCKS4 compatibility
    socks5  -- SOCKS5 compatibility
    generic -- generic proxy support (i.e. Squid, CERN)

A common way to determine the proxy type is to check your web browser settings. SOCKS has its own field while generic proxies have settings specifically for HTTP, FTP, etc. in the browser preferences box.

#016Is it possible to get the last-modified date of a web page via REBOL?
 

Yes, use the MODIFIED? function, e.g.:

    modified? http://www.REBOL.com
    connecting to: www.REBOL.com
    == 11-Oct-2000/3:30:46

The problem is that often web servers won't tell you the modification date and many web pages are dynamically generated. MODIFIED? will return NONE in those cases. Your mileage may vary.

#017Does REBOL networking support appending to and restarting downloads from some arbitrary point?
 

REBOL's networking supports both appends and restarts on all networking that can be accessed via READ. Here is an example of appending to a previously written file:

    write/append ftp://some.site data

To restart a download from some particular point, use READ/SKIP to designate what point to start downloading from:

    data: read/skip ftp://some.site/some-file 156'384

The above will start reading some-file at the 156,385th byte.

#018Sometimes REBOL has a network timeout error. How can I increase the network timeout value?
 

Setting:

    system/schemes/default/timeout: 0:10

will set a ten minute timeout for all protocols. If you want to set a specific protocol, such as FTP, put that in place of the default.

    system/schemes/ftp/timeout: 0:10

#019How can I get started writing a protocol in REBOL?
 

Have a look at the port code within REBOL. The following will print all of the protocols out:

    foreach scheme next first system/schemes [
        print mold get in system/schemes scheme
    ]

Also have a look at: SOURCE SEND and SOURCE NET-UTILS

You can also save the source of a specific protocol in the following way:

    save %ftp.r system/schemes/ftp/handler

#020What is the SUB-PORT in the port object hierarchy?
 

The sub-port is where the actual TCP port for the protocol is stored. TCP ports, because they are lower level, don't have any default values. Instead, the values must be explicitly set from the protocol.

#021Inside the port code, I see some functions, such as OPEN and INSERT written with fully qualified paths to SYSTEM/WORDS. Is this a context thing?
 

The way a port-handler written in REBOL works is to contain functions that map onto the native actions applied to the port. Thus, one function in the port is the OPEN function. Because the OPEN function needs to open a TCP port, it must use system/words/open to avoid recursively calling itself.

#022How can I pick several characters at once from a port without using OPEN/LINES?
 

You can use copy/part to pick several characters at once.

#023I am getting an error about LENGTH? PORT/PROXY/USER
 

The above error message generally means you are going through a proxy which requires authentication but the proxy username and password is not set. Here is how to set the default proxy username and password:

    system/schemes/default/proxy/user: "my-username"
    system/schemes/default/proxy/pass: "my-password"

The above can be included into your user.r file so it is executed each time you start REBOL.

The "default" in the paths above can be replaced with any of the following if the authentication is only required for specific protocols:

    finger whois daytime smtp pop http ftp nntp

Unfortunately, if your access is through a generic proxy the above solution may not work.

#024Can I use REBOL to send email through Hotmail?
 

Hotmail is a web-based email provider. They use secure sockets to transfer the mail to your browser.

REBOL handles email via the SMTP and POP protocols, not HTTP.

#025Can REBOL do SSL or HTTPS?
 

Yes secure client-side SSL and HTTPS is supported by REBOL/Command. (Server-side HTTPS is normally supported by your web server.)

#026I need special characters in the username or password part of URLs. How do I do that?
 

In REBOL, URL's are parsed into a PORT spec object. If you have special requirements, you can open the port using such an object. Here is an example of opening a POP port in an alternate way. The line:

    mailbox: open pop://login:passwd@emailserver.com

Can also be written as:

    mailbox: open [
        scheme: 'pop
        user: "login"
        pass: "passwd"
        host: "emailserver.com"
    ]

POP can then be accessed just as if it were opened using the one-line method.

#027Is UDP supported?
 

Yes. UDP ports are created in the same way as TCP ports. Example:

    udp-listen-port: open udp://:port-number
    udp-talk-port:   open udp://host:port-number

#028How do I find out what words are defined in the system?
 

Use the function: WHAT

#029I notice when I try to assign the return value of WHAT or HELP I get an error message instead. Why?
 

WHAT and HELP do not return a value to REBOL. To capture these, you could do the following:

    echo %what.txt  what  echo none

The function ECHO writes to a file everything that is printed to the console until it is turned off with ECHO NONE.

#030What if I want to write a function that does the same thing as WHAT but returns a value?
 

REBOL allows the user to see the source code of all non-native functions. Use the function SOURCE to see the code for WHAT and modify it as needed: SOURCE WHAT

#031What is in the system object?
 

The guts of REBOL.

The system object really is REBOL/Core's object. It serves as a reference point for the language. We make it visible, but we could also make it inaccessible. Play with it at your own risk.

    version    -- version number of the REBOL build you're running
    build      -- date and time the current executable was built
    product    -- product name (i.e. REBOL/Core, REBOL/View, REBOL/Command)
    components -- various build-time components included in the executable
    words      -- names of all the words defined in REBOL, including
                  words that you define
    license    -- REBOL's license agreement text
    options    -- various options and information about scripts
                  the cgi content-length and query-strings are both
                  under options/cgi
    user       -- settings for user email address, real name and other info
    script     -- settings related to the script last evaluated
    console    -- settings for the console
    ports      -- storage for the raw console ports
    network    -- host-name and host-address of the user's machine
    schemes    -- various network ports of REBOL are stored here along
                  with network port default values such as timeout
    error      -- error catalog
    standard   -- standard objects for later derivation (i.e. port
                  structure and email headers)
    view       -- settings specific to REBOL/View
    stats      -- information on current memory usage
    locale     -- settings for foreign languages

#032REBOL won't find my %user.r file. Why?
 

REBOL will by default look for the %user.r file in the directory where it was started. However, setting the environment variable REBOL_HOME allows you to specify a directory for REBOL to look for your user.r file.

#033What are the basics of PARSE?
 

Here are a few helpful notes on PARSE.

1. PARSE uses it's own dialect, which in REBOL lingo means that it can have its own grammar and vocabulary. So, don't make any assumptions about any words that you see in a PARSE block because they live in a separate context and work differently. The great power and leverage of PARSE comes from this very fact, and that's why dialects are the future.

2. Basic elements are:

    [block]  - a sub-rule to PARSE
    "string" - attempt to match the string to the input
    #"c"     - attempt to match a single character to the input
    <tag>    - match tag to the input
    (paren)  - evaluate a REBOL expression
    12       - repeat the pattern 12 times
    1 12     - repeat pattern at least 1 but no more than 12.
    word     - look-up word in REBOL, it can be a number,
               string, block, and PARSE will recognize it.
               HOWEVER, PARSE also has keywords that are special.
    word:    - mark the current input series position in word
    :word    - set the current input series position from word
    bitset   - match any specified char in the set (more later)

3. The vocabulary (words) of PARSE is:

    |    - specify alternate rule (recovering input stream)
    none - make previous rule optional
    skip - skip any character (or chars if repeat given)
    to   - advance input to the given string (or char)
    thru - advance input thru the given string (or char)
    some - one or more of something
    end  - match against the end or to end
    copy - copy the next match sequence to a word

Here is an example of PARSE in action:

    digit: charset "0123456789"
    expr: [term ["+" | "-"] expr | term]
    term: [factor ["*" | "/"] term | factor]
    factor: [primary "**" factor | primary]
    primary: [value | "(" expr ")"]
    value: [digit value | digit]

    parse "1 + 2 ** 9" expr
    == true
    parse "math expression?" expr
    == false

The above PARSE code determines if a given string contains a valid mathematical expression.

For more information on PARSE, see the REBOL/Core User's Guide which can be downloaded from the REBOL company website.

#034What formats of binary numbers are supported?
 

REBOL actually supports binary STRINGS. Of them, Base-2 (binary), base-16 (hexadecimal), and base-64 strings are possible.

You can convert these strings to integers, for instance:

    10 = to-integer 64#{AAAK} =  to-integer 16#{0A} = to-integer 2#{0000 1010}

You can turn an integer into a hexadecimal string with the TO-HEX function.

Integer (base-10) to binary is currently supported up to 32-bit signed numbers. The range is from -2147483647 to +2147483647.

Hex binaries must have an even number of digits, base-64 must have a multiple of 4 digits and base-2 must have a multiple of 8 digits.

The binary datatype was included to assist in working with compressed data, image data (such as JPEGs), executables, etc.

The default binary output format can be set in system/options/binary-base. Valid values are 2 (binary), 16 (hexadecimal) and 64 (base-64).

#035What IS a series?
 

A series is a collection of one or more elements that can be ordered so you can get the FIRST element, the SECOND element, PICK the forty-second element, get the LAST element, etc...

The essential characteristics of a series are that it contains a set of values that are organized in a particular order.

#036How do I make an array?
 

Arrays are the same as blocks. Most of the time in REBOL you don't need to use arrays (as done in BASIC and C). Blocks are better because they automaticaly expand.

However, we provide the ARRAY function as a shortcut for initializing blocks used as arrays.

This creates an array foo which is 10 x 10. All the initial values will be set to none:

    foo: array [10 10]

Use the /INITIAL refinement to specify an initial value:

    foo: array/initial [10 10 10] 42

Elements of the array can be accessed by paths. The following would return the element in the fifth column and fifth row, at a depth of five:

    foo/5/5/5

This would set that same element to 13.

    foo/5/5/5: 13

#037How do I save a filename with spaces in it?
 

Use quote marks around the filename like this:

    save %"a file with spaces" data

or

    save to-file "a file with spaces" data

While most modern operating systems can store filenames with spaces, not all of them can handle much punctuation, so go easy on the punctuation in filenames or you may make your script less portable.

#038Are there any advantages to using lists verses blocks?
 

The advantages become more obvious with large lists when doing inserts or removes. On a large block, all the data gets shuffled doing an insert at the head. On a list, existing data is never moved. This means that lists take more space than blocks as there is a linked list associated with the data. However, the speed advantages are significant. Here's an example:

    >> blk: make block! 20000
    == []
    >> t: now/time loop 20000 [ insert head blk 1 ] now/time - t
    == 0:00:35
    >> lst: make list! 20000
    == make list! []
    >>  t: now/time loop 20000 [ insert head lst 1 ] now/time - t
    == 0:00

NOTE: The time for BLK is not linear with the number of iterations because the amount of data that must be moved with each insert becomes larger and larger.

#039What do I use a HASH! for?
 

Hashes are good for data that you are going to perform many searches on. Hashes are one of the fastest data structures for search and retrieval. REBOL hashes can also be sorted using the SORT function.

#040I can't seem to find any way to do a substring.
 

To extract a substring in a way similar to many other languages, you could write the following function:

    substr: func [string start length][
        copy/part at string start length
    ]

    substr "Hello" 2 3
    == "ell"

    substr "REBOL is cool" 5 4
    == "L is"

The above example works because first the index of the string is moved to the start point (using the word AT) and then the function uses COPY/PART to copy from there to some index past that point.

#041I noticed REBOL has built-in compression. How do I use it?
 

Use the functions COMPRESS and DECOMPRESS. COMPRESS converts a string into a compressed binary, and DECOMPRESS takes a compressed binary and returns the original string. The COMPRESS function is comparable to ZIP or LHA in efficiency.

    data: compress "A string"

    data: compress read %file.txt

    data: compress read http://www.rebol.com

    string: decompress data

    print string

#042Why doesn't REBOL have an ELSE statement?
 

EITHER and IF/ELSE in REBOL parallel the functionality of the ELSE statement in other languages.

REBOL had an ELSE statement in the alpha versions, but ELSE complicated the language because the else had to be searched for each time an IF was encountered.

The syntax for EITHER is:

    either condition [true-block][false-block]

EITHER returns the value of the block it evaluates. IF/ELSE can be used in place of EITHER in the above example.

#044What does the /LOCAL refinement in the function argument list do?
 

Everything that follows the /LOCAL refinement is a local variable.

    f: func [arg /local data] [
        data: join "DATA" arg
    ]

#045How do I find out about a particular function of the system?
 

Use the HELP and SOURCE functions.

#046How does the /COMPARE refinement work with the SORT function?
 

Use the /COMPARE refinement to provide a function that performs the comparison between two different elements:

    sort/compare ["a" "B" "c"] func [a b][b < a]

would perform the reverse sort than the default.

#047What do things like [string!] and [any-block!] in a function specification block mean?
 

Function arguments followed by one or more datatype identifiers in a block denote a specific constraint on that argument to a function. For instance, the following header:

    some-func: func [value [money!]] [...]

means SOME-FUNC takes one argument assigned to VALUE. The function will return an error if it is supplied an argument other than a money type.

See the REBOL/Core User's Guide Functions chapter for more.

#048If a series that is being traversed by FOREACH, FORALL, or FORSKIP is modified during execution of the traversal, do the modifications apply to the traversal?
 

Yes. FOREACH, FORALL and FORSKIP use an updated version of the series argument each iteration through. Example:

    series: [1 2 3 4 5]
    foreach item series [
        print item
        remove back tail series
    ]

The above example will print the numbers 1 through 3 and the modified series will be [1 2].

FORALL and FORSKIP do the same thing:

    series: [1 2 3 4 5]
    forall series [
        print first series
        remove back tail series
    ]
    series: head series

#049Any plans to support IMAP?
 

Yes. IMAP is currently supported.

#050Will ICMP be supported?
 

No. It requires root access on unix systems. However, using REBOL/Command you can call a DLL that supports it.

#051Can REBOL launch other programs?
 

Yes. However, launching other programs breaks the language portability. Therefore, REBOL/Core (which is intended to be as cross-platform compatible as possible) doesn't support launching other programs while REBOL/Command fully supports it. REBOL/View supports launching additional REBOL/View instances as well as the system default web browser.

#052What do the REBOL version numbers mean?
 

The format is:

    version . revision . release . system . variation

For example:

    2.5.4.3.1

tells us that it's version 2, revision 5, release 4, for windows, running NT, 2000, XP, 98, 95.

The system and variation numbers can be used by scripts to determine what OS and processor they are running on.

#053How do I refer to a global word if it has been redefined locally?
 

You can set the global to a different word outside the local context:

    sys-print: :print

Now you can use sys-print.

    f: func [print [string!]][
        sys-print print
    ]

You can also use a fully qualified path to the word in system/words:

    f: func [print [string!]][
        system/words/print print
    ]

The word PRINT is used as an argument that makes it local to the function. To get the original PRINT function you specify a path to its global definition in the system object.

This second method does not execute as fast as the first method.

#054How does BIND work?
 

BIND takes a block of words and BINDs them into the current context. It takes a word from the context you want to BIND to as its second argument. Try playing with this example:

    REBOL [
        Title: "BIND Demo"
    ]

    global: on
    x: 1  y: 2  z: 3
    local-context: func [/local context][
        use [x y z ] [set [x y z] [a b c] print bind [x y z] 'context]
    ]
    global-context: func [][
        use [x y z] [set [x y z] [a b c] print bind [x y z] 'global]
    ]
    local-context global-context halt

LOCAL-CONTEXT prints a b c

GLOBAL-CONTEXT prints 1 2 3

LOCAL-CONTEXT'S BIND is actually redundant. GLOBAL-CONTEXT's BIND uses the word 'global to cause the values of X Y and Z be set to their values where the word 'global is defined, which happens to be out in the global context.

You may also BIND to other contexts besides the global context.

#055Can I use REBOL with XML?
 

REBOL has a built-in XML parser for simple types of XML strings. In addition, various REBOL users have implemented XML-RPC. Using REBOL/Command, external XML parsers can be called via the dynamic library loading capability.

#056How does REBOL evaluation work?
 

Evaluation is left to right, though application is right to left.

If you have:

    word1 word2 word3

Word1 is evaluated, then word2, then word3.

However, if word1 is a function with one argument then word2 is evaluated before it is passed to word1. Similarly with word2 to word3. If word1 is a function that takes two arguments then word2 and word3 must both be sequentially evaluated, but in this case from right to left before being passed into word1. Thus application is right to left.

If instead you have:

    do word1 word2 word3

and word1 creates and returns a function that takes two arguments, word2 and word3 will be evaluated before being passed into the anonymous function that is returned from word1.

This causes an error:

    if length? "zappo" < 22 [do something]

Parentheses are necessary around LENGTH? and "zappo" because the evaluation simply moves along from left to right. IF is evaluated. It requires a condition argument and a block to DO if the condition is true, so it sees LENGTH? and LENGTH? tries to evaluate. Now there is a small complication here in the fact that the infix < operator is actually seen as the argument to LENGTH? (just swap it in front of "zappo" mentally) so it has to be evaluated, and it tries to determine less-than between its two apparent arguments "zappo" and 22 which is an error.

To see it clearly try:

   x: func [y][print [mold y type? y]]

   x 2 < 3
   ==
   true logic

It did not print "2 number".

Consequently, it turns out with all the evaluation proceeding simply left to right that parentheses are actually less necessary more of the time than in languages with full hierarchies of precedence rules. For instance, in C and C++ people tend to (wisely) parenthesize expressions because they aren't always sure if a cast has a higher precedence than a bit wise xor etc.. In REBOL/Core you only have to remember left --> right.

#057How do I DO another script and pass it arguments?
 

Say you want to pass the number 101 to the file %dalmations.r:

    do/args %dalmations.r 101

In the script called %dalmations.r, the argument can be accessed as follows:

    print ["We have" system/script/args "dalmation(s)!"]

#060How do I pass REBOL arguments from the command line?
 

To pass arguments into a script when launching REBOL from the command line, do the following:

    commandline> rebol %some-script.r 54321 Launch!

Assuming %some-script.r is written as follows:

    REBOL [
        Title:  "Command-Line Argument Example"
    ]

    print mold system/options/args
    print mold system/script/args

The following will be output

    ["54321" "Launch!"]
    "54321 Launch!"

As the Macintosh OS doesn't have a native command line, command-line arguments do not apply to the Mac.

#061When I try to run REBOL on my BSD machine, I get an error message stating "incompatible binary format". Why?
 

REBOL for BSD is compiled with the newer ELF binary format while many older systems still expect the a.out format. To use REBOL, the BSD installation will need to be upgraded to support ELF.

#062I am running on a unix-like operating system where the REBOL distribution has the extension .tar.gz. How do I decompress it?
 

On most systems, at least one of these sequences could be used:

    1.  tar xvfz rebolxx.tar.gz

    2.  gzip -d rebolxx.tar.gz
        tar xvf rebolxx.tar

#063REBOL fails on AIX with a message about libtermcap. Why?
 

It appears your AIX installation does not have the fileset bos.compat.termcap installed. Install the aforementioned fileset to run REBOL. We use libtermcap. However, we are finding some systems do not have a libtermcap-compatible library installed.

#064When I try to start REBOL, it says there is a problem with libcurses.
 

Libcurses is a library which is found on almost every posix-compliant platform. The solution is to install libcurses on the system.

Some platforms do not include Libcurses in older versions (like Solaris which added libcurses with versions later than 5.6), in which case you will have to add the library.

Consult your system administrator for assistance if needed.

#065How do I install REBOL on my web provider's computer?
 

Find out what hardware/operating system they are using, download the correct version of REBOL and copy it into your CGI directory on that machine. If you want to have external network access from REBOL on that system, you may also have to set up your user.r file and copy that over to the CGI directory as well.

#066On a multi-user system, do I have to install REBOL system-wide or can I install it on an individual domain?
 

You can install REBOL system-wide and use the REBOL_HOME environment variable to set each user's individual script directory, or you can install REBOL in any domain and have it useable in only that domain.

#067When I try to run REBOL on my Mac68K, it says I don't have enough memory. Why?
 

On older Macs there was no way to dynamically allocate memory to a running program so the user had to define the amount of memory to allocate in advance. The allocation amount can be changed in the icon configuration. It is set to 10MB by default.

About | Contact | Support | Privacy | LicenseREBOL Technologies 2010