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))?
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 ***
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.
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.
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.