From: Javier
Subject: Easier type declarations?
Date: 
Message-ID: <562a27e6-5755-4920-87d9-354f54329118@s36g2000prg.googlegroups.com>
I'd like my Lisp (SBCL) to work friendly with type declarations, so
for example if I have:

(defun fib (n)
  (declare (fixnum n))
  (the fixnum
    (if (< n 2)
	1
      (+ (fib (- n 1)) (fib (- n 2))))))

I would like something like:

(defun fb:fixnum (n:fixnum)
  (if (< n 2)
	  1
	  (+ (fib (- n 1)) (fib (- n 2)))))

If ':' is not convenient (because it is used for packages), any other
single symbol would be nice, too (for example $ % &, etc).
Is this possible? How do I do it?

From: Pascal Costanza
Subject: Re: Easier type declarations?
Date: 
Message-ID: <5qbhvsFup337U1@mid.individual.net>
Javier wrote:
> I'd like my Lisp (SBCL) to work friendly with type declarations, so
> for example if I have:
> 
> (defun fib (n)
>   (declare (fixnum n))
>   (the fixnum
>     (if (< n 2)
> 	1
>       (+ (fib (- n 1)) (fib (- n 2))))))
> 
> I would like something like:
> 
> (defun fb:fixnum (n:fixnum)
>   (if (< n 2)
> 	  1
> 	  (+ (fib (- n 1)) (fib (- n 2)))))
> 
> If ':' is not convenient (because it is used for packages), any other
> single symbol would be nice, too (for example $ % &, etc).
> Is this possible? How do I do it?

In the HyperSpec, there are examples how to express a 
'local-type-declare' macro as part of the issue 
'COMPILER-LET-CONFUSION'. (Since compiler-let is not part of ANSI CL, 
that version of the macro doesn't work, of course.)


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/
From: Marco Antoniotti
Subject: Re: Easier type declarations?
Date: 
Message-ID: <38446acd-a671-483c-899f-2d2ccf094290@e4g2000hsg.googlegroups.com>
You have two issues in your code w.r.t. types

On Nov 18, 8:07 pm, Javier <·······@gmail.com> wrote:
> I'd like my Lisp (SBCL) to work friendly with type declarations, so
> for example if I have:
>
> (defun fib (n)
>   (declare (fixnum n))
>   (the fixnum
>     (if (< n 2)
>         1
>       (+ (fib (- n 1)) (fib (- n 2))))))

One thing is the DECLARE, the other is the THE form.  The first is a
declaration, the second is a promise you make that the expression will
not be changed into a BIGNUM.  These are different things.


>
> I would like something like:
>
> (defun fb:fixnum (n:fixnum)
>   (if (< n 2)
>           1
>           (+ (fib (- n 1)) (fib (- n 2)))))
>
> If ':' is not convenient (because it is used for packages), any other
> single symbol would be nice, too (for example $ % &, etc).
> Is this possible? How do I do it?

Yes, but probably not in the way you want.

One way is to have a syntax almost like defmethod

(defun (fib fixnum) ((n fixnum)) (if ...))

otherwise you can have something like

(defun fixnum fib ((n fixnum)) (if ...))

or

(defun fib => fixnum (n - fixnum) (if ...))

with a syntax gotten from McDermott's NISP and descendants.

You do all these things with macros: the DEFUN in the previous
examples is really NEW-DEFUN:DEFUN.  One cute example about how to
change the syntax of surface is (shameless plug) http://common-lisp.net/project/definer

Cheers

Marco
From: Kaz Kylheku
Subject: Re: Easier type declarations?
Date: 
Message-ID: <fb11b480-d3ce-4286-bf34-15942e7188c5@e6g2000prf.googlegroups.com>
On Nov 18, 11:07 am, Javier <·······@gmail.com> wrote:
> I would like something like:
>
> (defun fb:fixnum (n:fixnum)
>   (if (< n 2)
>           1
>           (+ (fib (- n 1)) (fib (- n 2)))))


You might want to have a look at the thread from November/December
2006 in this newsgroup, with the subject "A Better Syntax for Type
Declarations?"