Coercing a list to string
Coercing a list to string
- Subject: Coercing a list to string
- From: Axel Luttgens <email@hidden>
- Date: Sat, 18 Aug 2001 17:04:41 +0200
- Organization: ---
While writing date handlers, I became quite worried: sometimes my stuff
worked, sometimes not (OK, OK, that's not so uncommon...).
I finally tracked the problem down to a quite basic behavior of
AppleScript (1.6 with OS 9.1 and standard scripting additions only - no
third party OSAXen).
I don't remember having encountered that before.
Has this always been so, or is it a "feature" of newer versions of
AppleScript ?
== SCRIPT'S START =>
-- Let's define some things to play with.
on d(d)
return d
end d
on m(m)
return m
end m
on y(y)
return y
end y
-- For the clarity of outputs.
set {TID, AppleScript's text item delimiters} ,
to {AppleScript's text item delimiters, "/"}
-- Define a sample record.
set Dte to {day:1, month:3, year:2000}
-- This is not what I expected.
set X to {Dte's day, Dte's month, Dte's year} as string
log X
--> ""
-- Deferring evaluation works.
set X to {Dte's day, Dte's month, Dte's year}
set X to X as string
log X
--> "1/3/2000"
-- With functions, it works as expected (no need to defer).
set X to {d(1), m(3), y(2000)} as string
log X
--> "1/3/2000"
-- You can even nest function calls (as expected).
set X to {d(1), m(m(3)), y(2000)} as string
log X
--> "1/3/2000"
-- The problem occurs as soon as a record is involved.
set X to {Dte's day, m(3), y(2000)} as string
log X
--> ""
set X to {d(1), Dte's month, y(2000)} as string
log X
--> "1/"
-- Same seems to apply to lists.
set Dte to {1, 3, 2000}
set X to {Dte's item 1, Dte's item 2, Dte's item 3} as string
log X
--> ""
set X to {1, Dte's item 2, 2000} as string
log X
--> "1/"
-- Let's restore our environment ;-)
set AppleScript's text item delimiters to TID
<= SCRIPT'S END ==