• 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: Default or optional arguments to handlers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Default or optional arguments to handlers


  • Subject: Re: Default or optional arguments to handlers
  • From: Timothy Bates <email@hidden>
  • Date: Tue, 23 Apr 2002 12:53:52 +1000

On 23/4/02 8:46 AM, "has" <email@hidden> wrote:
> I'm not sure overloading is as important to a loosely typed language like
> AS as to a strongly typed one. Optional parameters would be very nice,
> however.

Optional parameters are also good for allowing the programming to improve a
handler without breaking old users.
In php I often find I have made something like

function getID($var1) {
echo $var1;
}

Called in a script as

doit($form_text);

Then I see I need to be more flexible. In php I can just add a new parameter

function doit(var1, $alsoPickATest:0) {
if $alsoPickATest {
echo $modifiedForm;
}else {
echo $var1;
}
}

The old call still works (because of defaulting), but the new call is more
functional.

> It's this and the lack of a Libraries folder + import command that are my
> two really big bugbears when it comes to writing/using mods. They make the
> whole business far more awkward than it ought to be.

My priority list is
1. all arrays are hashes, just like in php
set listA to {}
set "dog" of listA to ""fido"
get dog of listA
-->"fido"
get item 1 of listA
-->"fido"

2. variable parameters
to doit (var1:"hello", var2:"world")
return {var1,var2}
}

doit("goodbye")
--> {goodbye","world"}

3. access variables by name
set cat to "woody"
set accessor to "cat"
set referent of accessor to "sebastian"
get cat
--> "sebastian"

4. Libraries enhancements
a Scripting Additions becomes a generic library access folder
b.1 No distinction between Osax and AppleScript libraries
b.2 Ability to define names for Applescript handlers

to take an item (with terms {from list:theList, at:location})
return items 1 thru (location -1) of theList & opt-L
items location thru -1 of theList
end take an item

take item from list {1,2,3} at 2
--> {1,3}

>> if positional parameters are inadequate, use a single record instead:
>> doSomething({param2:"Jo", param1:"Hello"})

> I wouldn't use lists myself: too much room for confusion. Also, I think the
> 'all-or-nothing' approach works best. I've tried using stuff like:

Absolutely: way confusing.
_______________________________________________
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: Default or optional arguments to handlers
      • From: Andy Wylie <email@hidden>
References: 
 >Re: Default or optional arguments to handlers (From: has <email@hidden>)

  • Prev by Date: Re: illus-trator
  • Next by Date: Re: applescript-users digest, Vol 3 #378 - 13 msgs
  • Previous by thread: Re: Default or optional arguments to handlers
  • Next by thread: Re: Default or optional arguments to handlers
  • Index(es):
    • Date
    • Thread