Re: [racket-users] What is the Racket equivalent to 'return' for early exit?

2016-11-21 Thread Matthew Butterick
On Nov 21, 2016, at 9:37 AM, David Storrs wrote: > In Perl I would often write: > > sub do_something { > return unless ( some necessary condition is met ); > ... do the thing ... > } On Nov 21, 2016, at 10:07 AM, Leif Andersen wrote:

Re: [racket-users] What is the Racket equivalent to 'return' for early exit?

2016-11-21 Thread Norman Gray
Greetings. On 21 Nov 2016, at 18:07, Leif Andersen wrote: (define (do-something) (unless (some-condition) (error "NO")) (do-the-thing)) (with-handlers ([exn:fail? (lambda (e) (displayln "I returned early"))]) (do-something)) But that is specifically because I prefer the workflow

Re: [racket-users] What is the Racket equivalent to 'return' for early exit?

2016-11-21 Thread David Storrs
On Mon, Nov 21, 2016 at 10:30 AM, 'John Clements' via Racket Users < racket-users@googlegroups.com> wrote: > > > On Nov 21, 2016, at 09:37, David Storrs wrote: > > > > In Perl I would often write: > > > > sub do_something { > > return unless ( some necessary condition

Re: [racket-users] Re: What is the Racket equivalent to 'return' for early exit?

2016-11-21 Thread David Storrs
Okay, that makes sense. Thanks, all. On Mon, Nov 21, 2016 at 10:07 AM, Leif Andersen wrote: > Honestly, I personally like to use let/ec for this. I know it's still > using continuations, but it is much more lightweight, both syntactically > and in terms of run-time

Re: [racket-users] What is the Racket equivalent to 'return' for early exit?

2016-11-21 Thread 'John Clements' via Racket Users
> On Nov 21, 2016, at 09:37, David Storrs wrote: > > In Perl I would often write: > > sub do_something { > return unless ( some necessary condition is met ); > ... do the thing ... > } > > In Racket I could wrap the rest of the procedure in an (if), but that

Re: [racket-users] Re: What is the Racket equivalent to 'return' for early exit?

2016-11-21 Thread Leif Andersen
Honestly, I personally like to use let/ec for this. I know it's still using continuations, but it is much more lightweight, both syntactically and in terms of run-time costs. (define (do-something) (let/ec return (unless (some-condition) (return NO)) (do-the-thing))) Although

Re: [racket-users] Re: What is the Racket equivalent to 'return' for early exit?

2016-11-21 Thread George Neuner
On 11/21/2016 12:41 PM, David Storrs wrote: Edit: I know I could also use call/cc and invoke the continuation to escape, but that still adds another layer of indentation for something that in the normal case won't be called. It's not a big deal, but I was wondering about it. On Mon, Nov

[racket-users] Re: What is the Racket equivalent to 'return' for early exit?

2016-11-21 Thread David Storrs
Edit: I know I could also use call/cc and invoke the continuation to escape, but that still adds another layer of indentation for something that in the normal case won't be called. It's not a big deal, but I was wondering about it. On Mon, Nov 21, 2016 at 9:37 AM, David Storrs

[racket-users] What is the Racket equivalent to 'return' for early exit?

2016-11-21 Thread David Storrs
In Perl I would often write: sub do_something { return unless ( some necessary condition is met ); ... do the thing ... } In Racket I could wrap the rest of the procedure in an (if), but that adds an unnecessary level of indentation and feels clunky. Is there a clean solution? -- You