From: Gabor Melis
Subject: (satisfies #'(lambda (x) t))
Date: 
Message-ID: <fb0fb805.0303270655.77c954b0@posting.google.com>
No, it doesn't work. And yes, it is according to the spec. Satisfies
takes a symbol as its argument, which makes it hard to write type
specifiers the like of (at-least 5):

(deftype at-least (threshold)
  `(satisfies ,#'(lambda (x) (>= x threshold))))

Mild research on this subject turned up this oldish thread:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=m3n1yn67ts.fsf%40shodan.demon.co.uk&rnum=7&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DISO-8859-1%26q%3Dsatisfies%2Bsymbol%26meta%3Dgroup%253Dcomp.lang.lisp.*

The conclusion of which is a compiler patch is needed to do it
cleanly. Another solution - albeit an ugly one - might be this:

(make-package "SATISFIES2")

(deftype satisfies2 (fn)
  (let ((sym (gentemp "" "SATISFIES2")))
    (setf (symbol-function sym) #'(lambda (x) (funcall fn x)))
    `(satisfies ,sym)))

(deftype at-least (threshold)
  `(satisfies2 ,#'(lambda (y) (>= y threshold))))

(typep 5 '(at-least 3)) => T
(typep 1 '(at-least 3)) => NIL

It seems to work in CMUCL and Clisp, but of course it creates a small
closure for each of its occurences in the code and that closure is
permanent, but it's not that bad. Or is it?

Cheers, Gabor
From: Kent M Pitman
Subject: Re: (satisfies #'(lambda (x) t))
Date: 
Message-ID: <sfwel4shkkp.fsf@shell01.TheWorld.com>
ยทยทยทยท@hotpop.com (Gabor Melis) writes:

> No, it doesn't work. And yes, it is according to the spec. Satisfies
> takes a symbol as its argument, which makes it hard to write type
> specifiers the like of (at-least 5):
> 
> (deftype at-least (threshold)
>   `(satisfies ,#'(lambda (x) (>= x threshold))))
> 
> Mild research on this subject turned up this oldish thread:
> http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=m3n1yn67ts.fsf%40shodan.demon.co.uk&rnum=7&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DISO-8859-1%26q%3Dsatisfies%2Bsymbol%26meta%3Dgroup%253Dcomp.lang.lisp.*
> 
> The conclusion of which is a compiler patch is needed to do it
> cleanly. Another solution - albeit an ugly one - might be this:
> 
> [...]
>
> It seems to work in CMUCL and Clisp, but of course it creates a small
> closure for each of its occurences in the code and that closure is
> permanent, but it's not that bad. Or is it?

The spec doesn't require it to work.  It's not that we didn't anticipate
the need--we just didn't believe we had thoroughly enough addressed the
underlying concepts, both implementationally and philosophically, to be
able to allow it to work.

You want to read:

 3.2.4 Literal Objects in Compiled Files
read all of this


 3.2.4.1 Externalizable Objects
read all of this

 3.2.4.2.2 Definition of Similarity
take note of:

 ...
 functions
   Functions are not externalizable objects. 
 ...