You could do something like that now with the PORT! datatype, though awkwardly. The port actors return whatever you want them to:
my-sound: make port! [
scheme: 'simple-sound
[data1] [data2] [data3] ...
]
; in Rebol 3, the only requirement creating a port with a block
; is that it begin [scheme: 'scheme-name ...], can be followed
; by any data sequence accessible to INIT/actors via
; PORT/SPEC/REF
length-of my-sound
; == whatever your 'length-of actor returns
sound-suite/play my-sound
; can check: port? my-sound; my-sound/scheme = 'simple-sound
One of the reasons I think PORT! is misunderstood is that this type of usage isn't really 'port' in the traditional sense of an interface between systems, I'd suggest this falls under the traditional conception of Rebol objects which I think could be improved upon. Hence...
This sort of comports to the Javascript object model and is the intent behind my Class proposal. The efficiency in this model is that functions are not copied from the prototype to the kids, nor are default values—the kids only contain values where they deviate from the prototype. On further consideration, I would likely add verb actors to the Class model and possibly methods of handling iteration that it can be traversed by the *-EACH functions.
As an aside, Javascript objects (including arrays) are entirely built on associative arrays (MAP!) with string keys, there's no binding (the value of THIS within a function is determined by how it is called and can be overridden by .APPLY()/.CALL()). A path myobject.thing
is shorthand for myobject['thing']
, similarly myarray[0]
is shorthand for myarray['0']
; if myobject
has no 'thing'
key, JS will keep looking up the prototype chain until it reaches Object.prototype
(which is where, e.g. apply/call
live) and will return undefined
if it's not found. In this way it avoids Rebol OBJECT! needing every key in each kid, and instanceof
gives you some assurance that your object value has the requisite set of method (there's no equivalent of this in Rebol objects, slight equivalent in Rebol ports—value/scheme = 'myscheme
).