From: David Bakhash
Subject: declaring return type of a function
Date: 
Message-ID: <cxjk904toc9.fsf@engc.bu.edu>
Hi,

In general I'm satisfied with the way that lisp deals with type
declarations, except that if there's a function that I use a lot, and
I know it to return, say, a fixnum, then it becomes a lot of work, and
hassle to use the `the' macro everywhere to declare the return type of
that function:

(progn
  ...code...
  (setq x (+ *some-number*
	     (the fixnum (f z))))
  ...more code...
  )

However, I don't see anywhere in the type declarations, the ability to 
tell Lisp the return type of that function everywhere in the code, to
avoid this unnecessary hassle.

dave

From: Matthias H�lzl
Subject: Re: declaring return type of a function
Date: 
Message-ID: <86k904rvmu.fsf@gauss.muc.de>
David Bakhash <·····@bu.edu> writes:

> In general I'm satisfied with the way that lisp deals with type
> declarations, except that if there's a function that I use a lot, and
> I know it to return, say, a fixnum, then it becomes a lot of work, and
> hassle to use the `the' macro everywhere to declare the return type of
> that function:
> 
> (progn
>   ...code...
>   (setq x (+ *some-number*
> 	     (the fixnum (f z))))
>   ...more code...
>   )
> 
> However, I don't see anywhere in the type declarations, the ability to 
> tell Lisp the return type of that function everywhere in the code, to
> avoid this unnecessary hassle.

If I understand you correctly

(declaim (ftype (function (t) fixnum) f)) resp. (declare ...)

is what you are looking for.  That is, the program 

(declaim (ftype (function (integer) fixnum) foo))
(declaim (ftype (function (integer) symbol) bar))

(defun foo (i)
  (declare (ignore i))
  2)

(foo (bar 1))

will result in the following compiler output from CMUCL:

* (compile-file "home:test/declaration-2")
Python version 1.0, VM version Intel x86 on 07 DEC 98 01:17:25 pm.
Compiling: /home/tc/prog/lisp/progs/test/declaration-2.lisp 07 DEC 98 01:17:11 pm

Converted FOO.
Compiling DEFUN FOO: 
Byte Compiling Top-Level Form: 

File: /home/tc/prog/lisp/progs/test/declaration-2.lisp

In: FOO (BAR 1)
  (BAR 1)
Warning: Result is a SYMBOL, not a INTEGER.


Compilation unit finished.
  1 warning


home:test/declaration-2.x86f written.
Compilation finished in 0:00:00.

#p"/home/tc/prog/lisp/progs/test/declaration-2.x86f"
T
T
* 

Regards,

  Matthias
From: Steve Gonedes
Subject: Re: declaring return type of a function
Date: 
Message-ID: <m23e6s7wov.fsf@KludgeUnix.com>
David Bakhash <·····@bu.edu> writes:

< 
< Hi,
< 
< In general I'm satisfied with the way that lisp deals with type
< declarations, except that if there's a function that I use a lot, and
< I know it to return, say, a fixnum, then it becomes a lot of work, and
< hassle to use the `the' macro everywhere to declare the return type of
< that function:
< 
< (progn
<   ...code...
<   (setq x (+ *some-number*
< 	     (the fixnum (f z))))
<   ...more code...
<   )

You could probably get away with wrapping the last form with a `the'.

(defun this ()
  (setq ...)
   (the fixnum x))