[racket] Why are some Racket functions such a 'member' designed as partially boolean?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Fri May 25 12:57:08 EDT 2012

In some Racket languages they are: 

> Welcome to DrRacket, version [3m].
> Language: htdp/isl.
> > (member? 2 '(1 2 3))
> true

Note the '?'. 

In untyped languages, conditionals count every value other than #f as a true value. So there isn't a real need to return #t. Better still, in some cases it is much better to return an additional result value -- in member's case it would have been '(2 3) above -- because this value is useful and avoids a recompilation. 

 (define (take-step game-state)
   (if (move-available game-state)
       (step state (determine-best-move state))

It all likelihood there is a tremendous overlap between move-available? and determine-best-move so why not rewrite it like this:

 (define (take-step game-state)
   (define good-move (determine-best-move state))
   (if good-move (step state good-move) (give-up)))

On May 25, 2012, at 12:29 PM, Don Green wrote:

> Why are some Racket functions such a 'member' not designed as booleans?
> I would expect 'member' to be a boolean.
> I am inclined to write my own version of 'member' that is boolean.
> Before I do, I am wondering if the bright person who designed the Racket function: 'member', did so for some very good reason that is not obvious to me.
> I notice that there are a number of other Racket functions like this, where they return #t or the value of the argument passed to the function, not #t or #f.
> I am just looking for the concept so that I might be convinced that I should use the racket function as it is, rather than writing a boolean version.
> Thanks  
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120525/136beae5/attachment-0001.html>

Posted on the users mailing list.