Re: String to multiple-item list coercion
Re: String to multiple-item list coercion
- Subject: Re: String to multiple-item list coercion
- From: has <email@hidden>
- Date: Thu, 26 Sep 2002 13:12:32 +0100
Nigel Garvey wrote:
>
>set {day:a, month:b, year:c} to date "Sunday, September 1, 2002 12:00:00am"
>
>return {a, b, c}
>
> --> {1, September, 2002}
>
>
That's not only the most interesting technique I've seen on this list for
>
several weeks, but it's very much faster than the list assignment
>
alternative:
>
>
set {a, b, c} to date "Sunday, September 1, 2002 12:00:00am"'s {day,
>
month, year}
Also much prettier and more readable; the list version above is pretty ugly
looking. Multiple assignments with records on the left aren't new: they're
covered in the ASLG [p159-160] in one of those sections that most folks
probably never pay much attention to (it's not very exciting reading, after
all). It wasn't a big cognitive jump to realise that if records have
properties, and dates have properties, then ...
Incidentally, I do owe Steven a debt of gratitude here: by making me sit
down and really pay attention to a topic I'd never paid any real heed to
before, I now understand yet another thing about AS that I didn't really
before, and can now find valuable uses for.
For example, in both ASTest and AWPSRenderer frameworks, I need to pass an
arbitrary number of items through function calls that allow only a single
parameter. In languages such as Python, say, I'd just define my functions
so that they can accept an arbirary number of parameters, with the extra
parameters at the end being dumped direct into a list, which is certainly
highly convenient. Before in AR, I was advocating the following:
set paramRec to {a:record, containing:all, your:parameters}
renderWith(foo, paramRec)
...
on render(foo, paramRec)
blah-blah with a of paramRec
blah-blah with containing of paramRec
etc.
end render
Now I can chuck all that rubbish, and recommend the far simpler and easier
to read:
renderWith(foo, {bar, baz, ...})
...
on render(foo, {bar, baz, ...})
blah-blah with bar
blah-blah with baz
etc.
end render
Which is lovely. So, sincerely: thanks Steven, for making me a better
programmer (even though this was neither your intended goal nor my original
plan...;)
Cheers,
has
--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.