Changes in MAKE function!

Carl Sassenrath, CTO
REBOL Technologies
27-Jun-2007 16:15 GMT

Article #0093
Main page || Index || Prior Article [0092] || Next Article [0094] || 9 Comments || Send feedback

As you know, the datatype creator make accepts a datatype specifier or a prototype:

s: make string! 123
t: "abc"
s: make t 123

It is most useful in the case of objects:

ob1: make object! [a: 10]
ob2: make ob1 [b: 20]
print ob2
a: 10
b: 20

During R3 testing, this was listed as a bug:

f1: func [a] [print a]
f2: make :f1 []

That expression would read: make f2 using f1 as the prototype.


To make that work, it had to be defined. Here it is the definition...

First, recognize that in R3 the general constructor is:

f: make function [ [spec] [body] ]

Just use source on func to see such details.

So, now you know the format for make function prototype. It is the same.

f2: make :f1 []  ; just copy the function
f3: make :f1 [[body]] ; keep spec the same, use new body
f4: make :f1 [[spec][body]] ; replace spec and body

The f3 case is the most useful. It lets you "inherit" the function specification (e.g. argument list), but redefine the body of the function. F2 and f4 cases are just for completion of the form.

As a trivial example:

mo-string: make :to-string [[mold value]]


An additional note: you can also use copy now, instead of the f2 case above.

f5: copy :f1

Note that all parts are deep copied and rebound to the new function context.


Updated 13-Jun-2024 - Edit - Copyright REBOL Technologies -