2017-04-27 12:39 GMT+02:00 Jan Nieuwenhuizen <jann...@gnu.org>: > 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))