Calling a handler from within a handler?

Hello,

I think this is a fairly simple question. The answer must be out there somewhere, but I haven’t been able to find it.

What I want to do is call a handler from within a handler. For example, running compare_Lists below relies on the split handler:

--Handler: Removes duplicate list items delimited by "&"
on compare_Tags(origString, newString)
	set theDelim to "&"
	set origTags to split(origString, theDelim)
	set newTags to split(newString, theDelim)
	
	repeat with i from 1 to count of items in newTags
		if i is not "" then
			set theTag to item i of newTags
		end if
		ignoring white space
			if origTags does not contain theTag then
				set newComment to origString & " " & theDelim & theTag
			end if
		end ignoring
	end repeat
	return newComment
end compare_Tags

--Handler: Splits string into array by delimiter
to split(someText, delimiter)
	set AppleScript's text item delimiters to delimiter
	set someText to someText's text items
	set AppleScript's text item delimiters to {""}
	return someText
end split

Trying to do this within my larger script results in an error stating something like “split can’t continue”. Adding “on me” at the end of my handler call like I would within a Tell statement doesn’t work either.

Can someone explain how to make this technique work or work around it without de-modularizing it? I know I could just type out my split steps within the handler every time, but that gets old. This is especially true considering cases like this when I’d like to use a handler (split) within a handler (compare_Lists) within a handler (tag_Items). Here is the whole script with my failed implementation in case that helps:

--This script either appends provided text to the comments (default) or replaces the comments of the selected folder/file and sub folders/files 

--Variables used in handlers
property myComment : ""
property myAction : ""
property selectionName : ""
property selectionKind : ""

--Set selection
tell application "Finder"
	set mySelection to selection
	--set selectionRef to selection as alias
	--set {name:selectionName, kind:selectionKind} to info for (selectionRef) without size
end tell

--Record selection properties
selection_Info(mySelection)

--Prompt for new comment text (parameter is default entry)
enter_Comment("&tag")

--Prompt to replace or append to comments
choose_Action()

tell application "Finder"
	if myAction is equal to "" then set myAction to "append"
end tell

--Tag files/folders
repeat with oneItem in mySelection
	set {folder:Fo, package folder:Pa} to info for oneItem as alias
	if Fo and not Pa then
		tag_Items(mySelection, myComment, myAction)
		tell application "Finder" to set subFiles to entire contents of oneItem
		tag_Items(subFiles, myComment, myAction)
	else
		tag_Items({contents of oneItem}, myComment, myAction)
	end if
end repeat

--Handler: Compile name and kind list of selected files
on selection_Info(theSelection)
	repeat with oneItem in theSelection
		set {name:itemName, kind:itemKind} to info for oneItem as alias
		if selectionName is not "" then
			set selectionName to selectionName & " et al."
		else
			set selectionName to itemName
			set selectionKind to itemKind
		end if
	end repeat
end selection_Info

--Handler: Prompts for text (with supplied default entry)
on enter_Comment(defaultText)
	tell application "Finder"
		set myComment to text returned of (display dialog "Enter comment text for " & selectionKind & " " & selectionName & " and sub-files/folders" default answer defaultText)
	end tell
end enter_Comment

--Handler: Prompts to select append or replace comment
on choose_Action()
	tell application "Finder"
		set question to display dialog "Append text to current comments or replace comments entirely?" buttons {"Replace Comments", "Append to Comments"} default button 2
		set answer to button returned of question
		
		if answer is equal to "Replace Comments" then
			set myAction to "replace"
		else if answer is equal to "Append to Comments" then
			set myAction to "append"
		end if
	end tell
end choose_Action

--Handler: Appends or replaces supplied text to comment of supplied items
on tag_Items(itemList, theComment, preservation)
	tell application "Finder"
		repeat with oneItem in itemList
			set newComment to theComment
			if preservation is equal to "append" then
				set origComment to comment of oneItem
				set newComment to compareTags(origComment, newComment) of me
				--HOW DO I GET THESE HANDLERS TO CALL ONE ANOTHER!?				
			end if
			set comment of oneItem to newComment
		end repeat
	end tell
end tag_Items

--Handler: Removes duplicate list items delimited by "&"
on compare_Tags(origString, newString)
	set theDelim to "&"
	set origTags to split(origString, theDelim)
	set newTags to split(newString, theDelim)
	repeat with i from 1 to count of items in newTags
		if i is not "" then
			set theTag to item i of newTags
		end if
		ignoring white space
			if origTags does not contain theTag then
				set newComment to origString & " " & theDelim & theTag
			end if
		end ignoring
	end repeat
	return newComment
end compare_Tags

--Handler: Splits string into array by delimiter
to split(someText, delimiter)
	set AppleScript's text item delimiters to delimiter
	set someText to someText's text items
	set AppleScript's text item delimiters to {""}
	return someText
end split

Thank you for your help!
Donovan

Model: MacBook Pro
AppleScript: 1.10.7
Browser: Firefox 2.0.0.12
Operating System: Mac OS X (10.4)

Hi,

the syntax

my handler()

or

handler() of me

within a tell block is correct.

but you have a naming error:
your handler is called compare_Tags() and the call is compareTags()

How embarrassing! Well, at least the answer isn’t complicated.

Thanks Stefan.