Example of a minimal module
Ok, you've heard about REBOL modules, and we've made a lot of changes recently... but, you're not really sure how to make one. Here's an example. It's very simple.
First, create a module file. This one is saved as simple.reb:
REBOL [
title: "Simple module"
type: module
]
export num: 1234
export sum: func ["Example" val] [val + num]
Notice it look like a normal script, but we specify the type module and the word export is used to indicate exported words.
Now, in your program, you can either import the module:
import %simple.reb
Or, another way is to specify it in the header of your program:
REBOL [
title: "Main program"
needs: %simple.reb
]
Then you can easily access the exported functions and data of the module:
print num
1234
sum 1000
2234
Of course, this is just scratching the surface of what modules can do. But, I wanted to start with a simple example to show how easy it is to get going. It's that easy.
2 Comments
|