Okay, that makes sense.  Thanks, all.

On Mon, Nov 21, 2016 at 10:07 AM, Leif Andersen <l...@leifandersen.net>
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 costs.
>
> (define (do-something)
>   (let/ec return
>     (unless (some-condition)
>       (return NO))
>
>     (do-the-thing)))
>
> Although honestly, with this pattern, I find that errors work better here,
> as they return early, and you can decide how they get handled with a
> with-handlers.
>
> (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 of catching errors,
> rather than always having to manually check the output of the function....
> (I'm looking at you C...)
>
> Hope that helps.
>
>
> ~Leif Andersen
>
> On Mon, Nov 21, 2016 at 12:41 PM, David Storrs <david.sto...@gmail.com>
> 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 21, 2016 at 9:37 AM, David Storrs <david.sto...@gmail.com>
>> 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
>>> adds an unnecessary level of indentation and feels clunky.  Is there a
>>> clean solution?
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Racket Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to racket-users+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to