From: Paul Guyot (pguyot_at_kallisys.net)
Date: Thu Oct 21 2004 - 02:50:13 PDT
Aux environs du 20/10/04 à 19:58 -0500, sous le titre "[NTLK] How to
change a soup entry slot?", Jaime Méndez prit sa plus belle plume
pour écrire les mots suivants:
>I wat to get a soup entry slot value. I have the slot name in a string
>varible: slotName:="name";. The entry name is "myEntry".
Why do you have the slot name as a string instead of as a symbol?
>What I do is de following:
>
>for each item, value in myEntry do
> if strEqual(item&"", slotName) then myValue:=value;
>
>It compares the string value of each slot symbol name in "myEntry" with the
>string value of the variable "slotName".
>
>It works, I do get the slot value in variable "myValue".
It's just highly unefficient.
- you can compare symbols and item is a symbol, i.e. you can do:
local slotNameSymbol := Intern(slotName);
foreach item, value in myEntry do
if item = slotName then myValue := value;
- you can avoid looping once you've found the value you've been looking for.
- you can simply access slots in frames with their name (stored in a symbol).
local myValue := myEntry.(Intern(slotName));
- If slotName was a constant, say equal to "name", you could simply do:
local myValue := myEntry.name;
- you probably could just store the symbol of the slot into slotName
instead of a string representation of it and hence do:
local myValue := myEntry.(slotName);
>The question:
>
>How do I change the slot value of "myEntry"?
>
>The following did not work:
>
>for each item, value in myEntry do
> if strEqual(item&"", slotName) then
> begin
> myEntry.item:= otherValue;
> EntryChangeXmit(myEntry,nil);
> end;
>
>It just creates an othre slot named "item" instead of changeing the slot
>with the slot labeled "name". What am I doing wrong?
item is a reference to 'name.
You can do:
myEntry.(item) := otherValue;
Or simply, without the loop:
myEntry.(Intern(slotName)) := otherValue;
Or, if slotName is a symbol:
myEntry.(slotName) := otherValue;
>I can not do this:
>
>myEntry.slotName:=otherValue;
>EntryChangeXmit(myEntry,nil);
>
>because slotName is a string variable not a symbol.
Because:
- slotName is a reference
- slotName is a reference to a string.
If slotName was a reference to a symbol, you could do:
myEntry.(slotName) := otherValue;
You can use Intern function to convert a string to a symbol.
If you wanted to use a string constant (I admit it's stupid), you could do:
myEntry.(Intern("name")) := otherValue;
Or if you really wanted to use a reference to a string, you could do:
myEntry.(Intern(slotName)) := otherValue;
Paul
-- Ministre plénipotentiaire en disponibilité. Baignoire à vendre. http://www.kallisys.com/ http://newton.kallisys.net:8080/ -- This is the NewtonTalk list - http://www.newtontalk.net/ for all inquiries Official Newton FAQ: http://www.chuma.org/newton/faq/ WikiWikiNewt for all kinds of articles: http://tools.unna.org/wikiwikinewt/
This archive was generated by hypermail 2.1.5 : Thu Oct 21 2004 - 03:30:02 PDT