Hi RChristiansen,

1. The load function returns a block containing whatever is in the file.
When you load an object, you get a block that looks something like this:

[ make object! [some-word: some-value some-other-word: some-other-value ...] ]

This block consists of two words: make and object!, and an unrelated block
of set-words and values.

The contents of the block must be converted into an object and extracted
from the block.

You have two choices:

1. Using do

If you do the block, the contents of the block are evaluated, REBOL
identifies its contents as an expression that creates an object, and
creates and returns the created object.

object: do load %object.txt

2. Using reduce
If you have a file that contains several objects, you have the option of
using reduce. The reduce function also evaluates the expressions contained
in the block. In contrast to do it returns a block containing the evaluated
expressions. The three elements, word make, word object!, block
[ make object! [some-word: some-value some-other-word: some-other-value ...] ]

are evaluated and what is returned by reduce is a block containing an object:

[ make object! [some-word: some-value some-other-word: some-other-value ...] ]

Here:
>> loaded-block: [ make object! [some-word: "some-value" some-other-word:
"some-other-value"] ]
== [make object! [some-word: "some-value" some-other-word:
"some-other-value"]]
>> length? loaded-block
== 3
>> first loaded-block
== make
>> second loaded-block
== object!
>> third loaded-block
== [some-word: "some-value" some-other-word: "some-other-value"]
>> reduce loaded-block
== [
    make object! [
        some-word: "some-value"
        some-other-word: "some-other-value"
    ]]
>> length? reduce loaded-block
== 1
>> first  reduce loaded-block
>> print mold first  reduce loaded-block

make object! [
    some-word: "some-value"
    some-other-word: "some-other-value"
]

3. I hope you don't mind a few other comments:

To retrieve a directory listing, you can use the simple expression 
load %file-system-path

In your case:

absolute-path: %/absolute/path/articles/

foreach file load absolute-path [
  if not dir? file [
    article: do load join absolute-path file
    print article/headline
    print articel/subheadline
  ]
]

The line 
if not dir? file
is only necessary if absolute-path could contain subdirectories.

Hope this helps


;- Elan >> [: - )]

Reply via email to