• 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: how?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how?


  • Subject: Re: how?
  • From: Chris Page <email@hidden>
  • Date: Thu, 14 Jan 2010 16:36:18 -0800

On Jan 13, 2010, at 10:50 PM, Paul Scott wrote:

> Variations on the theme are possible, but I've settled on this particular approach. I wish "repeat once" was actually part of the language, because if you accidentally leave out the final exit, all hell breaks loose; and the alternative "repeat 1 times" is ugly as sin.

The real way to address this (in any programming language design) is to provide explicit support for exiting a local scope. For example, in Dylan, you can write:

  block (exit-this-block)
    ...
    if some-condition then
      exit-this-block()
    end
    ...
  end

“exit-this-block” is whatever name you chose. It is a local variable whose value is a function that returns from the block statement. You can even pass arguments to it, which will be returned as the value of the block statement (in AppleScript, it would set the value of “result”).

It might look like this in AppleScript:

  block exitThisBlock
    ...
    if someCondition then
      exitThisBlock(42)
    end
    ...
  end
  log the result --> “42"

Since the exit function is a local variable that you get to name, you can nest them, as well:

  block exitBlockA
    ...
    block exitBlockB
      ...
      if x then exitBlockA()
      if y then exitBlockB()
    end
  end

--
Chris Page

 The other, other AppleScript Chris

 _______________________________________________
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

  • Follow-Ups:
    • Re: how?
      • From: Paul Scott <email@hidden>
    • Re: how?
      • From: "Mark J. Reed" <email@hidden>
References: 
 >Re: how? (From: Paul Berkowitz <email@hidden>)
 >Re: how? (From: Paul Scott <email@hidden>)

  • Prev by Date: Re: how?
  • Next by Date: Re: exit repeat abuse;-)
  • Previous by thread: Re: how?
  • Next by thread: Re: how?
  • Index(es):
    • Date
    • Thread