On 5/9/2012 12:00 PM, Jeremy Nicoll - news posts wrote:
> So far as I can tell a caller not providing three arguments gets a syntax
> error (great), but how can I test that in the first case I've actually been
> passed a string, a stem, and a string, whereas in the second there's a stem
> and two strings?
Not as part of the USE instruction. You'll have to test them yourself,
most simply with the IsA method. For a stem, if you're using a stem
variable, be sure to test the argument itself, not the variable, since a
stem object will always be created in the assignment to the stem variable:
Call MyRoutine Larry, Moe, Curly
...
MyRoutine:
use strict arg this,that.,other
Say ' that. is a' that.~class~id /* always 'Stem' */
Say 'Arg(2) is a' Arg(2)~class~id /* whatever class Moe was */
You could wrap the test in a separate routine and pass it the whole set
of arguments in Arg(1,'A') (or .context~args, same thing). I'm not
quite sure what the intended distinction is between error codes 40
(Incorrect call) and 88 (Incorrect argument), but it looks like only 88
has a subcode (914) for the general case:
RequireClasses:
Use Arg arg, class
Do i over class~allIndexes
If \arg[i]~isA(class[i]) then
If class[i] = .stem then
Raise Syntax 88.920 array(i, arg[i])
/* 920 Argument _argument_ must have a stem object or
stem name value; found "_value_"
This could be 40.919 instead, with the same message */
Else
Raise Syntax 88.914 array(i, class[i]~id)
/* 914 Argument _argument_ must be of the class _class_ */
End
Return
MyRoutine:
use strict arg this,that.,other
Call RequireClasses Arg(1,'A'), .array~of(.string, .stem, .string)
ŹR