• 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: Optional Parameter in Handler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Optional Parameter in Handler


  • Subject: Re: Optional Parameter in Handler
  • From: has <email@hidden>
  • Date: Fri, 22 Nov 2002 12:34:21 +0000

Ed Walter wrote:

>Has anyone come up with a good way to have an optional parameter in a
>handler?

Optional parameters can be faked easily enough using a record. In the
example below, the bar property is required while the baz property is
optional (default=false). This technique can be useful when creating
reusable, general-purpose libraries, though is best used in moderation.

======================================================================

on foo(paramRec)
-- paramRec = {bar:integer [, baz:boolean] }
set {bar:bar, baz:baz} to paramRec & {baz:false}
log bar
log baz
end foo

foo({bar:1, baz:true})
foo({bar:2})

======================================================================


But I'm not really sure that's what you meant. As far as your example code
is concerned, why don't you just write it as:

======================================================================

on saveWorldVerbal(theList)
repeat with theString in theList
say theString
end repeat
return
end saveWorldVerbal

on saveWorldVisual(theList)
repeat with theString in theList
display dialog theString
end repeat
return
end saveWorldVisual

-------
--TEST

set happyList to {"Peace", "Love", "Understanding"}
saveWorldVerbal(happyList)
saveWorldVisual(happyList)

======================================================================

Rather than stuffing a whole mix of different behaviours into one fat
handler, you have several small ones each performing a single, well-defined
task. It's a lot simpler.

HTH

has

--
http://www.barple.pwp.blueyonder.co.uk -- The Little Page of AppleScripts
_______________________________________________
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.

  • Prev by Date: Re: Viola...
  • Next by Date: Re: lock the screen from the keyboard, win a prize
  • Previous by thread: Re: Optional Parameter in Handler
  • Next by thread: Script keeps crashing Filemaker Pro
  • Index(es):
    • Date
    • Thread