REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: bind

bind  words  context  /copy  /only  /new  /set

Binds words to the specified context. (Modifies)

Arguments:

words [block! any-word!] - A block of words or single word (returned)

context [any-word! any-object!] - A reference to the target context

Refinements:

/copy - Deep copy block before binding it

/only - Bind only first block (not deep)

/new - Add to context any new words found

/set - Add to context any new set-words found

See also:

bind?   use   do   func   function   does   make   import  

Description

Binds meaning to words in a block. That is, it gives words a context in which they can be interpreted. This allows blocks to be exchanged between different contexts, which permits their words to be understood. For instance a function may want to treat words in a global database as being local to that function.

The second argument to bind is a word from the context in which the block is to be bound. Normally, this is a word from the local context (e.g. one of the function arguments), but it can be a word from any context within the system.

bind will modify the block it is given. To avoid that, use the /copy refinement. It will create a new block that is returned as the result.

words: [a b c]
fun: func [a b c][print bind words 'a]
fun 1 2 3
fun "hi" "there" "fred"
hi there fred
words: [a b c]
object: make object! [
    a: 1
    b: 2
    c: 3
    prove: func [] [print bind words 'a]
]
object/prove
1 2 3
settings: [start + duration]
schedule: function [start] [duration] [
    duration: 1:00
    do bind settings 'start
]
print schedule 10:30
11:30

Editor note: Describe /new here

Editor note: Describe /set here


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