Hi,
Is there a function in the specification to convert a value to a
boolean? It could be implemented like:
(defun bool (&optional (x nil))
(if x t nil))
or
(defun bool (&optional (x nil))
(not (not x)))
But I want to know if the specification already have something like it.
I looked and only found the 'boole' function.
It's useful to do things like:
;; returns true if all elements in sequence are true
(every #'bool sequence)
Pedro Kroger
From: Pascal Costanza
Subject: Re: is there a function to convert a value to a boolean?
Date:
Message-ID: <4sed2lFvak1nU1@mid.individual.net>
Pedro Kr�ger wrote:
> Hi,
>
> Is there a function in the specification to convert a value to a
> boolean? It could be implemented like:
>
> (defun bool (&optional (x nil))
> (if x t nil))
>
> or
>
> (defun bool (&optional (x nil))
> (not (not x)))
>
> But I want to know if the specification already have something like it.
> I looked and only found the 'boole' function.
>
> It's useful to do things like:
>
> ;; returns true if all elements in sequence are true
> (every #'bool sequence)
What's wrong with (every #'identity sequence)?
Pascal
--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
Pascal Costanza wrote:
> What's wrong with (every #'identity sequence)?
nothing, I forgot about identity. Thanks a lot.
Pedro
From: Tin Gherdanarra
Subject: Re: is there a function to convert a value to a boolean?
Date:
Message-ID: <4sf2gsFvlu2mU1@mid.individual.net>
Pedro Kr�ger wrote:
> Hi,
>
> Is there a function in the specification to convert a value to a
> boolean? It could be implemented like:
>
> (defun bool (&optional (x nil))
> (if x t nil))
>
> or
>
> (defun bool (&optional (x nil))
> (not (not x)))
>
> But I want to know if the specification already have something like it.
> I looked and only found the 'boole' function.
>
> It's useful to do things like:
>
> ;; returns true if all elements in sequence are true
> (every #'bool sequence)
>
> Pedro Kroger
>
This is more about the names. We can have a
two-people-standard on this:
(defun truth (x)
(if (null x) nil t))
(defun truthp (x)
(or (eq t x) (eq nil x)))
(defun truth-from-int (i)
(not (zerop i)))
(defun int-from-truth (b)
(if b 1 0))
I use these quite frequently for my chip-simulations.
I could not find other uses. What are you building at
home?
--
Lisp kann nicht kratzen, denn Lisp ist fluessig
Tin Gherdanarra wrote:
> This is more about the names. We can have a
> two-people-standard on this:
thanks for the code.
> I use these quite frequently for my chip-simulations.
> I could not find other uses. What are you building at
> home?
nothing special, just studying lisp.
pedro