tags:

views:

111

answers:

1

Let's say I have a REBOL script in another file (imported.r) that looks like this:

REBOL [
    author: {Greg}
    title: {Awesome REBOL Code}
]
x: 3

How can I import this file into another script and gain access to the contents of the REBOL header? I'm aware of load/header but I can't seem to do anything with it.

imported: context load/header %imported.r

What do I do now to access the header of imported.r as an object!?

+2  A: 

LOAD/HEADER gives you a block of code, as you can see by PROBEing what it returns. It contains the unevaluated source for building a header object followed by the rest of the script.

To MAKE an OBJECT! from that header code, one way is to

>> set [header script] do/next load/header %imported.r
>> header/title 
== "Some script title"

or, if you only need the header object, just

>> header: first do/next load/header %imported.r
>> header/title 
== "Some script title"

This gives you object access via HEADER and the scripts code in the SCRIPT block, as DO/NEXT evaluates only the first expression and returns the result of the expression and the position in the code block after that evaluation.

Christian Ensel
You can also do -- script: load/header %imported.r header: take script
rgchris