• 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: lists and items and position of items
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lists and items and position of items


  • Subject: Re: lists and items and position of items
  • From: kai <email@hidden>
  • Date: Sat, 12 Mar 2005 15:08:57 +0000


On Saturday, March 12, 2005, at 02:52 pm, I wrote:


On Sat, 12 Mar 2005 14:43:59 +0100, Christian Vinaa wrote:

just to close this  question;

Yvan pointed out the correct solution now it works ok

Almost... ;-)

Folks may have received my last message in the form it was sent, but the web archives certainly seem to have difficulty in displaying formatted text properly. In case anyone is trying to make sense of a garbled version, here it is again as plain text (which I think I'll stick to in future):


Begin original message:
-----------------------

For the benefit of those not familiar with this issue, Christian's script was comparing strings like "Sal" with the references like: item 1 of {"Sal", "Sue", "Bob", "Carl"}. While we might recognise these as having essentially similar meanings, they differ nevertheless - unless and until the reference is evaluated to an exact match, such as (in this case): "Sal". Christian's 'list-position' handler therefore found zero matches in every comparison.

If I remember correctly, yvan suggested coercing the reference to a string before making the comparison. Indeed, that works fine for the list of strings that Christian was using as a source - specifically:

----------

set this_list to {"Sal", "Sue", "Bob", "Carl"}
...
requires a coercion like this in the 'list_position' handler:
if item i of this_list is this_item as string then return i
...
--> {1, 2, 3, 4}

----------

It obviously follows that, if we use a specific coercion for dereferencing, it should reflect the class of the original items. For example:

----------

set this_list to {45, 3.624, 67, 9 div 2}
...
if item i of this_list is this_item as number then return i
...
--> {1, 2, 3, 4}

----------

set this_list to {true, false}
...
if item i of this_list is this_item as boolean then return i
...
--> {1, 2}

----------

set this_list to {{3, 4, 5}, {"x", "y", "z"}, {true, false}, {current date}}
...
if item i of this_list is this_item as list then return i
...
--> {1, 2, 3, 4}


----------

...and so on.

However, a much more versatile, general-purpose approach to dereferencing is to either coerce to item, or to get the contents of each reference. These methods are even more useful when a list of mixed classes might be involved:

----------

set this_list to {true, "Sal", current date, {"x", "y", "z"}, integer, 86, {firstName:"Christian", lastName:"Vinaa"}, pi, 2 ^ 5, file}
...
if item i of this_list is this_item as item then return i
or:
if item i of this_list is contents of this_item then return i
...
--> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}


----------

---
kai

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: lists and items and position of items
      • From: Axel Luttgens <email@hidden>
    • Re: lists and items and position of items
      • From: yvan-koenig <email@hidden>
References: 
 >Re: lists and items and position of items (From: kai <email@hidden>)

  • Prev by Date: Re: lists and items and position of items
  • Next by Date: Re: lists and items and position of items
  • Previous by thread: Re: lists and items and position of items
  • Next by thread: Re: lists and items and position of items
  • Index(es):
    • Date
    • Thread