Hi Pascal, Jim,
"Pascal J. Bourguignon" <
p...@informatimago.com> writes:
> jimka <
ji...@rdrop.com> writes:
>
>> Can someone give me some examples of using function type specifiers.
>>
>>
http://www.lispworks.com/documentation/HyperSpec/Body/t_fn.htm
>>
>> I was under the impression that it was possible to specify a function
>> type as a mapping of input types to output types, but from my reading
>> of the spec that doesn't seem to be the case. For example, I thought
>> it was possible to say that binary function F maps (X Y) -> Z and (A
>> B) -> C.
>
> (deftype f () '(or (function (x y) z)
> (function (a b) c)))
This is is not quite the same as INDEPENDENT-DOMAINS-AND-RANGES (cf. my
other post): there is no guarantee you can call an F-typed function with
an A as the first parameter, it may only accept Xs there.
Perhaps AND fits that bill. Do you think it would be a reasonable
interpretation of "intersection of the typespecs"?
(and (function (x y) z)
(function (a b) c))
(For some context: Jim and I have been discussing CL-like type
specifiers for Cadence SKILL on a different forum:
http://www.cadence.com/Community/forums/p/27846/1328863.aspx#1328863 )
> cl-user> (typep (lambda (x y) (declare (integer x y)) (+ x y)) 'f)
> T
>
> Now of course, that doesn't mean much, the implementation may be lying
> to you
It's worse than that:
"An error of type error is signaled if type-specifier is values, or a
type specifier list whose first element is either function or
values." (From
http://clhs.lisp.se/Body/f_typep.htm.)
SBCL will tell you as much :) Which, I guess, is better than lying.
> Basically, function types used this way are all equivalent to FUNCTION,
> since CL doesn't impose the implementations to provide a termination
> proving program.
They're still useful outside of the language's runtime library;
e.g. just as documentation or for type inference:
(defun foo (fn u)
(declare (f fn))
(funcall fn u ...))
=> U is (OR X A)
(foo ... (definitely-an-a))
=> Result is of type C.