Re: Getting label from a record
Re: Getting label from a record
- Subject: Re: Getting label from a record
- From: Arthur Knapp <email@hidden>
- Date: Wed, 19 Nov 2003 13:19:29 -0500
Date: Wed, 19 Nov 2003 00:13:48 +0000
Subject: Re: Getting label from a record
From: kai <email@hidden>
The subject does, however, raise an interesting point - which I may
have
touched on before. Wouldn't it be preferable if the algorithm that
produces
error messages could be harnessed to offer an *official* 'as quoted
text'
coercion from a given class to a string?...
+data PICT0000; as quoted text --> "+data PICT0000;"
{Arthur:"Knapp"} as quoted text --> "{Arthur:\"Knapp\"}"
{"Nigel", "Garvey"} as quoted text --> "{\"Nigel\", \"Garvey\"}"
Yes, yes, yes... here, here, here!!! :)
All JavaScript values have, (or inherit), a toString() and toSource()
method. They are extremely useful, both algorithmically and for
debugging.
...then consider an alternate data structure -- say, a list where the
odd
values are the labels (as strings) and the even ones are the data.
But where's the fun in <repeat with n from 1 to count l by 2>?
In fact, if one is going to use a completely list-based solution, it
is far better to actually use two lists:
set theLabels to {...}
set theValues to {...}
This allows for two special operations on theLabels:
if ( thisLabel is in theLabels ) then
-- go ahead and search for it
else
-- don't bother
end
This would be problematic with a single list, where you couldn't
guarantee that thisLabel wouldn't also be one of the values.
In a similiar vain, a seperate list allows for a "binary-contains"
search:
BinaryContains(theLabels, thisLabel)
on BinaryContains(a, v)
set av to {v}
if (av is in a) then
set l to 1
set r to a's length
repeat until a's item l = v
set m to (l + r) div 2
if (av is in a's items l thru m) then
set r to m
else
set l to m + 1
end if
end repeat
return l
else
return 0
end if
end BinaryContains
{ Arthur J. Knapp;
<
mailto:email@hidden>;
What...? Oh...!
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.