Re: ?-suffix for booleans... good-idea? or bad-idea?

2017-04-27 Thread Marko Rauhamaa
Jan Nieuwenhuizen :

> 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.

There are also the traditional:

   (let ((name$ "Henry Ford")
 (birth-year% 1863)
 (timestamp& 1493294649)
 (price@ 99.99)
 (slice! 0.667)
 (proportion# 0.667))
  ...)


Marko



Re: ?-suffix for booleans... good-idea? or bad-idea?

2017-04-27 Thread Panicz Maciej Godek
2017-04-27 12:39 GMT+02:00 Jan Nieuwenhuizen :

> 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))


Re: ?-suffix for booleans... good-idea? or bad-idea?

2017-04-27 Thread Jan Nieuwenhuizen
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?

Greetings, --janneke

-- 
Jan Nieuwenhuizen  | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ®  http://AvatarAcademy.nl  



Re: ?-suffix for booleans... good-idea? or bad-idea?

2017-04-26 Thread Alex Kost
Paul (2017-04-25 12:21 -0400) wrote:

> On 04/25/2017 11:50 AM, Jan Wedekind wrote:
>
>> What do people think?  I'm struggling with deciding what's the right
>> thing for my own code, but leaning towards "we shouldn't use the ?
>> suffix for just boolean values".
>
> I like using the '?' suffix only for predicates.  I often use 'is-' 
> prefix for boolean values, which reads well: (if is-raining ...)

Thanks for sharing!  I also like to use '?' for functions but I always
felt uncomfortable to use it for variables.  Using "is-" (or "has-" or
alike) sounds interesting, I'm going to try this convention in my code,
thanks for the idea!

-- 
Alex



Re: ?-suffix for booleans... good-idea? or bad-idea?

2017-04-25 Thread Neil Jerram
I'm also not sure.  In the past I've written code with an 'xxx?' 
variable, and then added a procedure to set it, giving 'set-xxx?!' - 
which is not exactly elegant.


