Here is a little bit more practical example, for exploding paths, now I have introduced a handler into the script, that returns the text items of the delimiters, not much gain, but it is going in the right direction!
property tids : ""
global oldTids
on makeExplodePathScript()
script explodepath
to doit(aPath)
local tmpvar
set AppleScript's text item delimiters to tids
set tmpvar to text items of aPath
set AppleScript's text item delimiters to oldTids
return tmpvar
end doit
end script
end makeExplodePathScript
set oldTids to AppleScript's text item delimiters
# I create and configure the first text item delimiter script.
set tids to ":"
set explodeHfsPath to makeExplodePathScript()
set mpath to "A:long:path:of:type:hfs"
set those to explodeHfsPath's doit(mpath)
log those
-- > (*A, long, path, of, type, hfs*)
# I create and configure the second text item delimiter script.
set tids to oldTids
set explodeToChars to makeExplodePathScript()
set these to explodeToChars's doit(mpath)
log these
--> (*A, :, l, o, n, g, :, p, a, t, h, :, o, f, :, t, y, p, e, :, h, f, s*)
set apxpath to "/A/deep/path/to/some/file/in/Contents/Resources/somewhere"
set tids to "/"
set explodePxPath to makeExplodePathScript()
set them to explodePxPath's doit(apxpath)
log them
--> (*, A, deep, path, to, some, file, in, Contents, Resources, somewhere*)
set andThose to explodeToChars's doit(apxpath)
# now when we are reusing, we are getting the gain, just one line now!
log andThose
--> (*/, A, /, d, e, e, p, /, p, a, t, h, /, t, o, /, s, o, m, e, /, f, i, l, e, /, i, n, /, C, o, n, t, e, n, t, s, /, R, e, s, o, u, r, c, e, s, /, s, o, m, e, w, h, e, r, e*)