argument checking, was: About submatrix and its meaning
Subject: argument checking, was: About submatrix and its meaning
From: Richard Fateman
Date: Mon, 23 Nov 2009 07:57:20 -0800
Raymond Toy wrote:
> 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.
>
Actually, what I was thinking was more along the lines of what Ray was
suggesting. E.g.
foo(a,b,c):= (
check_args(foo,[a,listp],[b,integerp],[[a,b,c], a+b>c]),
... body of foo ...
)
where we could generate messages like
foo was given argument x which was supposed to be integerp.
The addition of more "syntax" is certainly not required.
RJF