[REBOL] Re: On list! inconsistency [was Re: WYSIWYG programming]
From: al:bri:xtra at: 3-Nov-2000 19:41
Rishi wrote:
> Hi Ladislav. I have tried to use insert the way you mentioned, but for
some reason, this does not work. I get the following error:
> Script: "Queue" (17-Oct-2000)
> ** Script Error: insert has no value.
> ** Where: insert-it: :insert
> insert: func [item [any-type!]]
>
> The interesting thing is that the method above works for any other
function I have tried (such as remove)...but not insert. It seems that you
cannot over-ride insert. I am have included my queue file with the modified
insert function the way you have described.
> Anyone know why this is? Is it a bug in rebol or am I doing something
wrong?
> q: make object! [
> list: make block! []
> insert-it: :insert
> insert: func[item [any-type!]] [insert-it list item]
What you probably didn't know, is that Rebol has seen the set-word! here:
insert:
and already assigned the value of 'insert in the make object! context to
no value
. You can get the same effect at the Rebol prompt, like this:
>> type? a_random_word_I_haven't_used_before
** Script Error: a_random_word_I_haven't_used_before has no value.
** Where: type? a_random_word_I_haven't_used_before
See how your error message is exactly like the above error?
> ** Script Error: insert has no value.
> ** Where: insert-it: :insert
Rebol, in making the object to assign to 'q, makes a context that contains
these words:
list
insert-it
insert
It does this by scanning for set-word! data-types in the block after:
make object!
so the result of evaluting this line:
insert-it: :insert
is that Rebol finds a match for 'insert in the current object's context,
and uses that for the value of:
:insert
Of course, that's an uninitialised value or "no value", so Rebol gives
the error message.
It would be nice to be able to specify a "parent" or "super" context, much
like a parent directory does, so you could write:
insert: :../insert
or perhaps better would be:
insert: :parent/insert
so as to refer to the word in the enclosing or outer context. Much like
'self is kind of a "special" value in objects. But that's a subject for a
REP, perhaps.
So to cure your problem, what you really need is, is the value of 'insert,
which can be found at:
system/words/insert
Making your q/insert function like this:
insert: func[item [any-type!]] [system/words/insert list item]
and saving the cost of:
insert-it: :insert
for each queue object.
And, BTW, wouldn't it be better to 'append rather than 'insert?
I hope that helps!
Andrew Martin
ICQ: 26227169
http://members.nbci.com/AndrewMartin/