Re: Best practices for creating and comparing lists of text?
Re: Best practices for creating and comparing lists of text?
- Subject: Re: Best practices for creating and comparing lists of text?
- From: CYB <email@hidden>
- Date: Fri, 16 Dec 2005 18:00:35 -0600
- Thread-topic: Best practices for creating and comparing lists of text?
Title: Re: Best practices for creating and comparing lists of text?
Hi all, this is a question for Kai who answered with a very interesting solution.
I follow this discussion, and many others, with interest and as a scripter beginner whit the hope to learn “best practices” in general, and let me tell you Kai ,I’m very impressed whit your code, I’m sure you have a lot of experience in this matter. Within a months reading this list I start to recognize some of you guys, who always write something that is interesting and I give you thanks to all for this lessons.
But I also admit that in this particular solution that you Kai, proposed I don’t understand parts of it, I spend part of the morning trying to analyze and understand it, but I’m still confuse, so as a newbie, I would like to ask you if you can explain or make more explicit parts of you code.
Assuming that you have the patience to do it:
tell t starts with "#" -- Which is the objective to do this. This is the first time I see something like this.
I understand “starts” as a containment operator (boolean) , as part of some question, but here forming a tell block, (?) I didn't catch it
if (count t) is 0 or it and (count t's paragraphs) is 1 then return {{}, {}} -- here I’m totally lost, when you say “or it and ... “ I’m not sure what represent “it” (is, in this case “t”?) and how it’s working between “or” & “and’
if it then set t to t's text from paragraph 2 to end — Here I assuming that you are asking if “it” is true?
end tell
script o
property m : t's paragraphs
property l : m's items
end script
Here, why you declare properties inside of a script object? Is not the same to do it out of it? I had never use script objects and I’m trying to learn about it.
--------------SECOND PART OF YOUR SCRIPT------------
tell m1's text items to if (count) is 1 then
set m2's end to i's contents
else
set AppleScript's text item delimiters to return
set m1 to beginning & ({""} & rest)
end if
Here you began with a tell, but there’s no end tell and..., well I don’t understand it :(
I’m sure there’s a more verbose way to do the same and would be more clear to me, but I didn’t found it. Can you do it for me? and probably for other beginners that sniff around this list?
Thanks, your help will be appreciated, and will let me be a much better scripter
Carlos Ysunza B.
Director
Ysunza/Santiago
Visual Communication • Automation
Tel. (52)55 5256-0336
email@hidden
http://www.ysunzasantiago.com
http://www.thesecretmexico.com
http://www.applescript.com.mx
I am working on two AppleScript scripting problems with text and lists that seem to be related. They also seem general enough that other people probably have invented the wheel already, and could suggest Best Practices for me.
Not too sure about Best Practices, Brian - but I'd probably start with something like the efforts below:
1) Extract text from a file whose format is like this:
# List of module names (and library names if they differ)
Modulename1
Modulename2=Libname2
Modulename3
Modulename4=Libname4
And convert the text to AppleScript lists that look something like this:
Modulenames = {"Modulename1","Modulename2","Modulename3","Modulename4"}
Libnames = {"Modulename1","Libname2","Modulename3","Libname4"}
-----------------------
to parse_lists from t
tell t starts with "#"
if (count t) is 0 or it and (count t's paragraphs) is 1 then return {{}, {}}
if it then set t to t's text from paragraph 2 to end
end tell
script o
property m : t's paragraphs
property l : m's items
end script
set n to 1
set tid to text item delimiters
set text item delimiters to "="
tell t's text items to repeat with i from 1 to (count) - 1
set n to n - 1 + (count item i's paragraphs)
tell item n of o's m
set item n of o's m to text item 1
set item n of o's l to text item 2
end tell
end repeat
set text item delimiters to tid
o's {m, l}
end parse_lists
set sourceText to "# List of module names (and library names if they differ)
Modulename1
Modulename2=Libname2
Modulename3
Modulename4=Libname4"
parse_lists from sourceText returning {Modulenames, Libnames}
--> {{"Modulename1", "Modulename2", "Modulename3", "Modulename4"}, {"Modulename1", "Libname2", "Modulename3", "Libname4"}}
-----------------------
2) Compare lists of folder names with module names, and identify which are in one list, and not the other (two sets: A not in B, and B not in A), as efficiently as possible. (Insidious detail: some dirnames are concatentations of other dirnames.)
-----------------------
on missing_strings from l1 against l2
if 0 is in {count l1, count l2} then return {l2, l1}
set m2 to {}
set tid to text item delimiters
set text item delimiters to return
set m1 to return & l2 & return
repeat with i in l1
set text item delimiters to return & i & return
tell m1's text items to if (count) is 1 then
set m2's end to i's contents
else
set AppleScript's text item delimiters to return
set m1 to beginning & ({""} & rest)
end if
end repeat
set text item delimiters to tid
if m1 is return then return {{}, m2}
{m1's paragraphs 2 thru -2, m2}
end missing_strings
set Modulenames to {"name1", "name1name2", "name2", "name2name3", "name3", "name4", "name6"}
set Foldernames to {"name1", "name1name2", "name3", "name4", "name4name5", "name5", "name6"}
missing_strings from Modulenames against Foldernames returning {missingModules, missingFolders}
--> {{"name4name5", "name5"}, {"name2", "name2name3"}}
-----------------------
---
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden