argument checking, was: About submatrix and its meaning
Subject: argument checking, was: About submatrix and its meaning
From: Raymond Toy
Date: Mon, 23 Nov 2009 09:36:01 -0500
Robert Dodier wrote:
> On 11/21/09, Kostas Oikonomou <ko at research.att.com> wrote:
>
>
>> How about a question mark? E.g. "x?listp".
>>
>> foo(P(x)) is too much like f(g(x)), function composition.
>>
>
> Well, it turns out "?" interferes with the use of ? to indicate
> Lisp symbols. But "??" is OK.
>
> Here's a first attempt to use "??" expressions to indicate
> argument-checking predicates in function definitions.
>
> foo (x??integerp) := ifactors (x);
> foo (1234);
> => [[2, 1], [617, 1]]
> foo (a + 1);
> => foo: expected argument x to satisfy integerp test; found: a + 1
> bar (a ?? lambda ([x], is (abs (x) < 1))) := 1/(1 - a);
> bar (1/2);
> => 2
> bar (2);
> => bar: expected argument a to satisfy lambda([x], is(abs(x) < 1))
> test; found: 2
>
>
> What do you think? Patch attached.
>
>
Interesting idea and approach.
I think I'd rather just leave the argument checking in the body of the
function itself, perhaps adding a function check_type that does the
checking that you show above.
Ray