Context - code included- 2nd version
[1/49] from: rotenca::telvia::it at: 11-Sep-2001 23:05
> Hi,
Hi, Ladislav
> > > > do (all but block)
> > >
<<quoted lines omitted: 3>>
> Probably you should explain what you meant by "do (all but block)", I am not
> sure I understood you.
Here it is:
>> do to-block "aaasdas"
** Script Error: aaasdas is not defined in this context
** Near: aaasdas
>> in system/words first to-block "aaasdas"
== none
so "do block" do not load word, but "do %file" "do url" load them.
RT Documentation says:
"Accepts a block, or LOADs a string, file, or URL into
a block, then evaluates the expressions of the block."
> to
> make
Depends by datatype (block! do not load )
> > My interpretation:
> > in the actual context (global+locals) the word is not binded (defined).
<<quoted lines omitted: 14>>
> Special Word once. (Special Words are immutable Rebol values according to my
> findings!) That is why I prefer my explanation.
I want to say that if the binding has been different ("this context" was
different) the word could be defined. If you ask its value after the binding
of word, you'll get a value, because "this context" (global+local) will be
different.
You prefer your interpretation, i think, because you want to keep your
definition of context like a simple collection.
I have the impression you don't like the concept of Context at all. You speak
of bind (16.) after the definition of almost everything (global, local,
special - context as collection) as if binding was a secondary propriety of
Context (and you say very little of bind function in 16.). For me Context is
not understandable well without the notion of binding.
Indeed, your definition of collection (11.) depends from the notion of
bindings:
Rebol Contexts can be defined as some collections of Rebol Words. I define a
function, that can find out, if two given Words are bound to the same
Context:
^^^^^^
same-context?: func [
...
not special? word2
same? word1 bind use word1 reduce ['first reduce [word1] ]
word2
^^^^^
As i have already said: your same-context function is not correct: it can only
prove that every Special Word is not binded to other words, so if you want
speak of collections, you must say that it is a collection with one item (like
the Zero?). You should say:
Every single Special Word is a Special Context.
Every Special Context is a collection of only one word.
There are as many Special Contexts as Special Words.
The number of Special Contexts is enlarge-able.
It does not exist in Rebol one method to find all Special Contexts.
> Well, I can show you how:
> new-bind: func [
<<quoted lines omitted: 10>>
> ]
> ]
1) We already know that we can create Special Words with to block!.
I should change my idea only if we can create them by successfull binding,
like with all other contexts!
2) If you are right, then
bind 'something SpecialW
> > Script Error: SpecialW is not defined in this context
is obiouvsly a bug and you should report it to RT, because here you should
create a new Special Word binded to SpecialW (so we should create
sub-collections of special words binded each other, but not defined).
In my vision, only the error message is little clear and i should ask RT to
change it.
> > We could call Special Context the Fail or Error Context. :-)
>
> The Fail Context or some such look well enough, maybe better than the
> Special Context...
I have thinked another name:
Alfa-Context
1) Alfa = the most simple state of word
(fails to bind any other word)
(the start, the beginning, like Zero)
2) Alfa = greek alfa privative => not a true Context
(if every words was special, the notion of context
and collection would be meaningless)
> > > Cheers
> > > Ladislav
---
Ciao (my english is bad)
Romano
[2/49] from: lmecir:mbox:vol:cz at: 10-Sep-2001 20:47
Hi,
...snip...
> I try to think at the Global Context as the target of Load (and other
> functions like to-word) which is the default loader for a block. I think
of it
> as the the load-context (or default-context).
>
> I should like to know all the functions which make a implicit-explicit
load.
> Can you help me?
> to-word
<<quoted lines omitted: 3>>
> load
> do (all but block)
I don't think the last one is correct...
> ... ?
to
make
> I think that your Special Context is not a true Context, it is not a
context
> at all, it has not the aspect and the use of a context, which is to give a
> value to a word.
I am trying to comply with the official documentation if possible:
special: first to block! "a"
set special 1
** Script Error: a is not defined in this context
** Where: halt-view
** Near: set special 1
This is how I can interpret it:
1) the word 'a stored in 'special is "in a context"
2) it is "in a context" where it "isn't defined"
3) I call that context the Special Context
OTOH, it is my definition. For me it is the simplest definition. Didn't try
to invent any other, I confess...
> It is only the class of words out of context
> (decontextualized). I can understand "special word", but not "special
> context":
>
> words
> binded (many Contexts) not-binded (out of context)
> So i do not like your visualize-context when it returns first system/words
for
> Special words. First system/words is only one big collection of Special
word,
> but it is a collection like another. If I do a:
>
> to-block read %italianvocabolary10000words
>
> i have created 10000 special words which v-c does not see. It instead
return
> me 3k words among which there is none of my 10k italian words. So i think
that
> v-c must return a [] or none for special words, also because they have no
> context.
As to whether the Special Context is a Context: it depends on definition. I
wrote a definition which is telling me, that it is a Context. Your
proposition reflects my implementation of V-C as I wrote it 24/7/2000.
> > > local?: func [
> > > {find out, if the given Word is a Local Word}
<<quoted lines omitted: 7>>
> >
> > This notion is less useful than the notion of Local Words I prefer,
because
> > from two Words of the same Context the first one may be "local" while
second
> > "non-local".
>
> Here I do not see any difference between your and mine implementation. Can
> explain it to me?
Sorry, I just didn't read what was written, you are right.
> > > in-object?: func [
> > > {find out, if the given Word is defined in a object-context}
<<quoted lines omitted: 18>>
> o: context [self: system/words]
> I have tried to correct the last 2 incorrect behaviour in another version.
I
> find
> it useful for visualize-context: it can reveal the object-local-unloaded
words
> that your implementation do not find at all. If the function fails,
> visualize-context can default to the old scheme: scanning system words.
> When this function return true, it is true, when false, it is undefined.
May be interesting
Cheers
Ladislav
[3/49] from: lmecir:mbox:vol:cz at: 10-Sep-2001 23:11
Hi,
> > > in-object?: func [
> > > {find out, if the given Word is defined in a object-context}
<<quoted lines omitted: 18>>
> o: context [self: system/words]
> I have tried to correct the last 2 incorrect behaviour in another version.
I
> find
> it useful for visualize-context: it can reveal the object-local-unloaded
words
> that your implementation do not find at all. If the function fails,
> visualize-context can default to the old scheme: scanning system words.
> When this function return true, it is true, when false, it is undefined.
>
Now I know what you were after. The problem is, that the function fails in
the case:
word: use 'self [self: make object! [] 'self]
in-object? word
The correction might be:
in-regular-object?: function [
{finds out, if the given Word is in a regular object}
word [word!]
] [self bound-self] [
found? all [
not special? word
not same? 'self bound-self: bind 'self word
object? get/any bound-self
same? bound-self in get/any bound-self 'self
]
]
[4/49] from: rotenca:telvia:it at: 11-Sep-2001 0:52
> Hi,
Hi,
> > do (all but block)
>
> I don't think the last one is correct...
Sure?
> to
> make
Merci!
> I am trying to comply with the official documentation if possible:
> special: first to block! "a"
<<quoted lines omitted: 6>>
> 2) it is "in a context" where it "isn't defined"
> 3) I call that context the Special Context
My interpretation:
in the actual context (global+locals) the word is not binded (defined).
Es.
>> specials: to block! "a"
== [a]
>> set first specials 1
** Script Error: a is not defined in this context
** Near: set first specials 1
>> bind specials 'system
== [a]
>> set first specials 1
== 1
It is true that bind replaces the words it binds, but what can we ask to an
error message?
> OTOH, it is my definition. For me it is the simplest definition. Didn't try
> to invent any other, I confess...
It is only a linguistic question, i agree.
> As to whether the Special Context is a Context: it depends on definition. I
> wrote a definition which is telling me, that it is a Context.
I don't want to stress you about this very little question but I can't resist
(sorry). You say:
I define a function, that can find out, if two given Words are bound to the
same Context:
now: in the function same-context?:
...
special? word1
special? word2
...
which use the error:
Script Error: wordx is not defined in this context.
Which says that the word1 and word2 are not y
defined(word1)<>y and defined(word2)<>y -> context(word1)=context(word2)
is a logical error for me, but perhaps I'm in error.
In effect:
bind 'something SpecialWord
Script Error: SpecialWord is not defined in this context
Why a word must be defined to bind something to it? Because defined = binded
to a context.
If the last command could create a Special Word I should admit to be wrong.
We could call Special Context the Fail or Error Context. :-)
Excuse me again for my insistence really out of place.
> Cheers
> Ladislav
---
Ciao
Romano
[5/49] from: holger:rebol at: 10-Sep-2001 17:57
On Mon, Sep 10, 2001 at 08:47:33PM +0200, Ladislav Mecir wrote:
> I am trying to comply with the official documentation if possible:
> special: first to block! "a"
<<quoted lines omitted: 6>>
> 2) it is "in a context" where it "isn't defined"
> 3) I call that context the Special Context
That is not necessary. Don't invent something if you don't have
to :). Occam's Razor...
You just misunderstood the error message. The "is not defined" refers
to the word not existing (in this context), not to the word not having
a value in it. In other words: the word is unbound.
There is no "Special Context" of the kind you describe in REBOL. A word
is either unbound or it is bound into a context. A word can only have a
value if it is bound. Most of the time words are bound automatically.
There are some exceptions, e.g. words in blocks created by to-block "string".
The only context that is (somewhat) unusual, e.g. in that it can
dynamically expand, is the global context, exposed at the REBOL layer
through system/words. The global context behaves just like a regular context
in most ways though, e.g. it only contains words which have been bound
to it, i.e. it does not necessarily contain ALL words:
>> find first system/words 'abcd
== [abcd]
(The word 'abcd on the command line was bound into the global context by the
interpreter after parsing the input.)
>> find first system/words first to-block "abce"
== none
(The word 'abce was never bound into the global context.)
--
Holger Kruse
[holger--rebol--com]
[6/49] from: lmecir:mbox:vol:cz at: 11-Sep-2001 3:30
Hi,
> > > do (all but block)
> >
> > I don't think the last one is correct...
>
> Sure?
Probably you should explain what you meant by "do (all but block)", I am not
sure I understood you.
> > to
> > make
<<quoted lines omitted: 15>>
> in the actual context (global+locals) the word is not binded (defined).
> Es.
Aha, so you are trying to define a notion of Actual Context to help you to
explain this situation. The problem with your explanation is, that the
situation in your description looks like being caused by the fact the Word
is not "defined" in the Actual Context. Even though I don't know your
definition of the Actual Context, I am pretty sure, that it should be an
extensible collection of Rebol Words, if it contains the Global Context,
which is an extensible collection of Rebol Words itself. It provokes a
thought that after an extension of the Actual Context the situation of the
Word may change because after such an extension the amount of the "defined"
Words must increase.
But, alas, the opposite is true: no extension of anything can cause the Word
to become "defined", because it will always remain the Special Word being a
Special Word once. (Special Words are immutable Rebol values according to my
findings!) That is why I prefer my explanation.
...
> I don't want to stress you about this very little question but I can't
resist
Absolutely no problem. A nice discussion.
> You say:
>
> "I define a function, that can find out, if two given Words are bound to
the
> same Context: "
> now: in the function same-context?:
<<quoted lines omitted: 13>>
> to a context.
> If the last command could create a Special Word I should admit to be
wrong.
Well, I can show you how:
new-bind: func [
{bind a Word to a Context}
word [word!]
known-word [word!]
] [
if error? try [return bind word known-word] [
either loaded? word [
first find first rebol/words word
] [
first to block! mold word
]
]
]
> We could call Special Context the Fail or Error Context. :-)
The Fail Context or some such look well enough, maybe better than the
Special Context...
[7/49] from: lmecir:mbox:vol:cz at: 11-Sep-2001 3:58
Hi Holger,
> > I am trying to comply with the official documentation if possible:
> >
<<quoted lines omitted: 13>>
> You just misunderstood the error message. The "is not defined" refers
> to the word not existing (in this context),
I am not able to accept the notion of This Context, as you present it, I am
sorry. The notion of This Context is totally contradictory to the behaviour
of Rebol I am observing.
...
> A word
> is either unbound
> or it is bound into a context.
Well, I am not scared to hear sir William's name. I think, that the
difference between our POV's is exactly the same as the difference between
an ancient Roman and an Arab arguing whether the Zero is a number. I know
who won and why. 8^)
...
[8/49] from: holger:rebol at: 10-Sep-2001 20:11
On Tue, Sep 11, 2001 at 03:58:02AM +0200, Ladislav Mecir wrote:
> Hi Holger,
> > > I am trying to comply with the official documentation if possible:
<<quoted lines omitted: 17>>
> I am not able to accept the notion of This Context, as you present it, I am
> sorry.
That error message is a "catch all" for situations in which REBOL encounters
a word which is not bound into a context, when the operation REBOL attempts
to perform requires the word to be bound. This includes 'get, 'set, evaluation
of a word, evaluation of a path, 'protect, 'bind (the sample word) etc.
Whether the word has a value does not even matter (unless the particular
operation requires a value). This further illustrates that the issue is
binding, not value, and that "is not defined" has nothing to do with values.
Example:
>> set first to-block "a" 1
** Script Error: a is not defined in this context
** Near: set first to-block "a" 1
>> set 'a 1
== 1
Those are the facts. Whether you agree with the exact wording of the
error message is your choice. "a is not bound into any context" would
probably be more accurate, but also somewhat more technical and more
difficult to understand for new users.
Regardless of what the exact message text is, contexts work in a certain
way, a "Special Context" the way you describe it does not exist in REBOL
and is not necessary or useful to describe the existing behavior.
> The notion of This Context is totally contradictory to the behaviour
> of Rebol I am observing.
I did not present any notion of "This Context" at all :), so how it can
contradict any observed behavior, and what behavior is that ?
--
Holger Kruse
[holger--rebol--com]
[9/49] from: tim:johnsons-web at: 9-Sep-2001 10:04
Hi After Seeing Ladislavs message about 'map, I followed his link
and was pleased to see a wealth of really good material there.
I don't (for instance) see the material on contexts in the rebol
user's manual (or did I see it). Maybe it ought to be....
Good work Ladislav. Thanks!
(This will help me break out of my adherence to "C" paradigms).
tj
On Sun, Sep 09, 2001 at 01:28:39PM +0200, Ladislav Mecir wrote:
> Hi all,
> I incorporated some more Romano's ideas to
<<quoted lines omitted: 6>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
Tim Johnson <[tim--johnsons-web--com]>
http://www.johnsons-web.com
[10/49] from: rotenca:telvia:it at: 10-Sep-2001 12:32
> Hi Romano,
Hi Ladislav,
thank you for your precise comments!
> some comments:
> > binded?: func [
> The above is exactly the opposite of what I want to call a Special Word.
Very well!
> > loaded?: func [
> This notion is your invention and it surely deserves our attention! The fact
> is, that one Rebol Context (as you have proven) can consist of Loaded as
> well as Not Loaded Words (except for the Global Context, which cannot
> contain Not Loaded Words, of course...). The implementation cannot really
> handle ANY-WORD! values.
I admit: didn't checked arguments! I cloned one for all function! I thinked
only at word! datatype!
I try to think at the Global Context as the target of Load (and other
functions like to-word) which is the default loader for a block. I think of it
as the the load-context (or default-context).
I should like to know all the functions which make a implicit-explicit load.
Can you help me?
to-word
to-lit-word
to-set-word
to-get-word
load
do (all but block)
... ?
> Word, because it is only a subcollection of the Special Context I tried to
> define. It is not a Context.
I think that your Special Context is not a true Context, it is not a context
at all, it has not the aspect and the use of a context, which is to give a
value to a word. It is only the class of words out of context
(decontextualized). I can understand "special word", but not "special
context":
words
binded (many Contexts) not-binded (out of context)
Loaded/unloaded says only if the global context has a copy of the word. Can be
useful to check "global-transparent" code.
So i do not like your visualize-context when it returns first system/words for
Special words. First system/words is only one big collection of Special word,
but it is a collection like another. If I do a:
to-block read %italianvocabolary10000words
i have created 10000 special words which v-c does not see. It instead return
me 3k words among which there is none of my 10k italian words. So i think that
v-c must return a [] or none for special words, also because they have no
context.
> > local?: func [
> > {find out, if the given Word is a Local Word}
<<quoted lines omitted: 8>>
> from two Words of the same Context the first one may be "local" while second
> "non-local".
Here I do not see any difference between your and mine implementation. Can
explain it to me?
> > in-object?: func [
> > {find out, if the given Word is defined in a object-context}
<<quoted lines omitted: 11>>
> o/self: 11
> in-object? in o 'self ; == false
You are right, it can fail also if you globally define:
self: system/words
or
o: context [self: system/words]
I have tried to correct the last 2 incorrect behaviour in another version. I
find
it useful for visualize-context: it can reveal the object-local-unloaded words
that your implementation do not find at all. If the function fails,
visualize-context can default to the old scheme: scanning system words.
When this function return true, it is true, when false, it is undefined.
> Cheers and thanks again.
> Ladislav
Thank you for all your work!
--
Ciao
Romano
[11/49] from: rotenca:telvia:it at: 8-Sep-2001 18:51
In the previous there was an error in v-c. Resend my corrected post.
-------
Thank you for your previous message, i'll answer asap.
Here it is my idea of special-global-local words. written as code.
In the yesterday message i misinterpreted some of your code (and of your mind,
of course).
Now i think to understand well your idea of Special Word.
So in my code there are now only Special Word e Very Special Word.
I have written a modified version of Visualize-Context.
Happy to know your idea and my bug...
---
Ciao
Romano
-----
rebol[
Title: "Analyze a word"
Date: 30/7/2001
File: %myword.r
Email: [rotenca--libero--it]
Author: "Romano Paolo Tenca"
Version: 1.0.0
Category: [text util 3]
Purpose: {
find the type of a Rebol word
Visualize-Context redefined
many functions are a modified version of the
originals of Ladislav Mecir
to reflect the very special words
}
]
binded?: func [
{determines, if a Word is defined in any context}
word [any-word!]
] [
not error? try [error? get/any :word]
]
loaded?: func [
{determines, if a Word is defined in system-words}
word [any-word!]
] [
found? find first system/words word
]
vspecial?: func [
{determines, if a Word is a Very Special Word}
word [any-word!]
] [
found? all [
not binded? word
not loaded? word
]
]
special?: func [
{determines, if a Word is a Special Word}
word [any-word!]
] [
found? all [
not binded? word
loaded? word
]
]
global?: func [
{find out, if the given Word is a Global Word}
word [any-word!]
] [
found? all [
loaded? word
same? word bind word 'system
]
]
local?: func [
{find out, if the given Word is a Local Word}
word [any-word!]
] [
found? all [
binded? word
not global? word
]
]
local-unloaded?: func [
{find out, if the given Word is a Local Word not loaded in system/words}
word [any-word!]
] [
found? all [
binded? word
not loaded? word
]
]
in-object?: func [
{find out, if the given Word is defined in a object-context}
word [any-word!]
/local self
] [
found? all [
binded? word
not same? 'self bind 'self word
equal? object! type? get/any bind 'self word
]
]
in-use?: func [
{find out, if the given Word is Local to a func or use block}
word [any-word!]
] [
found? all [
local? word
not in-object? word
]
]
v-c: visualize-context: function [
{
Returns a copy of context words binded to the context
ATTENTION:
for a word local to use or func, return only the loaded? word
for an un-binded word returns []
}
word [word!] {one Word of the given Context}
] [result b-word] [
result: copy []
any [
if not binded? word [result]
if global? word [bind/copy first system/words 'system]
if in-object? word [bind/copy first get bind 'self word word]
do [
foreach s-word first system/words [
if not same? s-word b-word: bind s-word word [
append result b-word
]
]
result
]
]
]
what?: func [word [word!]] [
if loaded? word [print "loaded?"]
if binded? word [print "binded?"]
if vspecial? word [print "vspecial?"]
if special? word [print "special?"]
if global? word [print "global?"]
if local? word [print "local?"]
if in-object? word [print "in-object?"]
if in-use? word [print "in-use?"]
if local-unloaded? word [print "local-unloaded?"]
print ""
]
;examples
what? 'do
what? first first system/words
use [a] [what? a]
halt
[12/49] from: lmecir:mbox:vol:cz at: 9-Sep-2001 0:08
Hi Romano,
thanks again for revealing my bugs, I tried to correct them. The text really
needed correction.
some comments:
> rebol[
> Title: "Analyze a word"
<<quoted lines omitted: 18>>
> not error? try [error? get/any :word]
> ]
The above is exactly the opposite of what I want to call a Special Word.
> loaded?: func [
> {determines, if a Word is defined in system-words}
> word [any-word!]
> ] [
> found? find first system/words word
> ]
This notion is your invention and it surely deserves our attention! The fact
is, that one Rebol Context (as you have proven) can consist of Loaded as
well as Not Loaded Words (except for the Global Context, which cannot
contain Not Loaded Words, of course...). The implementation cannot really
handle ANY-WORD! values.
> vspecial?: func [
> {determines, if a Word is a Very Special Word}
<<quoted lines omitted: 5>>
> ]
> ]
The notion of Very Special Word isn't as useful as the notion of a Loaded
Word, because it is only a subcollection of the Special Context I tried to
define. It is not a Context.
> special?: func [
> {determines, if a Word is a Special Word}
<<quoted lines omitted: 5>>
> ]
> ]
This notion is again less useful than the notion of Special Word I am using,
which "defines" a Context while this notion can "define" only a
subcollection of a Context.
> global?: func [
> {find out, if the given Word is a Global Word}
<<quoted lines omitted: 5>>
> ]
> ]
This implementation cannot really handle ANY-WORD! datatype values.
> local?: func [
> {find out, if the given Word is a Local Word}
<<quoted lines omitted: 5>>
> ]
> ]
This notion is less useful than the notion of Local Words I prefer, because
from two Words of the same Context the first one may be "local" while second
non-local
.
> local-unloaded?: func [
> {find out, if the given Word is a Local Word not loaded in
system/words}
> word [any-word!]
> ] [
<<quoted lines omitted: 14>>
> ]
> ]
the last function is incorrect (and incorrectible, IMO), e.g.:
o: make object! []
o/self: 11
in-object? in o 'self ; == false
> in-use?: func [
> {find out, if the given Word is Local to a func or use block}
<<quoted lines omitted: 5>>
> ]
> ]
Incorrectible, I am afraid.
...snip...
Cheers and thanks again.
Ladislav
[13/49] from: lmecir:mbox:vol:cz at: 9-Sep-2001 13:28
Hi all,
I incorporated some more Romano's ideas to
http://www.sweb.cz/LMecir/contexts.html
Added a BIND section.
Regards
Ladislav
[14/49] from: rotenca::telvia::it at: 8-Sep-2001 18:32
Context - code included
Thank you for your previous message, i'll answer asap.
Here it is my idea of special-global-local words. written as code.
In the yesterday message i misinterpreted some of your code (and of your mind,
of course).
Now i think to understand well your idea of Special Word.
So in my code there are now only Special Word e Very Special Word.
I have written a modified version of Visualize-Context.
Happy to know your idea and my bug...
---
Ciao
Romano
-----
rebol[
Title: "Analyze a word"
Date: 30/7/2001
File: %myword.r
Email: [rotenca--libero--it]
Author: "Romano Paolo Tenca"
Version: 1.0.0
Category: [text util 3]
Purpose: {
find the type of a Rebol word
Visualize-Context redefined
many functions are a modified version of the
originals of Ladislav Mecir
to reflect the very special words
}
]
binded?: func [
{determines, if a Word is defined in any context}
word [any-word!]
] [
not error? try [error? get/any :word]
]
loaded?: func [
{determines, if a Word is defined in system-words}
word [any-word!]
] [
found? find first system/words word
]
vspecial?: func [
{determines, if a Word is a Very Special Word}
word [any-word!]
] [
found? all [
not binded? word
not loaded? word
]
]
special?: func [
{determines, if a Word is a Special Word}
word [any-word!]
] [
found? all [
not binded? word
loaded? word
]
]
global?: func [
{find out, if the given Word is a Global Word}
word [any-word!]
] [
found? all [
loaded? word
same? word bind word 'system
]
]
local?: func [
{find out, if the given Word is a Local Word}
word [any-word!]
] [
found? all [
binded? word
not global? word
]
]
local-unloaded?: func [
{find out, if the given Word is a Local Word not loaded in system/words}
word [any-word!]
] [
found? all [
binded? word
not loaded? word
]
]
in-object?: func [
{find out, if the given Word is defined in a object-context}
word [any-word!]
/local self
] [
found? all [
binded? word
not same? 'self bind 'self word
equal? object! type? get/any bind 'self word
]
]
in-use?: func [
{find out, if the given Word is Local to a func or use block}
word [any-word!]
] [
found? all [
local? word
not in-object? word
]
]
v-c: visualize-context: function [
{
Returns a copy of context words binded to the context
ATTENTION:
for a word local to use or func, return only the loaded? word
for an un-binded word returns []
}
word [word!] {one Word of the given Context}
] [result b-word] [
result: copy []
any [
if not binded? word [result]
if global? word [bind/copy first system/words 'system]
if in-object? word [bind/copy first get bind 'self word word]
foreach s-word first system/words [
if not same? s-word b-word: bind s-word word [
append result b-word
]
]
result
]
]
what?: func [word [word!]] [
if loaded? word [print "loaded?"]
if binded? word [print "binded?"]
if vspecial? word [print "vspecial?"]
if special? word [print "special?"]
if global? word [print "global?"]
if local? word [print "local?"]
if in-object? word [print "in-object?"]
if in-use? word [print "in-use?"]
if local-unloaded? word [print "local-unloaded?"]
print ""
]
;examples
what? 'do
what? first first system/words
use [a] [what? a]
halt
[15/49] from: lmecir:mbox:vol:cz at: 12-Sep-2001 23:26
Re: Context - code included- 2nd version
The latest version of http://www.sweb.cz/LMecir/contexts.html reflects some
points made in the latest discussions.
Cheers
Ladislav
[16/49] from: rotenca:telvia:it at: 13-Sep-2001 0:44
> I don't know if the discussion didn't start to be boring, but here are my
> reactions:
Up to now, i have learned many things and cleared many of my ideas on Rebol.
So i should say: boring but useful to me :-)
> I bound the SPECIAL ('foo) to a USE context and stored the result to BOUND.
> Nevertheless, the SPECIAL ('foo) still doesn't look changed. It still looks
> like a Special Word. Are you trying to convince me that it shouldn't,
> because it has been bound to the This Context?
That message is ambiguos. Natural language is not a formal language.
That message should be changed because some people mis-interpret it :-)
> Basic fact # 1: My definition of the Rebol Context notion is the only
> definition available.
Sorry, it is an incorrect definition. You can use your definition, but it is
not a definition of Rebol Contexts, is the definition of Mecir Contexts.
It is absolutly clear in Core Doc that a word in itself has no value. A word
with no value (=Special Word) is a value and can be used as a Symbol.
When a word has been linked to a value, it can be used also as Variable.
Values are stored in block, and collected and linked to words in Context.
Value are NOT stored in word (as you say). It is clear that Contexts are
collections of Variables, not collections of Words. Symbols are alfanumeric
indexes to get values from Contexts:
first system/words
returns the alphanumeric indexes (Symbols) accepted by the global object to
connect known values to known words.
In:
>> in rebol/words first to-block "system"
== system
The word without value "system" (SpecialWord) is used as a symbol, i.e. like a
value. It is like to use the value 3 to index a block. When you say that a
Rebol Context is a collections of words, it is like you said that the block
x: ["a" "b" "c"]
collects
the integer 3 because you can get "c" with the expressions:
x/3
This is all. A Mecir Context is a collection of words. A Rebol Context is a
collection of Variables. They can convive, only if they are not confused each
other (like you make).
Now some evidence and comments from RT documentation:
1)
Message ID: not-defined
A word used was not defined within any context.
Message:
[:arg1
is not defined in this context"]"
Tell me how you can explain the word "any". When a word is in a context, only
that context can give a definition to the word, so why to speak of "any"
others contexts?
2) "A variable refers to a specific value only within a defined context," p.
2-9
So when it doesn't "refers to a specific value" (=get fails = SpecialWord) it
is not "within a defined context"
3) "the context of words in a string is not known." 3-11
4) "The scope of a variable is determined when its context is defined."
Ergo: context of a word can be undefined.
5) "Binds meaning to words in a block. That is, it gives
words a context in which they can be interpreted.
This allows blocks to be exchanged between different
contexts, which permits their words to be understood."
6) "Words can be reused. The meaning of a word is dependent on its context, so
words
can be reused in different contexts."
7) "Words are the symbols used by REBOL. A word may or may not be a variable,
depending on how it is used."
8)"A variable refers to a specific value only within a defined context, such
as a block,
a function, or an entire program. Outside that context the variable can refer
to some
other value or to no value at all."
9) "Words are used in two ways: as symbols or as variables."
A word is a variable if it has a value, and it has a value if is defined in a
context. Outside a context the word can have a value if is defined in another
context, or it can have no value and in this case is "not defined within any
context".
So my functions could become (restricting the use of word "symbol"):
variable?: binded? ...
symbol?: not binded? ...
and words: variables + symbols. It is also incorrect to speak of local words
and global words, you must speak of
local-variables (object-variables + block-variables - i.e. use,
func)
global-variables
> > Indeed, your definition of collection (11.) depends from the notion of
> > bindings:
>
> Not at all, it only uses a Rebol function the implementation of which I
> wrote. When I did it I didn't need any notion of bindings. I needed only to
> write something in Rebol.
So i could say that the two class of words Loaded?/Not Loaded? are two
Contexts because they divide all the words in collections and i can write the
function which make the division? Too easy.
> Cheers
> Ladislav
> >
---
Ciao
Romano
[17/49] from: lmecir:mbox:vol:cz at: 12-Sep-2001 1:24
I don't know if the discussion didn't start to be boring, but here are my
reactions:
> I want to say that if the binding has been different ("this context" was
> different) the word could be defined. If you ask its value after the
binding
> of word, you'll get a value, because "this context" (global+local) will be
> different.
I will try to interpret the above sentence and discuss it:
First of all I understood, that you defined : This Context is a collection
of all Global and Local Words. Am I right? (The definition is a bit
contradictory, because This Context is not a Context.)
; a Special word:
special: first to block! "foo"
; bind it to a context:
use special reduce [
bound: 'first reduce [special]
]
I bound the SPECIAL ('foo) to a USE context and stored the result to BOUND.
Nevertheless, the SPECIAL ('foo) still doesn't look changed. It still looks
like a Special Word. Are you trying to convince me that it shouldn't,
because it has been bound to the This Context?
> You prefer your interpretation, i think, because you want to keep your
> definition of context like a simple collection.
> I have the impression you don't like the concept of Context at all.
8^)
> You speak
> of bind (16.) after the definition of almost everything (global, local,
> special - context as collection) as if binding was a secondary propriety
of
> Context (and you say very little of bind function in 16.). For me Context
is
> not understandable well without the notion of binding.
The reason for that is much simpler. If I want to describe the behaviour of
BIND, I must speak about Contexts. If I want to speak about Contexts, I must
first define the notion, because that was my goal when I started to write
the article.
Basic fact # 1: My definition of the Rebol Context notion is the only
definition available.
Basic fact # 2: My definition of the Rebol Context notion differs from the
meaning the context notion usually has in other languages.
> Indeed, your definition of collection (11.) depends from the notion of
> bindings:
Not at all, it only uses a Rebol function the implementation of which I
wrote. When I did it I didn't need any notion of bindings. I needed only to
write something in Rebol.
> Rebol Contexts can be defined as some collections of Rebol Words. I
define a
> function, that can find out, if two given Words are bound to the same
> Context:
<<quoted lines omitted: 6>>
> ^^^^^
> As i have already said: your same-context function is not correct: it can
only
> prove that every Special Word is not binded to other words, so if you want
> speak of collections, you must say that it is a collection with one item
(like
> the Zero?).
Incorrect. I am stating that if WORD1 is a Special Word, then the expression
same-context? word1 word2
yields TRUE if WORD2 is a Special Word and FALSE otherwise.
>You should say:
>
> Every single Special Word is a Special Context.
Incorrect. The collection of all Words that are in the SAME-CONTEXT as a
Special Word is the collection of all Special Words.
> Every Special Context is a collection of only one word.
Incorrect. See above.
> There are as many Special Contexts as Special Words.
Incorrect. See above.
> The number of Special Contexts is enlarge-able.
> It does not exist in Rebol one method to find all Special Contexts.
Incorrect. See above.
...snip...
Cheers
Ladislav
[18/49] from: holger:rebol at: 12-Sep-2001 17:39
On Wed, Sep 12, 2001 at 11:26:57PM +0200, Ladislav Mecir wrote:
> The latest version of http://www.sweb.cz/LMecir/contexts.html reflects some
> points made in the latest discussions.
Unfortunately your major misconceptions are still in there. The highlights:
- Words do not "store" values, they ARE values. REBOL is a first-class language,
and a word is a value like any other value. Values may have properties that
distinguish different values of the same type from each other, e.g. integer!
values may have different numeric values. The properties of word! (and lit-word!,
set-word!, get-word!) are, precisely, a reference to the context the word is bound
to (if any) and its spelling.
When evaluating a value the result is, usually, another value. The value you get
when evaluating a word is NOT a property of the word, it is something determined
dynamically by the interpreter, at the time the word is evaulated. Those values are
not stored in words, they are stored in contexts.
- Contexts are not word tables, but name-value lookup tables. The "names" are
the spellings of words. The "values" are ordinary REBOL values, and are what
you get when you evaluate a word with the same spelling that is bound into
the context.
- There is no "Special Context" and there are no "Special Words". What you call
a "Special Word" is in reality a word not bound into a context.
- Your distinction between local, global, special etc. words is a little
confusing, mostly because "Loaded Word" is orthogonal to the other definitions.
It refers to the existance of a word in the global context, whereas all the
other definitions refer to the binding of an individual word.
Better, more consistent with the documentation (not to mention implementation):
Replace "Special Word" with "word not bound into a context".
Replace "Loaded Word" with "word which exists in the global context".
Replace "Global Word" with "word bound into the global context".
Replace "Local Word" with "word bound into a non-global context".
These are the major problems with your document. A lot of the complexity and many
of the individual observations you made seem interesting and significant only because
your somewhat arbitrary definitions obscure the actual meaning. Once those terms
are replaced by their meanings most observations follow logically and become
redundant.
Some more minor nitpicks:
- to-block! does not bind words into a context. make word! and to-word
bind all words into the global context (terminology).
- The global context expands automatically as new words are bound into it.
The fact that this increases the number of "Loaded Words" is redundant
(again, result of obscure terminology).
- Aliases are not properties of contexts and therefore do not show up in
visualizations of contexts. That's because aliases are global, not local
per context.
- Scoping: REBOL uses lexical scoping, not dynamic scoping, but allows words
to be rebound during block evaluation. That's how words can refer to different
contexts even though their scope is lexical. "Scope hierarchies" imply some
kind of tree, which does not exist, so using that term is probably a bad idea.
Calling a scope hierarchy "virtual" is yet another definition which obscures
facts rather than illustrates them.
The facts are: words live inside of blocks. When a block is created all words
in it are either bound into a context, or remain unbound. Certain functions
('use etc.) change the binding of words. That is all there is to it, and the
"scope" of a word at any given time is simply determined by the last bind
operation on it before the word gets evaluated.
- The "bug" you described when combining 'use with functions and other contexts
is not a bug. It is intentional. There are only four ways how a function can
(theoretically) access its local variables and arguments, in any language:
- Using a hidden context pointer. That's what C does, using the stack pointer.
REBOL does not (and cannot) do it, because the only local environment REBOL
has when executing a function body is that particular function body, which is
a simple block, and the association from a function to its block is one-way (like
all references in REBOL). This means the function body has no hidden reference
back to the function itself, and therefore cannot access its arguments.
- By creating a completely new "environment" for each function. That includes
a new argument and variable space (context) AND a new function body (deep-copied).
This way all words in the function body can be rebound into the new context.
That's what your 'cfunc does, but it is unacceptable performance-wise.
- By keeping a single function body for all function invocations, and dynamically
rebinding it to a different context, one for each invocation, every time a
function is called or returns. This generates O(n) complexity for each function
call, where n is the size of the function, i.e. performance is prohibitive as
well for large functions, and it has other practical problems.
- By keeping a single function body for all function invocations, bound to the
same context, and changing the context on the fly (i.e. exchanging the
"value" part of the name-value table for each function call, using a virtual
stack). This is what REBOL does. The "bug" you describe is a normal and
inevitable side effect of this, and not a "bug" at all. Your "fix" changes the
function execution model in a way that generates unacceptable performance.
If you really need the behavior you describe then you are, of course, free to
write your own functions which implement it, as you have done, but for performance
reasons that behavior should not be the default in REBOL.
- The drawback you describe in regard to what you call the Dynamic Recursion Path
is actually caused by the fact that the context of the outer function remains
intact (indefinite extent) AND retains its values after the outer function
returns (for non-recursive function invocations), under certain circumstances.
This is an implementation detail you should not rely on, because it is likely to
change in future versions, i.e. there is a good chance that in the future after
a (non-recursive) function invocation the values of that function's context are
set to unset!. This would break the way your inner function references the
outer function's arguments after the outer function has returned.
The problem with function contexts keeping their values after the function returns
is that the referenced values do not get garbage-collected, even though no (apparent)
reference exists any more, until the function is called again. In some situations
(e.g. when trying to close and garbage-collect an unreferenced port) this can be very
problematic.
Relying on the values of a function's context beyond the life time of the corresponding
function call should be considered illegal, i.e. you need to, e.g., 'reduce the body
of your
inner function so the argument gets replaced by its value before the function is returned.
This also resolves the drawback you mentioned, i.e. use
f: func [x] [func [] reduce [x]]
and the behavior is as expected and compatible with future versions.
--
Holger Kruse
[holger--rebol--com]
[19/49] from: greggirwin:starband at: 13-Sep-2001 9:13
Holger,
Thanks for your incredibly detailed (and highly informational!) post. 99% of
it is going right over my head since I'm still in the process of grokking
REBOL basics but I'll be pulling it out often I'm sure, to see if I'm
learning anything.<g>
There is no substitute for genuine, first-hand, information and I just
wanted to let you know that your time is appreciated.
--Gregg
[20/49] from: sanghabum:aol at: 13-Sep-2001 4:43
Hi Holger,
> Unfortunately your major misconceptions are still in there. The highlights:
<snip>
I've very glad that Ladislav Mecir has prompted you into issuing a detailed
technical document explaining binding and contexts. I've found it very
confusing trying to work all this out from the meagre clues the official
documentation provides.....So you can't consider it unlikely that some of us
invent terminology in an attempt to understand things.
The Core manual fails, for example, to define "Global" as far as I can tell.
It does state that:
A variable refers to a specific value only within a defined context, such as
a block,
a function, or an entire program. Outside that context the variable can refer
to some
other value or to no value at all. The context of a variable can span an
entire
program or it can be restricted to a particular block, function, or object.
Leaving aside that worrying "such as" (*what* other defined but unexplained
contexts exist?), we have the term "entire program".
This appears to mean one invocation of REBOL.EXE and perhaps is the same as
Global Context.
But the example %headfull.r script refers to itself as a program, so perhaps
entire program
means "single script" in some circumstances.
And does a launched script share a Global context with its parent, or is
Global really "local to program invocation"?
And there's more. Like (from the manual again) what does "module" mean here:
In large scripts and where possible, avoid using global variables that carry
their internal state from one module or function to another.
? The manual has
just used another undefined term which is used precisely *once* in the entire
document.
So I welcome your starting to issue more technical papers on the innards and
philosophy of REBOL. And thanks too to Ladislav for prompting it. Long may it
continue!
--Best wishes,
--Colin
[21/49] from: lmecir:mbox:vol:cz at: 13-Sep-2001 22:29
Hi all,
----- Original Message -----
From: Holger Kruse <[holger--rebol--com]>
To: <[rebol-list--rebol--com]>
Sent: Thursday, September 13, 2001 2:39 AM
Subject: [REBOL] Re: Context - code included- 2nd version
> On Wed, Sep 12, 2001 at 11:26:57PM +0200, Ladislav Mecir wrote:
> > The latest version of http://www.sweb.cz/LMecir/contexts.html reflects
some
> > points made in the latest discussions.
>
> Unfortunately your major misconceptions are still in there. The
highlights:
> - Words do not "store" values,...
Would you like to change it to: "...words represent values...", "values are
represented by words..." [RCUG 2.3 p. 3-13], or something different?
...snip...
> The properties of word! (and lit-word!,
> set-word!, get-word!) are, precisely, a reference to the context the
word is bound
> to (if any) and its spelling.
I like the notion of Spelling.
...snip...
> - There is no "Special Context" and there are no "Special Words". What you
call
> a "Special Word" is in reality a word not bound into a context.
You are contradicting yourself above, aren't you? In the first sentence you
are telling that there are no "Special Words" and in the second one you are
telling, that you call them "words not bound into a context".
As to whether the "Special Context" exists: here you are making the same
mistake. Because you admit that the words ("words not bound into a context")
exist, the collection of such words exists too. The only point you can make
is, that the collection specified is not a context. But, that is again a big
trouble, because I found out, that every "word not bound to any context" is
actually bound to the Special Context (to translate it to your terminology:
has got a reference, that is the same as the reference that any other "word
not bound to any context" has).
> - Your distinction between local, global, special etc. words is a little
> confusing, mostly because "Loaded Word" is orthogonal to the other
definitions.
> It refers to the existance of a word in the global context, whereas all
the
> other definitions refer to the binding of an individual word.
The notion of "Loaded Word" is indeed incoherent with the other notions I
used. It served well as an illustrative example of an incoherent notion,
which was its main use.
> Better, more consistent with the documentation (not to mention
implementation):
> Replace "Special Word" with "word not bound into a context".
> Replace "Loaded Word" with "word which exists in the global context".
> Replace "Global Word" with "word bound into the global context".
> Replace "Local Word" with "word bound into a non-global context".
>
> These are the major problems with your document. A lot of the complexity
and many
> of the individual observations you made seem interesting and significant
only because
> your somewhat arbitrary definitions obscure the actual meaning. Once those
terms
> are replaced by their meanings most observations follow logically and
become
> redundant.
This is a legitimate POV, of course. I am motivated by those, who don't
think that the "replacement of the terms" is enough to be able to understand
the rules of the game.
...snip...
> - Aliases are not properties of contexts and therefore do not show up in
> visualizations of contexts. That's because aliases are global, not local
> per context.
This is an explanation of the phenomena, but I woudn't understand it without
seeing an illustrative Rebol code sample.
> - Scoping: REBOL uses lexical scoping, not dynamic scoping, but allows
words
> to be rebound during block evaluation. That's how words can refer to
different
> contexts even though their scope is lexical. "Scope hierarchies" imply
some
> kind of tree, which does not exist, so using that term is probably a bad
idea.
> Calling a scope hierarchy "virtual" is yet another definition which
obscures
> facts rather than illustrates them.
I don't like the notion of scope hierarchy too. The only problem with it is,
that there are some who are asking: "How come, that I see the scope
hierarchy and you are telling there is none?" I too wanted to tell them that
the scope hierarchy didn't exist in Rebol and the behaviour they were seeing
was just a result of a different mechanism, i.e. it was not the real thing,
it just looked so (a virtual thing).
> The facts are: words live inside of blocks.
I would add: not always. In Rebol it is possible to create words that don't
live inside of blocks
.
> When a block is created all words
> in it are either bound into a context, or remain unbound. Certain
functions
> ('use etc.) change the binding of words. That is all there is to it, and
the
> "scope" of a word at any given time is simply determined by the last
bind
> operation on it before the word gets evaluated.
This is correct but misleading, if you don't define the notion of "the last
bind operation" and what you mean by scope.
> - The "bug" you described when combining 'use with functions and other
contexts
> is not a bug. It is intentional.
I admit that it may be a bit unfair to call it a "bug".
> There are only four ways how a function can
> (theoretically) access its local variables and arguments, in any
language:
> - Using a hidden context pointer. That's what C does, using the stack
pointer.
> REBOL does not (and cannot) do it, because the only local environment
REBOL
> has when executing a function body is that particular function body,
which is
> a simple block, and the association from a function to its block is
one-way (like
> all references in REBOL). This means the function body has no hidden
reference
> back to the function itself, and therefore cannot access its
arguments.
> - By creating a completely new "environment" for each function. That
includes
> a new argument and variable space (context) AND a new function body
(deep-copied).
> This way all words in the function body can be rebound into the new
context.
> That's what your 'cfunc does, but it is unacceptable performance-wise.
Yes, the CFUNC-generated functions are performance-wise unacceptable for
some uses. The performance of CFUNC-generated functions might become more
satisfactory if it were implemented natively using a highly optimized
algorithm. OTOH, in that case the performance might be even better than the
performance of the functions generated by FUNC now.
> - By keeping a single function body for all function invocations, and
dynamically
> rebinding it to a different context, one for each invocation, every
time a
> function is called or returns. This generates O(n) complexity for each
function
> call, where n is the size of the function, i.e. performance is
prohibitive as
> well for large functions, and it has other practical problems.
>
> - By keeping a single function body for all function invocations, bound
to the
> same context, and changing the context on the fly (i.e. exchanging the
> "value" part of the name-value table for each function call, using a
virtual
> stack). This is what REBOL does. The "bug" you describe is a normal
and
> inevitable side effect of this, and not a "bug" at all. Your "fix"
changes the
> function execution model in a way that generates unacceptable
performance.
> If you really need the behavior you describe then you are, of course,
free to
> write your own functions which implement it, as you have done, but for
performance
> reasons that behavior should not be the default in REBOL.
>
> - The drawback you describe in regard to what you call the Dynamic
Recursion Path
> is actually caused by the fact that the context of the outer function
remains
> intact (indefinite extent) AND retains its values after the outer
function
> returns (for non-recursive function invocations), under certain
circumstances.
> This is an implementation detail you should not rely on, because it is
likely to
> change in future versions, i.e. there is a good chance that in the
future after
> a (non-recursive) function invocation the values of that function's
context are
> set to unset!. This would break the way your inner function references
the
> outer function's arguments after the outer function has returned.
That might be an improvement, because it may increase effectivity (garbage
collection) and safety, exactly as you are saying below. OTOH I know, that
there is a way how to implement Rebol, improve the performance and have the
closures as the default behaviour.
> The problem with function contexts keeping their values after the
function returns
> is that the referenced values do not get garbage-collected, even though
no (apparent)
> reference exists any more, until the function is called again. In some
situations
> (e.g. when trying to close and garbage-collect an unreferenced port)
this can be very
> problematic.
>
> Relying on the values of a function's context beyond the life time of
the corresponding
> function call should be considered illegal, i.e. you need to, e.g.,
'reduce the body of your
> inner function so the argument gets replaced by its value before the
function is returned.
> This also resolves the drawback you mentioned, i.e. use
>
> f: func [x] [func [] reduce [x]]
>
> and the behavior is as expected and compatible with future versions.
>
> --
> Holger Kruse
> [holger--rebol--com]
>
Cheers
Ladislav
[22/49] from: holger:rebol at: 13-Sep-2001 14:33
On Thu, Sep 13, 2001 at 10:29:49PM +0200, Ladislav Mecir wrote:
> Would you like to change it to: "...words represent values...", "values are
> represented by words..." [RCUG 2.3 p. 3-13], or something different?
Neither, actually, because both wordings imply a static reference, which does
not exist.
You have to distinguish between explanations intended for beginners, and
explanations that are suitable for the kind of technical discussion we are
having. For instance the User's Guide also refers to "variables", even though
there is no such thing in REBOL. REBOL does not have variables as a concept
by itself, but variables in other languages are really just dynamic name-value
mappings, and you can get a similar effect in REBOL by binding a word into a
context and 'set'ting a value for it in that context. You should not take all
explanations too literally, in particular not if explanations are intended to
explain complex concepts in easy terms.
There is also the problem that the word "word" is not always used consistently.
What does the word 'word' mean ?
Hi, Bill :). Sometimes people use "word" when
they just refer to a spelling, other times when they refer to a particular value
of the type word! inside of some block series. In the former case the "word" does
not represent a value, in the latter it might, indirectly, if you want to look at
it that way. It is still a somewhat unnatural point of view though, somewhat like
claiming that a function "represents a value" when it really "returns a value".
> > - There is no "Special Context" and there are no "Special Words". What you
> call
> > a "Special Word" is in reality a word not bound into a context.
>
> You are contradicting yourself above, aren't you? In the first sentence you
> are telling that there are no "Special Words" and in the second one you are
> telling, that you call them "words not bound into a context".
You can always make up some arbitrary definition. By "there is no" I mean
that your definition is neither necessary nor, IMHO, useful. You might
just as well define the class of all "Cool Words" to be words that start
with the letter "c". I would claim "there are no Cool Words", and you would
come back claiming "I can create words starting with the letter 'c', so there
are 'Cool Words'". This is not getting us anywhere.
> As to whether the "Special Context" exists: here you are making the same
> mistake. Because you admit that the words ("words not bound into a context")
> exist, the collection of such words exists too.
Yes, and the "Cool Context" is the context of all "Special Words" starting
with the letter "c" ??? The "Special Context" is an arbitrary definition not
backed up by observation or implementation.
Plus, in this specific instance, your definition is not just redundant, but
actually conflicting, because a context is, by definition, a name-value
mapping, and unbound words do not (and CANNOT) have any value, so they cannot
belong to any context. Introducing a "Special Context" with different rules
than all other contexts (word without values) just so you can call it a
context
is Very Bad Science.
> The only point you can make
> is, that the collection specified is not a context. But, that is again a big
> trouble, because I found out, that every "word not bound to any context" is
> actually bound to the Special Context (to translate it to your terminology:
> has got a reference, that is the same as the reference that any other "word
> not bound to any context" has).
No, it is not bound anywhere. That's why you cannot assign a value to it.
'set on an unbound word results in an error.
I don't know what you mean by "has a reference". If a word is bound into a
context then that word references the context (indefinite extent), and the
name-value table of the corresponding context lists the spelling of that word
in its "name" column. An unbound word does not reference any context, and no
context necessarily lists the spelling of that word.
> > The facts are: words live inside of blocks.
>
> I would add: not always. In Rebol it is possible to create words that don't
> "live inside of blocks".
If you want to be really precise then replace "block" with "block series":
every single word in REBOL, without exception, exists inside of a block series.
Always.
> > When a block is created all words
> > in it are either bound into a context, or remain unbound. Certain
<<quoted lines omitted: 6>>
> This is correct but misleading, if you don't define the notion of "the last
> bind operation" and what you mean by scope.
last
in a temporal sense, "scope" in its usual meaning.
--
Holger Kruse
[holger--rebol--com]
[23/49] from: greggirwin:starband at: 13-Sep-2001 16:43
<< Would you like to change it to: "...words represent values...", "values
are
represented by words..." [RCUG 2.3 p. 3-13], or something different? >.
How about "...words refer to values..."?
--Gregg
[24/49] from: lmecir:mbox:vol:cz at: 14-Sep-2001 0:40
Lots of comments:
you don't have to agree or understand. I am sorry if I made you think
otherwise.
> 1)
> "Message ID: not-defined
> A word used was not defined within any context.
> Message:
> [:arg1 "is not defined in this context"]"
>
> Tell me how you can explain the word "any". When a word is in a context,
only
> that context can give a definition to the word, so why to speak of "any"
> others contexts?
The above formulation isn't mine. What I see is, that it looks very
confusing. A code sample:
spc: first to block! "rebol"
error? get/any spc
** Script Error: rebol is not defined in this context
** Where: halt-view
** Near: error? get/any spc
If you don't tell me, what does the "any" mean in this case, I don't know.
> 2) "A variable refers to a specific value only within a defined context,"
p.
> 2-9
>
> So when it doesn't "refers to a specific value" (=get fails SpecialWord) it
> is not "within a defined context"
>
I show you another example of the same reasoning:
I am sleeping only if I am in my bed.
- true, at least for me
So when I am not "sleeping" I am not "in my bed" - false 8^)
...snip...
> 4) "The scope of a variable is determined when its context is defined."
> Ergo: context of a word can be undefined.
No, wrong reasoning again:
Zero is equal to zero when one is equal to one.
Ergo: one can be not equal to one.
...snip...
> 8)"A variable refers to a specific value only within a defined context,
such
> as a block,
> a function, or an entire program. Outside that context the variable can
refer
> to some
> other value or to no value at all."
The above sentence I read as: "a block can be a context" or "a function can
be a context" or "an entire program can be a context". Highly confusing.
...snip...
> A word is a variable if it has a value, and it has a value if is defined
in a
> context. Outside a context the word can have a value if is defined in
another
> context, or it can have no value and in this case is "not defined within
any
> context".
Incorrect.
> So my functions could become (restricting the use of word "symbol"):
>
> variable?: binded? ...
> symbol?: not binded? ...
I am sure that you either haven't understood the text or that the text has
confused you. The meaning of it is, that you have got two ways how you can
use any word:
1) use it as a symbol
2) use it as a variable
[25/49] from: lmecir:mbox:vol:cz at: 14-Sep-2001 2:07
Hi,
----- Original Message -----
From: Holger Kruse <[holger--rebol--com]>
To: <[rebol-list--rebol--com]>
Sent: Thursday, September 13, 2001 11:33 PM
Subject: [REBOL] Re: Context - code included- 2nd version
> On Thu, Sep 13, 2001 at 10:29:49PM +0200, Ladislav Mecir wrote:
>
> > Would you like to change it to: "...words represent values...", "values
are
> > represented by words..." [RCUG 2.3 p. 3-13], or something different?
>
> Neither, actually, because both wordings imply a static reference, which
does
> not exist.
Then, what easily reversible (by "reversible" is meant that it can describe
a relation between a word and a value and, vice versa, its reversed version
can describe a relation between a value and a word) wording using less than
eight words not implying a static reference is available?
> Plus, in this specific instance, your definition is not just redundant,
but
> actually conflicting, because a context is, by definition, a name-value
> mapping
So, are you telling that I should change the definition of the context
notion to reflect that it should be a name-value mapping?
> > > The facts are: words live inside of blocks.
> >
> > I would add: not always. In Rebol it is possible to create words that
don't
> > "live inside of blocks".
>
> If you want to be really precise then replace "block" with "block series":
> every single word in REBOL, without exception, exists inside of a block
series.
> Always.
I am not sure I understand the meaning of that.
Cheers
Ladislav
[26/49] from: holger:rebol at: 13-Sep-2001 17:40
On Fri, Sep 14, 2001 at 02:07:22AM +0200, Ladislav Mecir wrote:
> Then, what easily reversible (by "reversible" is meant that it can describe
> a relation between a word and a value and, vice versa, its reversed version
> can describe a relation between a value and a word) wording using less than
> eight words not implying a static reference is available?
Technically, the relation is only from the word to the value, not the other
way around. No reference is possible from a value to a word that evaluates to
that value.
> So, are you telling that I should change the definition of the context
> notion to reflect that it should be a name-value mapping?
Yes, as others have advised you. The values bound words evaluate to
are kept in contexts, not in words.
--
Holger Kruse
[holger--rebol--com]
[27/49] from: lmecir:mbox:vol:cz at: 14-Sep-2001 11:53
Hi,
----- Original Message -----
From: Holger Kruse <[holger--rebol--com]>
To: <[rebol-list--rebol--com]>
Sent: Friday, September 14, 2001 2:40 AM
Subject: [REBOL] Re: Context - code included- 2nd version
> On Fri, Sep 14, 2001 at 02:07:22AM +0200, Ladislav Mecir wrote:
>
> > Then, what easily reversible (by "reversible" is meant that it can
describe
> > a relation between a word and a value and, vice versa, its reversed
version
> > can describe a relation between a value and a word) wording using less
than
> > eight words not implying a static reference is available?
>
> Technically, the relation is only from the word to the value, not the
other
> way around. No reference is possible from a value to a word that evaluates
to
> that value.
Nobody objected against the formulation Gregg offered, so I think, that the
following formulations/reversed formulations should be acceptable:
Word can be used to refer to a value
<=> "Value can be referred to by a
Word"
Word refers to a value
<=> "Value is referred to by a Word"
I
[28/49] from: rotenca:telvia:it at: 14-Sep-2001 18:46
> Lots of comments:
>
> you don't have to agree or understand. I am sorry if I made you think
> otherwise.
No, no. Don't worry! I know.
...
> > Tell me how you can explain the word "any". When a word is in a context,
> only
> > that context can give a definition to the word, so why to speak of "any"
> > others contexts?
>
> The above formulation isn't mine. What I see is, that it looks very
> confusing. A code sample:
It is from Core. Your explanation: "is confusing". It seems to me that when
something is againts your ideas, "it is confusing" ;-)
> spc: first to block! "rebol"
> error? get/any spc
> ** Script Error: rebol is not defined in this context
> ** Where: halt-view
> ** Near: error? get/any spc
>
> If you don't tell me, what does the "any" mean in this case, I don't know.
Too many parts of Rebol doc is confusing or meaningless for you.
Can be true, but is seems strange to me.
> > 2) "A variable refers to a specific value only within a defined context,"
> > So when it doesn't "refers to a specific value" (=get fails
<<quoted lines omitted: 3>>
> "I am sleeping only if I am in my bed." - true, at least for me
> So when I am not "sleeping" I am not "in my bed" - false 8^)
You read it as a->b, but i read it as a<->b, so: not a -> not b.
In this context, i think that the right interpretation is mine, your is
possible. If we get yours, we have:
a->b
not a
= b undefined
i.e
if a word doesn't refers to a value we can not know if it is "within" a
context (or its context is undefined).
But you say that we can know, just failing to to get the value of word, the
context of a words:
special? : error? try [error? get/any :word]
Obviously, one of two is incorrect.
> ...snip...
> > 4) "The scope of a variable is determined when its context is defined."
>
> > Ergo: context of a word can be undefined.
>
> No, wrong reasoning again:
>
> "Zero is equal to zero when one is equal to one."
If you use "when" in the usual sense (i must see the context) and i have
reason to trust you, i must think that you think that "one is not always equal
to one". It is not true for me, but it seems that you think that. I can't
exclude this only because i've a different idea. I can't think that you speak
confusingly all the time you do not express my same convintions. It seems that
you think that it is POSSIBLE that one it is not one.
At least one statement of doc affirms that a word is "not defined within any
context" so i have understand that "when"
in the right sense.
...
> The above sentence I read as: "a block can be a context" or "a function can
> be a context" or "an entire program can be a context". Highly confusing.
Not so clear. But read it in the Context! :-)
> > context. Outside a context the word can have a value if is defined in
> another
> > context, or it can have no value and in this case is "not defined within
> any
> > context".
>
> Incorrect.
I forget Mecir Contexts :-)
> > So my functions could become (restricting the use of word "symbol"):
> >
<<quoted lines omitted: 5>>
> 1) use it as a symbol
> 2) use it as a variable
No, i'm not confused:
you can not succesfully use a word as variable if, for that word, the function
symbols? return TRUE:
Proof:
> spc: first to block! "rebol"
>symbol? spc
==true
> error? get/any spc
> ** Script Error: rebol is not defined in this context
> ** Where: halt-view
> ** Near: error? get/any spc
What i want to say:
1) variable?: binded? : this word can be used BOTH as variable and as symbol
2) symbol?: not binded? not variable?: this word can't be used as variable
(without trasforming it in a variable with binding) but it can be used as a
symbol.
Beyond all, i think that your observation #9 is the problem.
You should say: bind has a bug.
AUT Mecir Context <> Rebol Context AUT bind has a bug (XOR :-)).
You do not say that bind as a bug, ergo...
Changing argument: there a reason for which bind doesn't bind to get-words and
set-words? Sometime we have of context only that type of word, and i do not
know a method to trasfom them in word! preserving binding.
To end here it is some very little suggestions for your s-c? (argument and
reading):
same-context?: func [
{
find out, if the given Words
are bound to the same Context
}
word1 [word!]
word2 [any-word!] ;<<<<<<
] [
found? any [
all [
special? word1
special? word2
]
all [
not special? word1
same? word2 first bind to-block mold word2 word1 ;<<<<<<
]
]
]
I hope it is correct.
---
Ciao
Romano
[29/49] from: g:santilli:tiscalinet:it at: 14-Sep-2001 22:38
Hello Ladislav!
On 14-Set-01, you wrote:
LM>> every single word in REBOL, without exception, exists
LM>> inside of a block series.
LM>> Always.
LM> I am not sure I understand the meaning of that.
Can you give me an example of a word that is not in a "block
series"?.
Notice that:
to-word "a"
places 'A in system/words.
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[30/49] from: g:santilli:tiscalinet:it at: 14-Sep-2001 22:42
Hello Holger!
On 14-Set-01, you wrote:
HK> Technically, the relation is only from the word to the value,
HK> not the other way around. No reference is possible from a
HK> value to a word that evaluates to that value.
Well, other than:
>> a: 1
== 1
>> pick first system/words index? find second system/words 1
== a
:-)
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[31/49] from: g:santilli:tiscalinet:it at: 14-Sep-2001 22:13
Hello Ladislav!
On 13-Set-01, you wrote:
Some cents from me...
LM> You are contradicting yourself above, aren't you? In the
LM> first sentence you are telling that there are no "Special
LM> Words" and in the second one you are telling, that you call
LM> them "words not bound into a context".
It depends on the meaning you give to the word "special". If I
read "Special Word" I think of a word that is different from
Normal Words
; your special word is, instead, a word with its
context attribute set to null (or none, if you prefer :).
LM> ("words not bound into a context") exist, the collection of
LM> such words exists too. The only point you can make is, that
The fact that you can collect something does not mean that the
collection exists. You could collect all the gold in the world,
but does the collection of all the gold in the world exist? Again,
it depends on the meaning of the word "exist". For an explanation
to be easily understandable, words should be used with their
common meaning, or it should be stated that they are being used
with some different meaning.
Your "Special Context" has no attributes or properties. I don't
find it useful, but this is of course only MHO.
LM> Context (to translate it to your terminology: has got a
LM> reference, that is the same as the reference that any other
LM> "word not bound to any context" has).
I see your point, but the notion of "no context" seems to me
simpler and more understandable (i.e. less confusing) than the
notion of "special context".
LM> This is a legitimate POV, of course. I am motivated by those,
LM> who don't think that the "replacement of the terms" is enough
LM> to be able to understand the rules of the game.
Of course you are right. But isn't it better to use terms that are
easier to understand and require less definitions and
explanations?
LM> Yes, the CFUNC-generated functions are performance-wise
LM> unacceptable for some uses. The performance of
LM> CFUNC-generated functions might become more satisfactory if
LM> it were implemented natively using a highly optimized
LM> algorithm. OTOH, in that case the performance might be even
LM> better than the performance of the functions generated by
LM> FUNC now.
I still tend to think that not having to do anything is faster
than having to do something (i.e. rebinding, or just creating a
new context). With the current implementation the programmer has
the choice.
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[32/49] from: lmecir:mbox:vol:cz at: 15-Sep-2001 1:06
----- Original Message -----
From: Gabriele Santilli <[g--santilli--tiscalinet--it]>
To: <[rebol-list--rebol--com]>
Sent: Friday, September 14, 2001 10:42 PM
Subject: [REBOL] Re: Context - code included- 2nd version
> Hello Holger!
> On 14-Set-01, you wrote:
<<quoted lines omitted: 9>>
> Regards,
> Gabriele.
Actually I meant a more natural thing:
Formulation (word -> value):
To set a Rebol word to refer to a Rebol value we can...
Reverse formulation (value -> word):
To get a Rebol value referred to by a Rebol word we can...
[33/49] from: lmecir:mbox:vol:cz at: 15-Sep-2001 0:29
Hi,
> Changing argument: there a reason for which bind doesn't bind to get-words
and
> set-words? Sometime we have of context only that type of word, and i do
not
> know a method to trasfom them in word! preserving binding.
RT didn't provide such a function.
> To end here it is some very little suggestions for your s-c? (argument and
> reading):
<<quoted lines omitted: 21>>
> Ciao
> Romano
It is a feasible idea, but it contains bugs that would prevent it to work. I
have got a more or less working implementation and will include it to the
next version of http://www.sweb.cz/LMecir/contexts.html
[34/49] from: lmecir:mbox:vol:cz at: 15-Sep-2001 0:58
> I still tend to think that not having to do anything is faster
> than having to do something (i.e. rebinding, or just creating a
> new context).
The problem is with that "not having to do anything", because the
interpreter does a lot of (invisible but showing itself in the benchmarks)
work.
[35/49] from: lmecir:mbox:vol:cz at: 15-Sep-2001 0:40
> Hello Ladislav!
> On 14-Set-01, you wrote:
<<quoted lines omitted: 9>>
> Regards,
> Gabriele.
See this:
ud: first to block! "foo"
recycle
probe ud ; == foo
ls: make list! 1
append ls ud
unset ud
recycle
It may still be considered true, but it was unclear to me.
[36/49] from: g:santilli:tiscalinet:it at: 15-Sep-2001 14:00
Hello Ladislav!
On 15-Set-01, you wrote:
LM> The problem is with that "not having to do anything", because
LM> the interpreter does a lot of (invisible but showing itself
LM> in the benchmarks) work.
Other than placing the arguments' values in the function context?
Since I didn't do any serious benchmark I'd like to see yours and
your results, if that is possible. (Some QAD tests I did seem to
show that REBOL does not do more than setting the values in the
context...)
Also, I hope Holger wants to shed some light over this. :)
Regards,
Gabriele.
--
Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer
Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[37/49] from: rotenca:telvia:it at: 15-Sep-2001 21:06
> > To end here it is some very little suggestions for your s-c? (argument and
> > reading):
<<quoted lines omitted: 25>>
> >
> It is a feasible idea, but it contains bugs that would prevent it to work. I
What bug? Please, can you make an example?
---
Ciao
Romano
[38/49] from: lmecir:mbox:vol:cz at: 15-Sep-2001 21:41
> > It is a feasible idea, but it contains bugs that would prevent it to
work.
same-context?: func [
{
find out, if the given Words
are bound to the same Context
}
word1 [word!]
word2 [any-word!] ;<<<<<<
] [
found? any [
all [
special? word1
special? word2
]
all [
not special? word1
same? word2 first bind to-block mold word2 word1 ;<<<<<<
]
]
]
> What bug? Please, can you make an example?
>
> ---
> Ciao
> Romano
>
e.g.:
same-context? 'a first [a:]
but that is not the only bug
[39/49] from: lmecir:mbox:vol:cz at: 16-Sep-2001 10:06
Hi all,
just posted the latest version of http://www.sweb.cz/LMecir/contexts.html
with terminological changes reflecting Holger's recommendations. Moreover,
the CFUNC implementation it contains doesn't rely on the values of function
context words after the function returns.
some differences:
> Replace "Special Word" with "word not bound into a context".
This surely is more accurate than the notion of "undefined word", but It
would make the text less concise than I considered acceptable
> Replace "Loaded Word" with "word which exists in the global context".
Removed the notion completely, used a different notion of
effective/ineffective binding
> Replace "Global Word" with "word bound into the global context".
I preferred conciseness in this case
> Replace "Local Word" with "word bound into a non-global context".
Again I preferred conciseness, because it didn't seem to introduce any
ambiguities
> - The global context expands automatically as new words are bound into it.
> The fact that this increases the number of "Loaded Words" is redundant
> (again, result of obscure terminology).
Accepted
> - Scoping: REBOL uses lexical scoping, not dynamic scoping, but allows
words
> to be rebound during block evaluation. That's how words can refer to
different
> contexts even though their scope is lexical. "Scope hierarchies" imply
some
> kind of tree, which does not exist, so using that term is probably a bad
idea.
> Calling a scope hierarchy "virtual" is yet another definition which
obscures
> facts rather than illustrates them.
Accepted
[40/49] from: rotenca:telvia:it at: 16-Sep-2001 12:48
> > > It is a feasible idea, but it contains bugs that would prevent it to
> work.
I've read your new implementation of Contexts. Now it is more near to Core
Doc. Must re-read it in the next days.
For now (but you have abandoned Loaded idea):
1) I prefer this for a pratical reason: it doesn't change the global context:
gen-bind: func [
{Binds WORD to a specified context.}
word {A value to bind.}
known-word [word!] {A sample word from the target context.}
] [
first bind to-block mold :word known-word
]
2) My new s-c? This could change the GC but it is very concise. I have another
which doen't change the Gc but it is more long. Is this bug Free?
same-context?: func [
{
find out, if the given Words
are bound to the same Context
}
word1 [any-word!]
word2 [word!]
] [
found? any [
all [
undefined? word2
undefined? :word1
]
all [
not special? word2
same? :word1 gen-bind to-word :word1 word2
]
]
]
Thank you for your attention to my bad code.
---
Ciao (my english is bad)
Romano
[41/49] from: lmecir:mbox:vol:cz at: 16-Sep-2001 13:48
Hi Romano,
> I've read your new implementation of Contexts. Now it is more near to Core
> Doc. Must re-read it in the next days.
> For now (but you have abandoned Loaded idea):
I accepted Holger's suggestion.
> 1) I prefer this for a pratical reason: it doesn't change the global
context:
> gen-bind: func [
> {Binds WORD to a specified context.}
<<quoted lines omitted: 3>>
> first bind to-block mold :word known-word
> ]
As far as I know my definition of GEN-BIND doesn't change the Global
Context. (If your findings are different, post an example, please.)
Moreover, your implementation has got a "hole" :
word: to word! "nonsense:" ; == nonsense:
type? word ; == word!
type? first to block! mold :word ; == set-word!
> 2) My new s-c? This could change the GC but it is very concise. I have
another
> which doen't change the Gc but it is more long. Is this bug Free?
same-context?: func [
{
find out, if the given Words
are bound to the same Context
}
word1 [any-word!]
word2 [word!]
] [
found? any [
all [
undefined? word2
undefined? :word1
]
all [
not special? word2
same? :word1 gen-bind to-word :word1 word2
]
]
]
No, it isn't. It resembles one of my older implementations, but it doesn't
yield the correct result e.g. in this case:
word1: 'word1
word2: use 'word2 ['word2]
> Ciao (my english is bad)
> Romano
Ciao (neither my english is perfect)
Ladislav
[42/49] from: rotenca:telvia:it at: 16-Sep-2001 14:17
> Hi Romano,
Hi, Ladislav
> I accepted Holger's suggestion.
Almost all :-)
> Moreover, your implementation has got a "hole" :
>
> word: to word! "nonsense:" ; == nonsense:
> type? word ; == word!
> type? first to block! mold :word ; == set-word!
I know it. I wanted just to ask to explain this thing:
probe to word! ":a:"
==:a:
>> probe to block! ":a:"
** Syntax Error: Invalid word -- :a:
** Near: (line 1) :a:
Is it a bug of to-word!, or i don't understand something?
> No, it isn't. It resembles one of my older implementations, but it doesn't
> yield the correct result e.g. in this case:
>
> word1: 'word1
> word2: use 'word2 ['word2]
Now i'll check code, but yours last published function get the right result?
---
Ciao (my english is bad)
Romano
[43/49] from: rotenca:telvia:it at: 16-Sep-2001 14:20
> word1: 'word1
> word2: use 'word2 ['word2]
It seems to me that 'word2 in the use block remains global. An use bug? Or i'm
wrong?
Ciao (my english is bad)
Romano
[44/49] from: rotenca:telvia:it at: 16-Sep-2001 14:41
> As far as I know my definition of GEN-BIND doesn't change the Global
> Context. (If your findings are different, post an example, please.)
I was wrong.
---
Ciao
Romano
[45/49] from: lmecir:mbox:vol:cz at: 16-Sep-2001 14:57
> > word1: 'word1
> > word2: use 'word2 ['word2]
>
> It seems to me that 'word2 in the use block remains global. An use bug? Or
i'm
> wrong?
Indeed, it looks as a bug. I thought that
use 'word2 ['word2]
and
use [word2] ['word2]
should yield the same result, but they apparently don't.
> Ciao (my english is bad)
> Romano
>
Ciao
Ladislav
[46/49] from: lmecir:mbox:vol:cz at: 16-Sep-2001 14:53
Hi Romano,
> > Moreover, your implementation has got a "hole" :
> >
<<quoted lines omitted: 8>>
> ** Near: (line 1) :a:
> Is it a bug of to-word!, or i don't understand something?
The problem is, that TO WORD! or MAKE WORD! can create some "artificial"
words that the Rebol parser normally recognizes as different datatypes. We
may consider that to be an "advantage" or a "disadvantage", but RT can claim
it to be a feature, not a bug.
> > No, it isn't. It resembles one of my older implementations, but it
doesn't
> > yield the correct result e.g. in this case:
> >
> > word1: 'word1
> > word2: use 'word2 ['word2]
>
> Now i'll check code, but yours last published function get the right
result?
> ---
> Ciao (my english is bad)
> Romano
Hmm, i didn't check it, but it really differs from:
word1: 'word1
word2: use [word2] ['word2]
and I don't know why.
Ciao
Ladislav
[47/49] from: joel:neely:fedex at: 16-Sep-2001 3:14
Hi, Ladislav, Romano, et al,
Ladislav Mecir wrote:
...
> >
> > Is it a bug of to-word!, or i don't understand something?
<<quoted lines omitted: 3>>
> "advantage" or a "disadvantage", but RT can claim it to be
> a feature, not a bug.
Might I suggest that this is not very different from
>> foo: load "42" == 42
>> type? foo == integer!
>> foo: to-decimal "42" == 42
>> type? foo == decimal!
>> foo: to-word "42" == 42
>> type? foo == word!
in that the "default" lexical scanning of a string involves
syntax rules which REBOL uses to determine what datatype the
string should be translated (LOADed) into. However, REBOL
gives us the ability to override those defaults and force
differently-typed values to be created instead.
-jn-
--
------------------------------------------------------------
Programming languages: compact, powerful, simple ...
Pick any two!
joel'dot'neely'at'fedex'dot'com
[48/49] from: rotenca:telvia:it at: 16-Sep-2001 20:30
> Hi, Ladislav, Romano, et al,
Hi, Joe, Ladislav et al,
> Might I suggest that this is not very different from
> >> foo: load "42" == 42
<<quoted lines omitted: 3>>
> >> foo: to-word "42" == 42
> >> type? foo == word!
Strange but understable. Core Guide don't say that "42" is an invalid word.
What i don't understand is this: Core guide says:
Words are not case sensitive and can include hyphens and a few other special
characters such as +, -, ', *, !, ~, &, ., and ?.
...
The following characters are not allowed in words:
@#$%^,
This is false:
>> bind to word! "#" 'system
== #
>> #: 3
== 3
Here it is a Global word. But then when you try to get the value of # Rebol
says: what dou you want? that is an issue!
But what check the interpreter? The datatype of a value or its molded value?
It is not clear.
And also:
The end of a word is indicated by a space, a line break, or one of the
following
characters:
[](){}
:;/"
This is false also. Surely for ":" i did not check others.
This strange behaviour is only of word! ?
I try to datatype! to block! but here controls seem to me more strict.
---
Ciao
Romano
[49/49] from: joel:neely:fedex at: 16-Sep-2001 11:16
again, Romano,
Romano Paolo Tenca wrote:
> > Hi, Ladislav, Romano, et al,
> Hi, Joe, Ladislav et al,
<<quoted lines omitted: 8>>
> Strange but understable. Core Guide don't say that "42"
> is an invalid word.
Actually, it does... In the on-line version of RCUG (the
quickest one for me to check), section 5.1 "Word Names",
begins with the statements:
Words are composed of alphabetic characters, numbers [sic],
and any of the following characters:
? ! . ' + - * & | = _ ~
A word cannot begin with a number [sic], and there are
also some restrictions on words that could be interpreted
as numbers. For example, -1 and +1 are numbers, not words.
(Note that the document confuses the distinction between
numbers and digits. This, unfortunately, is a warning of
things to come...) It seems clear that "42" will not be
recognized as a word name because it begins with a digit.
> What i don't understand is this: Core guide says:
> "Words are not case sensitive and can include hyphens and
<<quoted lines omitted: 3>>
> "The following characters are not allowed in words:
> @#$%^,"
Let me try another variation on the analogy. If the sequence
of characters "12.0" (without the quotation marks!) appears
in a script, REBOL will assume it should translate that
sequence of characters into a DECIMAL! value because of the
presence of the dot, even though you can over-rule that
interpretation yourself:
>> glorp: load "12." == 12
>> type? glorp == decimal!
>> glump: to-integer "12." == 12
>> type? glump == integer!
>> equal? glorp glump == true
LOAD uses the standard rules, and therefore creates a DECIMAL!
value. If you intervene, however, you can force the creation
of an INTEGER! value, even though integers normally don't
contain dots in their textual representation.
The statements you quoted above from RCUG are really talking
about the standard rules by which REBOL translates text into
internal values. They don't mean that that you can't override
the normal assumptions and force REBOL to create values (e.g.
words) out of something that doesn't follow the standard rules.
Even though the standard lexical scanning rules for REBOL are
that something starting with an octothorp ("#") will not be
translated into a WORD! value, you can force REBOL to create
such a word, as your example below illustrates:
> >> bind to word! "#" 'system
> == #
> >> #: 3
> == 3
>
We can expand this example of explicit over-riding:
>> trick: reduce [to set-word! "#" 35]
== [#: 35]
>> do trick
== 35
>> get to-word "#"
== 35
>> get '#
** Syntax Error: Invalid word -- '#
** Near: (line 1) get '#
>> get to-lit-word "#"
== 35
As you correctly point out, once the rules are broken, it
can become very confusing to follow what's going on.
> But then when you try to get the value of # Rebol says:
> what dou you want? that is an issue!
>
Because a standard usage of "#" is as the prefix of an
ISSUE! value:
>> type? #1100
== issue!
>> type? #abc
== issue!
(but not the only usage!)
> But what check the interpreter? The datatype of a value
> or its molded value? It is not clear.
>
It's simple, just hard to explain (especially in light of
the overloaded and imprecise terminology of RCUG). Let's
take an example:
>> confusion: reduce [to-set-word "%yikes" 2.54]
== [%yikes: 2.54]
>> do confusion
== 2.54
>> print %yikes
yikes
>> type? %yikes
== file!
What's happening? We forced the creation of a word whose
spelling is not "normal" because it begins with a percent
sign (normally used as a prefix to indicate file names).
Therefore, when we say PRINT %YIKES at the interactive
prompt, REBOL applies the normal rules and translates the
next thing after PRINT into a file name. In order to get
back to the word we created with the non-standard name, we
have to override the rules again...
>> print get to-word "%yikes"
2.54
Hope this helps!
-jn-
--
------------------------------------------------------------
Programming languages: compact, powerful, simple ...
Pick any two!
joel'dot'neely'at'fedex'dot'com
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted