• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: applescript-users digest, Vol 3 #858 - 16 msgs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: applescript-users digest, Vol 3 #858 - 16 msgs


  • Subject: Re: applescript-users digest, Vol 3 #858 - 16 msgs
  • From: "Arthur J. Knapp" <email@hidden>
  • Date: Tue, 17 Sep 2002 12:24:15 -0400

> From: "Wallace, William" <email@hidden>
> Subject: RE: applescript-users digest, Vol 3 #858 - 16 msgs
> Date: Mon, 16 Sep 2002 16:08:13 -0500

> Speaking as one of the newest of newbies, I have to say that I found the
> "empty string trick" highly intuitive and clear. Even though prior to
> reading this post, I did not explicitly understand that the concatenation
> operator coerces from left to right. What is not clear to me is why
> Applescript is first creating a list then a string in the "(i & j & k & l)
> as string" example you give.

If the leftmost value is a string, then AppleScript tries to coerce the
right value to a string, (string concatenation). If the leftmost value is
a record, then it *requires* the rightmost value to be a record, (record
concatenation). If the leftmost value is of any other class, including
list, then AS assumes you are doing list concatenation.

string & (string or coerceable to string) --> string
record & (must be record) --> record
(anything else) & (anything else) --> list

Actually, there is a greater complexity involved with list concatenation.
The *formal* way in which concatenating works is as follows:

(list or coerceable to a single item list) & (list or etc...)

That is to say, if the leftmost operand is not a string or record, then it
*should* be a list, and if it isn't, AppleScript is more than happy to
treat it as a single item list. This is a common behind the scenes coercion.

Some of the more observant readers may now be wondering, "So how do you
concatenate a record to the left side without forcing AppleScript to think
you are doing record concatenation?". The answer is that you coerce the
record to a single item list yourself:

{ record } & anything --> { record, anything }

An even more common question is, "How do you concatenate sublists?":

set a to {1, 2, 3}
set b to {4, 5, 6}

a & b --> {1, 2, 3, 4, 5, 6}, normal list concatenation

{ a } & { b } --> { {1, 2, 3}, {4, 5, 6} }, sublists


> ... Or more to the point, how do you know this? Is
> this something you've divined though observation or something you've picked
> up along the way from someone else on the list or does this info come from
> some reference material that you have?

All of the above. ;-)

The AppleScript Language Guide:

<http://developer.apple.com/techpubs/macosx/Carbon/interapplicationcomm/Appl
eScript/AppleScriptLangGuide/index.html>

{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
}
_______________________________________________
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.

  • Follow-Ups:
    • Re: applescript-users digest, Vol 3 #858 - 16 msgs
      • From: Emmanuel <email@hidden>
  • Prev by Date: Droplet Problem
  • Next by Date: Addressing the folder that contains an item
  • Previous by thread: RE: applescript-users digest, Vol 3 #858 - 16 msgs
  • Next by thread: Re: applescript-users digest, Vol 3 #858 - 16 msgs
  • Index(es):
    • Date
    • Thread