From: kavenchuk
Subject: declaim for function returning fixed value.
Date: 
Message-ID: <1140081107.697190.43550@g44g2000cwa.googlegroups.com>
For function returning fixed value (or generate error) such as

(defun fun1 (...) ... t)

what declaim is better:

(declaim (ftype (function (...) (member t)) func1))
or
(declaim (ftype (function (...) (values t)) func1))?

From: Barry Margolin
Subject: Re: declaim for function returning fixed value.
Date: 
Message-ID: <barmar-0D3F82.19093516022006@comcast.dca.giganews.com>
In article <·······················@g44g2000cwa.googlegroups.com>,
 "kavenchuk" <·········@jenty.by> wrote:

> For function returning fixed value (or generate error) such as
> 
> (defun fun1 (...) ... t)
> 
> what declaim is better:
> 
> (declaim (ftype (function (...) (member t)) func1))
> or
> (declaim (ftype (function (...) (values t)) func1))?

The first one.  The VALUES type specifier specifies the number and type 
of multiple values returned, so the second type specifier indicates that 
it returns one value of type T, not one value that *is* T.  If you 
wanted to use VALUES, it would be (values (member t)).

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: ········@comail.ru
Subject: Re: declaim for function returning fixed value.
Date: 
Message-ID: <1140146967.674884.74210@g44g2000cwa.googlegroups.com>
Barry Margolin wrote:

> In article <·······················@g44g2000cwa.googlegroups.com>,
>  "kavenchuk" <·········@jenty.by> wrote:
[...]
> > (declaim (ftype (function (...) (values t)) func1))?
>
> The first one.  The VALUES type specifier specifies the number and type
> of multiple values returned, so the second type specifier indicates that
> it returns one value of type T

According to CLHS the declaration above means that every application of
FUNC1 may be wrapped
into (THE (VALUES (T)) ...), and according to the description of THE
this does not contraint
the number of returned values, so (VALUES T) is effectless. I want to
think that (VALUES T
&OPTIONAL) says that there is exactly one value, but I'm not sure in it.
From: Ivan Boldyrev
Subject: Re: declaim for function returning fixed value.
Date: 
Message-ID: <18dhc3-mu1.ln1@ibhome.cgitftp.uiggm.nsc.ru>
On 9387 day of my life ·········@jenty.by wrote:
> For function returning fixed value (or generate error) such as
>
> (defun fun1 (...) ... t)
>
> what declaim is better:
>
> (declaim (ftype (function (...) (member t)) func1))
> or
> (declaim (ftype (function (...) (values t)) func1))?

None of them is required if Lisp implementation is proper :)

-- 
Ivan Boldyrev

                       Perl is a language where 2 x 2 is not equal to 4.
From: kavenchuk
Subject: Re: declaim for function returning fixed value.
Date: 
Message-ID: <1140425498.622113.326100@g43g2000cwa.googlegroups.com>
How about optimization?
I use sbcl. Simple case:

* (defun f1 (x y)
(declare (type (unsigned-byte 32) x y))
(print (+ x y))
t)

F1
* (describe 'f1)

F1 is an internal symbol in #<PACKAGE "COMMON-LISP-USER">.
Function: #<FUNCTION F1>
Its associated name (as in FUNCTION-LAMBDA-EXPRESSION) is F1.
The function's arguments are:  (X Y)
Its defined argument types are:
  ((UNSIGNED-BYTE 32) (UNSIGNED-BYTE 32))
Its result type is:
  (VALUES (MEMBER T) &OPTIONAL)
On Mon, Feb 20, 2006 10:48:21 AM [-2] it was compiled from:
  (LAMBDA ()
    (SB-INT:NAMED-LAMBDA F1
                         (X Y)
                         (DECLARE (TYPE (UNSIGNED-BYTE 32) X Y))
                         (BLOCK F1 (PRINT (+ X Y)) T)))


In most complete cases result type is define as *

Maybe this nothing...

Thanks!
-- 
WBR, Yaroslav Kavenchuk.