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
set-word!local (adds it to the
f: function [a: 1] ; == func [/local a][a: 1])
foo: 42) won't make a word local (
f: function  [set 'a 1] ; == func [set 'a 1]<-
functioncollect that word (wrong - to be more precise) ->
f: function  [foreach w [1 2 3][ print w]] ;== func [/local w][foreach w [1 2 3] [print w]]
_function/collect-deepfrom within Red (console? compiled?)
setworks the way it does by design. It allows you to externalize a word without having to use
/extern, so it will not change. And you really don't want to mod things in the bowels of the langauge, even if you can, because that will create all sorts of problems when sharing code and staying compatible with language changes.
It allows you to externalize a word without having to use /extern
set (or other "functions") in the
f: function  [parse [a] [set z word!] z] z; a)? It wasn't my intention to externalize a word by using
Could you change that kind of functions (or introduce others) in the
parse to be "local"?