• 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: Booleans in positional parameter sub routines [was; Can someone explain this?}
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Booleans in positional parameter sub routines [was; Can someone explain this?}


  • Subject: Re: Booleans in positional parameter sub routines [was; Can someone explain this?}
  • From: Cal <email@hidden>
  • Date: Mon, 18 Dec 2000 00:10:50 -0500

Sun Real <email@hidden> wrote:

Trying to use the above, I came across this:

to doSomething with noise -- works
if noise then beep
end doSomething

to doSomething with noise -- execution error: "The variable noise is
not defined."
set a to 1
if noise then beep
end doSomething

to doSomething with noise -- works
noise
set a to 1
if noise then beep
end doSomething

And:

Testing here suggests that 'Set2be' is compiling as a positional
parameter sub-routine call with just a boolean parameter:

Set2be with to
set not2be to false

to Set2be with to
beep
end Set2be

This runs here. I don't know why the compiler allows the keyword 'to' to
be passed as a boolean param (it didn't appear to be possible to use it),
but if a non-reserved word is used, it becomes a switch:

Set2be with too
set not2be to false

to Set2be with too
if too then
beep
else
beep 2
end if
end Set2be

I highly recommend _against_ using "with" as the keyword for a keyword parameter name. If the value passed in is anything other than a boolean, you won't be able to get the value. Also, you'll get really confused because either "with" or "without" work the same in the handler declaration, regardless of how the call is written. For reasons of ambiguity, I'd avoid using this construct on handler declarations.

I also recommend against using "to" as a formal parmeter value. The example above won't work with "to":

to Set2be with to
if to then <-- illegal syntax
beep
else
beep 2
end if
end Set2be

You're much better off using keywords other than "with" and "without" on the declarations. You can check the class of the parameter to see whether you've got a boolean, if you're expecting a boolean.

Cal


  • Prev by Date: Re: What's an FSS? (newbie)
  • Next by Date: Re: Remote Access
  • Previous by thread: Re: Help with Entourage/Outlook
  • Next by thread: script compiled on 9.04 gives -43 (file not found) on 8.6
  • Index(es):
    • Date
    • Thread