REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Scripts: Loading Scripts

Pending Revision

This document was written for R2 and has yet to be revised for R3.

Script files can be loaded as data with the load function. This function reads the script and translates the script into values, words, and blocks, but does not evaluate the script. The result of the load function is a block, unless only a single value was loaded, then that value is returned.

The script argument to the load function is a file name, URL, or a string.

load %script.r
load %datafile.txt
load http://www.rebol.org/script.r
load "print now"

The load function performs the following steps:

For example, if a script file buy.r contained the text:

Buy 100 shares at $20.00 per share

it could be loaded with the line:

data: load %buy.r

which would result in a block:

probe data
[Buy 100 shares at $20.00 per share]

It should be noted that the "Buy" example above is a dialect of REBOL, not directly executable code. See Chapter 4 on Expressions or Chapter 15 on Parsing for more information.

Note that a file does not require a header to be loaded. The header is necessary only if the file is to be run as a script.

The load function supports a few refinements. The load Function Refinements lists the refinements and a description of their functionality:

/headerIncludes the header if present.
/nextLoads only the next value, one value at a time. This is useful for parsing REBOL scripts.
/markupTreats the file as an HTML or XML file and returns a block that holds its tags and text.

Normally, load does not return the header from the script. But, if the /header refinement is used the returned block contains the header object as its first argument.

The /next refinement loads the next value and returns a block containing two values. The first returned value is the next value from the series. The second returned value is the string position immediately following the last item loaded.

The /markup refinement loads HTML and XML data as a block of tags and strings. All tags are tag data types. All other data are treated as strings.

If the following file contents where loaded with load/markup:

<title>This is an example</title>

a block would be produced:

probe data
[<title> "This is an example" </title>]


  TOC < Back Next > REBOL.com - WIP Wiki Feedback Admin