Re: Subroutine difference in script editor and project builder
Re: Subroutine difference in script editor and project builder
- Subject: Re: Subroutine difference in script editor and project builder
- From: kai <email@hidden>
- Date: Mon, 18 Aug 2003 02:57:45 +0100
on Tue, 12 Aug 2003 21:37:29 -0400, "jay" <email@hidden> wrote:
>
Why can I run this sort routine in the script editor fine
>
http://www.apple.com/applescript/guidebook/sbrt/pgs/sbrt.05.htm
>
>
but in project builder I get the error: "No result was returned from some part
>
of this expression. (-2763)"
>
>
here is my code:
>
set myList to ASCII_Sort(anotherList)
It doesn't look like anyone has responded to this yet, jay - so I'll wade in
with what I can.
I had a look at the ASCII_Sort code and it doesn't look like there's
anything there that could cause a problem. The fact that the script runs OK
in SE on both your machine and mine leads me to conclude that there might be
an issue in project builder. So (if you haven't already done so) you might
consider posting your question to the project builder-users list:
http://www.lists.apple.com/mailman/listinfo/projectbuilder-users
While checking out the ASCII_Sort script, I did notice that it wasn't
particularly fast - especially with longer lists. (Whenever I doubled the
length of a list, the time taken to execute the script increased by a factor
of more than 6.)
In view of this, you might like to try this alternative (indenting removed
to avoid line-wraps):
================
on strSort(l)
if (count l's strings) is not (count l) then
set t to text item delimiters
set text item delimiters to ASCII character 1
set l to (l as string)'s text items
set text item delimiters to t
end if
script s
property n : {l's item 1}
property p : l's rest
end script
repeat with v in s's p
if v < s's n's item 1 then
set s's n's beginning to v
else if v > s's n's item -1 then
set s's n's end to v
else
set l to 1
set h to count s's n
repeat until h is 1
set m to h div 2
if v > s's n's item (l + m) then
set h to h - m
set l to l + m
else
set h to m
end if
end repeat
set s's n to s's n's items 1 thru l & v & s's n's items (l + 1) thru -1
end if
end repeat
s's n's contents
end strSort
================
set composers to {"Ellington", "Beethoven", "Copland", "Verdi", "Prokofief",
"Borodin", "Schubert", "Bach", "Mozart", "Brahms", "Haydn", "Bernstein",
"Chopin", "Britten", "Berlioz", "Elgar", "Tchaikovsky", "Satie"}
strSort(composers)
--> {"Bach", "Beethoven", "Berlioz", "Bernstein", "Borodin", "Brahms",
"Britten", "Chopin", "Copland", "Elgar", "Ellington", "Haydn", "Mozart",
"Prokofief", "Satie", "Schubert", "Tchaikovsky", "Verdi"}
================
It's unlikely that any of this will help to resolve the error -2763 issue.
:-( However, the handler does offer significant performance gains over
ASCII_Sort - especially for longer lists. :-)
For example, the 'strSort' handler sorted a 5-item list twice as quickly as
ASCII_Sort - and was about 50 times faster than ASCII_Sort on a 200-item
list. Here are some of the figures:
------ ----------
listed ASCII_Sort
items comparison
------ ----------
5 x 2
10 x 3
25 x 5
50 x 10
100 x 20
200 x 50
------ ----------
>
Also any links to fast search routines for lists is greatly appreciated.
When you say search routines, do you mean ways of getting the position of an
item from a list? (I'm assuming you do - but apologies if I'm off-course.)
If you have a text-based list that doesn't contain return characters, then
you'll be hard pressed to beat this approach, developed by Nigel Garvey and
Emmanuel. (From memory - so stuff like variable labels may be different -
but I believe the fundamentals are there):
===============
on strPos(s, l)
set t to text item delimiters
set text item delimiters to return
set l to return & l & return
set text item delimiters to return & s & return
set p to (count l's text item 1's paragraphs) mod (count l's paragraphs)
set text item delimiters to t
p
end strPos
===============
set rainbow to {"red", "orange", "yellow", "green", "blue", "indigo",
"violet"}
strPos("green", rainbow)
--> 4
===============
However, should your list contain strings with return characters, or include
other value classes, then you might like to consider something like this:
===============
on valPos(v, l)
script s
property p : l
end script
set u to {v}
set l to 1
set h to count s's p
considering case
repeat until h is 1
set m to h div 2
if u is in s's p's items l thru (l + m - 1) then
set h to m
else
set h to h - m
set l to l + m
end if
end repeat
if v is s's p's item l then return l
end considering
0
end valPos
===============
set valList to {"aardvark", {"x", "y"}, 56, 3.8, tab, {real:pi, integer:1},
path to startup disk, date "4/4", name of item 1 of application "Finder"}
valPos({"x", "y"}, valList)
--> 2
valPos(tab, valList)
--> 5
valPos({integer:1, real:pi}, valList)
--> 6
===============
Note that, as shown in the last test example, it's the *contents* of a
record (rather than sequence of its items) that affects a match. I didn't
include examples of raw data (such as <<data utxt00680065006C006C006F>>),
but they also work OMM.
In case you need further reference, I had a quick look through the list
archives for a few recent discussions about related subjects.
For sorting lists, you might like to re-check these threads:
"Quicksort Implementation v1.0.2"
"Sorting a List Solution Revisited"
"Sorting A List - Need Help"
- And for getting the position of an item in a list:
"Get position of item in list"
"Determining item number matching "x" in a list"
---
kai
_______________________________________________
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.