[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ?-suffix for booleans... good-idea? or bad-idea?
From: |
Panicz Maciej Godek |
Subject: |
Re: ?-suffix for booleans... good-idea? or bad-idea? |
Date: |
Thu, 27 Apr 2017 12:53:37 +0200 |
2017-04-27 12:39 GMT+02:00 Jan Nieuwenhuizen <address@hidden>:
> Christopher Allan Webber writes:
>
> > I've noticed that it's common in Guile modules to use "foo?" for
> > variable names involving booleans. It's tempting,
>
> > But is it a good idea?
>
> It's an idea that I like and use. Not sure that says anything about
> good or bad.
>
> I would like to help you paint though!
>
> We have functions like null? and pair? that return booleans, where I
> would like the [non]-nil value. I often find myself writing things like
>
> (let ((bar (if (pair? foo) (baz foo)
> #f)))
>
> where I would rather like to write something like
>
> (let ((bar (and=> (pair?=> foo) baz)))
>
> How do you do these things, and how do you call your pair?=> function?
>
>
I usually use the and-let* form (SRFI-2) to deal with such cases.
(and-let* (((pair? foo)))
(baz foo))
The (grand scheme) library which I maintain provides a variant of and-let*
that additionally provides pattern matching:
https://github.com/plande/grand-scheme/blob/master/grand/syntax.scm#L255
so you could even write the above code as
(and-let* (((_ . _) foo))
(baz foo))