functiondialect binds all set-words to a new inner context.
'valueis local to the loop.
I am working on having a single function with different arguments length depending on the "method" of the function.
alter-db 'add-rows ["db-name" "table-name" [column1 column2 column3]] alter-db 'remove-table ["db-name" "table-name"]
alter-db has different number of arguments depending on the method used
Inside alter-db I have a block which specifies the words of the arguments
Alter-DB is defined as
Alter-DB: function [ method arg-block ] [ fnc-args: [ 'add [db table rows] 'remove-table [db table] ] ]
I want to associate each word in a method i.e. 'ADD has -db table rows-
To the corresponding word in arg-block
What if I use a global function like:
set-args: function [my-args arg-words] [ set select my-args method arg-words ..... ]
and call it from the inside of
set-args fnc-args arg-block
After selecting them ?
How do I bind words to the calling function ?
setdoesn't deal with binding... that's the magic, it just uses the word's binding (remember that all
any-word!types store their binding internally)
Yes @moliad but first/second/third or obj/1 ../2 /3 is a method you could apply to object content. In fact in rebol you could use it on the third element of an object. (i.e.: probe first third obj)
The key distinction here is intended use. Maps and objects are based on unorderd key-value slots, blocks are based on ordered slots. This is an important distinction. While this is not laid out in a design spec, it tells you that it is safe to use blocks based on their order, but that it's not safe to do so with maps and objects. That is, a block will always return values in the same order, but a different implementation of map/object might change the internal order of things, and return them in a different order in response to words-of/values-of.
foreach, as @nedzadarek showed, it is special, along with
repeat, If you use
function rather than
_function/collect-deep are responsible for that special handling.
This is a workaround for now, but a fairly effective one in most cases. Not perfect, but better than nothing.
_functionis the context name in the