• 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: Bridge anyone? [not off topic]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bridge anyone? [not off topic]


  • Subject: Re: Bridge anyone? [not off topic]
  • From: Nigel Garvey <email@hidden>
  • Date: Mon, 8 Nov 2004 02:10:50 +0000

Bernard Bernu wrote on Sun, 7 Nov 2004 18:13:23 +0100:

>If you put the handler deal inside script o instead of script o inside
>deal, you have to explicitely make a copy of chances as:
>script o
>	property cchances : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ¬
>		14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, ¬
>		27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, ¬
>		40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52}
>	property hands : {{}, {}, {}, {}}
>	on deal()
>		try
>			set hands to {{}, {}, {}, {}}
>			copy cchances to chances
>			repeat with i from 1 to 52
>				set c to some integer of chances
>				set item c of chances to missing value
>				set end of item ((c - 1) mod 4 + 1) of hands to item i of my deck
>			end repeat
>			return hands
>		on error s number n
>			error "deal : " & s number n
>		end try
>	end deal
>end script
>
>Then the time increases from 36s to 96s (10000 deal on a PBG4 667).
>I understand that the property chance inside the script o is defined at
>compiled time.
>Is the explicit copy statment only responsible for doubling the time or
>are there other deeper reasons for that?

Some of the speed of my version comes from using *references* to the list
properties (such as "o's hands", "o's chances") rather than just the
properties' names ("hands", "chances"). For some reason, this greatly
speeds the access to the lists' items. (That's why I used a script object
with properties in the handler rather than just using local variables.)
Try making 'chances' a property of your script and refer to it and to
'hands' as "o's chances" and "o's hands". Alternatively, since the
handler is now inside the script o, you could refer to o's properties as
"my" properties.

  script o
	   property cchances : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ¬
      14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, ¬
      27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, ¬
      40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52}
    property hands : {{}, {}, {}, {}}
    property chances : {}

    on deal()
      try
        set hands to {{}, {}, {}, {}}
        copy cchances to chances
        repeat with i from 1 to 52
          set c to some integer of my chances
          set item c of my chances to missing value
          set end of item ((c - 1) mod 4 + 1) of my hands to item i of my
deck

        -- etc.

Script o inherits properties from the main script, so "my deck" should
still work even if 'deck' is located in the main script rather than
inside 'o'.

NG
 _______________________________________________
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

  • Prev by Date: Re: Alias Forms as Property
  • Next by Date: Re: Bridge anyone? [not off topic]
  • Previous by thread: Re: Error of type 216
  • Next by thread: Re: Bridge anyone? [not off topic]
  • Index(es):
    • Date
    • Thread