• 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: Implementing a Map class in AS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Implementing a Map class in AS


  • Subject: Re: Implementing a Map class in AS
  • From: has <email@hidden>
  • Date: Wed, 16 Apr 2008 12:05:28 +0100

On 16 Apr 2008, at 03:37, Mark J. Reed wrote:

I know this is a silly thing to do, but I was wondering if it was at
all idiomatic to use a script object as a class definition...

AppleScript supports a form of prototype-based OOP (as opposed to the more common, and more complex, class-based approach) via its 'script' type. Script objects also provide the basis for modular construction. e.g. See the AppleMods website <http://applemods.sourceforge.net/modBrowser.html > for demonstrations of both forms of usage (the Types library is a good starter for OOP examples).



[...]
script Map
	property keyList : {}
	property valueList : {}

	on new()
		copy me to anInstance
		return anInstance
	end new


Avoid using AppleScript's 'copy' command on script objects. 'copy' performs a deep copy of the script object and all its parents, so each time you call it, it duplicates your entire top-level script and every object in it. This breaks any top-level shared state, and is hugely expensive and can easily overwhelm and crash the AS interpreter due to the numbers of objects involved. Use a constructor function instead:

on newMap()
	script Map
		...
	end
end newMap


has -- Control AppleScriptable applications from Python, Ruby and ObjC: http://appscript.sourceforge.net

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden
References: 
 >Implementing a Map class in AS (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Automation Sans Window Server
  • Next by Date: Re: Automation Sans Window Server
  • Previous by thread: Implementing a Map class in AS
  • Next by thread: Emptying the "Volumes" folder
  • Index(es):
    • Date
    • Thread