dictionaries
[1/9] from: cavallieri:carlo:g:mail at: 16-Feb-2006 16:00
Hi,
on AltMe i read about factor language (factorcode.org).
Also factor it is based on word, word that make things(function),
in addition it has dictionaries (vocabularies), similar to namespaces
Just for curiosity, why rebol does not have a namespaces systems?
If i have two identical word, how can i use the second without
delete
(replace) the first?
[2/9] from: SunandaDH:aol at: 16-Feb-2006 12:10
Carlo:
> If i have two identical word, how can i use the second without
> "delete"(replace) the first?
Namespaces have been whispered as part of REBOL 3.0, but no date for that.
The nearest equivalent is objects (aka contexts):
context1: make object! [var1: 10]
context2: make object! [var1: 100]
print context1/var1 + context2/var1
Sunanda.
[3/9] from: cavallieri::carlo::gmail::com at: 16-Feb-2006 21:15
Ok, so it's only a "next feature" and not a thing that rebol will
nerver see for "design decision"
Hope to see Namespaces soon :)
2006/2/16, SunandaDH-aol.com <SunandaDH-aol.com>:
[4/9] from: anton::wilddsl::net::au at: 17-Feb-2006 12:47
Hi Cavva,
As Sunanda pointed out, we use objects all the time
for this. eg:
make object! [print: "lost!"]
It looks in the above example that we have redefined the
word 'print. We have, but only the 'print in that object.
The value of 'print in the default, global context is still
the same and so 'print evaluates as usual.
In the following example I am binding a block of words
to a particular context. Those words which are found in
the context will be bound to the context. The rest of the
not-found words will keep their current binding:
a: "global"
b: "global"
ctx: context [b: "local"]
print bind [a b] ctx
;---> global local
You can bind huge chunks of code if you like.
This gives the same result as above:
do bind [print [a b]] ctx
;---> global local
Also if you want to get just one word out of a particular
object, you can use IN and GET:
print get 'a ;---> global
print get in ctx 'b ;---> local
Anton.
[5/9] from: cavallieri:carlo:gm:ail at: 17-Feb-2006 9:36
Thanks Anton, your response was very useful and interesting.
But, if I want to use different word defined in different context,
i must write something like:
print bind [a] ctx1
print bind [b] ctx2
print bind [c] ctx3
Am I wrong?
I think that some like
using: [ 'ctx1 'ctx2 'ctx3 ]
print a
print b
print c
would be more easy
2006/2/17, Anton Rolls <anton-wilddsl.net.au>:
[6/9] from: greggirwin:mindspring at: 17-Feb-2006 9:52
Hi Cavva,
C> But, if I want to use different word defined in different context,
C> i must write something like:
C> print bind [a] ctx1
C> print bind [b] ctx2
C> print bind [c] ctx3
C> Am I wrong?
You can use path notation
print [ctx1/a ctx2/b ctx3/c]
You can also use IN to get a word bound to a context; and gurus do all
kinds of tricky stuff when it comes to binding. REBOL has very few
limits on how you can make things work.
-- Gregg
[7/9] from: lmecir:mbox:vol:cz at: 17-Feb-2006 18:29
Cavva napsal(a):
>Thanks Anton, your response was very useful and interesting.
>But, if I want to use different word defined in different context,
<<quoted lines omitted: 9>>
>print c
>would be more easy
that is quite easy to accomplish, here is how:
using: func [
[throw]
context-block [block!]
body [block!]
] [
foreach context context-block [bind body in context 'self]
do body
]
ctx1: context [a: 11]
ctx2: context [b: 12]
ctx3: context [c: 13]
using reduce [ctx1 ctx2 ctx3] [
print a
print b
print c
]
HTH
-L
[8/9] from: cyphre::seznam::cz at: 17-Feb-2006 18:38
You can do even such 'confusing' things :-)
>> ctx1: make object! [value: 10]
>> ctx2: make object! [value: 20]
>> ctx3: make object! [value: 30]
>> blk: copy []
== []
>> repeat n 3 [append blk in get to-word join 'ctx n 'value]
== [value value value]
>> blk
== [value value value]
>> reduce blk
== [10 20 30]
>>
regards,
Cyphre
[9/9] from: cavallieri::carlo::gmail::com at: 17-Feb-2006 21:01
Really great solution !!
thanks, thanks to all.
2006/2/17, Ladislav Mecir <lmecir-mbox.vol.cz>:
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted