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

REBOL 3 Functions: resolve

resolve  target  source  /only  from  /all

Copy context by setting values in the target from those in the source.

Arguments:

target [any-object!]

source [any-object!]

Refinements:

/only

from [block! integer!] - Only specific words (exports) or new words in target (index to tail)

/all - Set all words, even those in the target that already have a value

Contents

Description

The resolve function is used to merge values from one context into another but avoids replacing existing values.

It is used mainly to support runtime environments, where newly exported functions must be merged into an existing lib context. Because lib can become quite large, performance must be optimized, which is the reason why resolve is a native function.

Basic Concept

This example will help to show the basic concept:

obj1: object [a: 10]
obj2: object [b: 20]
append obj1 'b
resolve obj1 obj2
print obj1
a: 10
b: 20

But notice:

obj1: object [a: 10]
obj2: object [a: 30 b: 20]
append obj1 'b
resolve obj1 obj2
print obj1
a: 10
b: 20

So, resolve has no affect on values that have already been set in the target context.

Note that protected words will not be modified, they are ignored. No error occurs.

Refinements

/onlyonly affect word values that are provided in a block argument that follows this refinement. In addition, this refinement also supports a special optimization where you can indicate the index of the starting point for changes. That is useful with large contexts such as lib and others.
/allforces resolve to change all values, not just those that are unset. This is similar to append on an object! except that the source is an object, not a block.
/extendany words not found in the target context will be added. This eliminates the append step that was shown above (or a similar bind step). This refinement optimizes such operations.


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