Also I'm not sure it's best practice to have many 
variables/attributes/parameters with boolean values, as this can lead to 
code that has too many opaque uses of #t and #f.  (I.e. it's often 
unclear, at the point of use, what each #t or #f means.)  It might be 
better to refactor to something with non-boolean values, e.g. from


   (set! red? #t)
   (set! narrow?#t)

to

   (set! properties '(red narrow))

And in that case the question about '?' would disappear.

Regards,
  Neil


On 25/04/17 04:43, Alex Vong wrote:

Good question! I can't decide as well. I want to know how people think
about it.

In a lazy language, a variable is a 0-ary thunk, while a predicate is a
1-ary thunk. Since they are really just special case of a general thing,
it make sense to use foo? for both cases. But we all know guile is not
lazy, so I really don't know what to do.

Christopher Allan Webber  writes:


Hello everyone!  Here's a little bikeshed for us to paint.

I've noticed that it's common in Guile modules to use "foo?" for
variable names involving booleans.  It's tempting, because this looks
an awful lot like you're asking a question... and it's also common
for this even to be keyword arguments to procedures, etc.

But is it a good idea?  I thought "foo?" was supposed to be for
predicates, as a nicer version of the "foo-p" predicate convention in
other non-scheme lisps.  I can't imagine other lisps doing "foo-p" for
just variables with boolean values.

On the other hand, once you start adding ? to the end of boolean'y
things, it *does* become tempting to put them at the end of boolean
variables and arguments.  It looks pretty nice.

What do people think?  I'm struggling with deciding what's the right
thing for my own code, but leaning towards "we shouldn't use the ?
suffix for just boolean values".

  - Chris





Re: ?-suffix for booleans... good-idea? or bad-idea?

2017-04-25 Thread Panicz Maciej Godek
Hi :)

2017-04-24 19:01 GMT+02:00 Christopher Allan Webber 
:

> Hello everyone!  Here's a little bikeshed for us to paint.
>
> I've noticed that it's common in Guile modules to use "foo?" for
> variable names involving booleans.  It's tempting, because this looks
> an awful lot like you're asking a question... and it's also common
> for this even to be keyword arguments to procedures, etc.
>
> But is it a good idea?  I thought "foo?" was supposed to be for
> predicates, as a nicer version of the "foo-p" predicate convention in
> other non-scheme lisps.  I can't imagine other lisps doing "foo-p" for
> just variables with boolean values.
>
> On the other hand, once you start adding ? to the end of boolean'y
> things, it *does* become tempting to put them at the end of boolean
> variables and arguments.  It looks pretty nice.
>
> What do people think?  I'm struggling with deciding what's the right
> thing for my own code, but leaning towards "we shouldn't use the ?
> suffix for just boolean values".
>

I think that there's no need to be super-consistent here.
Actually, I can't think of any natural and elegant use of a boolean variable
from the top of my head, but my gutt feeling is that it usually can be
avoided
(however, if you have some particular examples on your mind, I think
it could be instructive to see them here).

Also, there seems to be many aspects of this. When we're using
a name inside a let or let* form, it shouldn't be very harmful to use
question mark
in the name of an intermediate variable. The thing with function parameters
and global names are I believe more important, because they are a part of
some interface.

As for parameter names, I'm not sure whether it is a good idea to use
question marks in the names that ought to refer to predicates. I'm not sure
if it is better for a prototype of "filter" to be

(filter condition? list)

or

(filter condition list)

Actually, I find it more natural to interpret the predicate as a boolean
flag
to a function, rather than a predicate. That said, I think it is a bad
practice
to make boolean flags arguments to functions, because it is impossible
to say how (f #false #true #false) differs from (f  #true #true #true) nor
what the roles of these arguments are (which is why I think the interface
of "format" sucks)

Hinldley-Milner languages avoid this problem, because a type signature
tells more than just a name (and is more reliable), and they handle tagged
unions easily, and it is much better to define a union and use one of its
values, than a boolean value (and using Lisp symbols for this purpose,
although more readable, is error prone and likely less efficient)

Best regards,
Panicz


Re: ?-suffix for booleans... good-idea? or bad-idea?

2017-04-25 Thread Paul

On 04/25/2017 11:50 AM, Jan Wedekind wrote:


What do people think?  I'm struggling with deciding what's the right
thing for my own code, but leaning towards "we shouldn't use the ?
suffix for just boolean values".


I like using the '?' suffix only for predicates.  I often use 'is-' 
prefix for boolean values, which reads well: (if is-raining ...)


-Paul



Re: ?-suffix for booleans... good-idea? or bad-idea?

2017-04-25 Thread Jan Wedekind
In Ruby ...? is used for methods returning boolean. E.g. 5.even?. Boolean 
variables are not sufficed. E.g. x = 5.even? The method call "even?" is the 
question. "x" is the answer.

On 25. April 2017 04:43:23 GMT+00:00, Alex Vong  wrote:
>Good question! I can't decide as well. I want to know how people think
>about it.
>
>In a lazy language, a variable is a 0-ary thunk, while a predicate is a
>1-ary thunk. Since they are really just special case of a general
>thing,
>it make sense to use foo? for both cases. But we all know guile is not
>lazy, so I really don't know what to do.
>
>Christopher Allan Webber  writes:
>
>> Hello everyone!  Here's a little bikeshed for us to paint.
>>
>> I've noticed that it's common in Guile modules to use "foo?" for
>> variable names involving booleans.  It's tempting, because this looks
>> an awful lot like you're asking a question... and it's also common
>> for this even to be keyword arguments to procedures, etc.
>>
>> But is it a good idea?  I thought "foo?" was supposed to be for
>> predicates, as a nicer version of the "foo-p" predicate convention in
>> other non-scheme lisps.  I can't imagine other lisps doing "foo-p"
>for
>> just variables with boolean values.
>>
>> On the other hand, once you start adding ? to the end of boolean'y
>> things, it *does* become tempting to put them at the end of boolean
>> variables and arguments.  It looks pretty nice.
>>
>> What do people think?  I'm struggling with deciding what's the right
>> thing for my own code, but leaning towards "we shouldn't use the ?
>> suffix for just boolean values".
>>
>>  - Chris

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.


Re: ?-suffix for booleans... good-idea? or bad-idea?

2017-04-24 Thread Alex Vong
Good question! I can't decide as well. I want to know how people think
about it.

In a lazy language, a variable is a 0-ary thunk, while a predicate is a
1-ary thunk. Since they are really just special case of a general thing,
it make sense to use foo? for both cases. But we all know guile is not
lazy, so I really don't know what to do.

Christopher Allan Webber  writes:

> Hello everyone!  Here's a little bikeshed for us to paint.
>
> I've noticed that it's common in Guile modules to use "foo?" for
> variable names involving booleans.  It's tempting, because this looks
> an awful lot like you're asking a question... and it's also common
> for this even to be keyword arguments to procedures, etc.
>
> But is it a good idea?  I thought "foo?" was supposed to be for
> predicates, as a nicer version of the "foo-p" predicate convention in
> other non-scheme lisps.  I can't imagine other lisps doing "foo-p" for
> just variables with boolean values.
>
> On the other hand, once you start adding ? to the end of boolean'y
> things, it *does* become tempting to put them at the end of boolean
> variables and arguments.  It looks pretty nice.
>
> What do people think?  I'm struggling with deciding what's the right
> thing for my own code, but leaning towards "we shouldn't use the ?
> suffix for just boolean values".
>
>  - Chris


signature.asc
Description: PGP signature


?-suffix for booleans... good-idea? or bad-idea?

2017-04-24 Thread Christopher Allan Webber
Hello everyone!  Here's a little bikeshed for us to paint.

I've noticed that it's common in Guile modules to use "foo?" for
variable names involving booleans.  It's tempting, because this looks
an awful lot like you're asking a question... and it's also common
for this even to be keyword arguments to procedures, etc.

But is it a good idea?  I thought "foo?" was supposed to be for
predicates, as a nicer version of the "foo-p" predicate convention in
other non-scheme lisps.  I can't imagine other lisps doing "foo-p" for
just variables with boolean values.

On the other hand, once you start adding ? to the end of boolean'y
things, it *does* become tempting to put them at the end of boolean
variables and arguments.  It looks pretty nice.

What do people think?  I'm struggling with deciding what's the right
thing for my own code, but leaning towards "we shouldn't use the ?
suffix for just boolean values".

 - Chris