Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I check that arguments passed to an ooREXX function are the right type?

24 views
Skip to first unread message

Jeremy Nicoll - news posts

unread,
May 9, 2012, 12:00:00 PM5/9/12
to
I have a function which, according to its first parameter needs different
arguments passed to it. I'm experimenting with code starting:

use arg verb, ...

then depending on 'verb' have statements like:

use strict arg this,that.,other

or use strict arg one.,two,three

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? I guess there's two issues - making sure the stem is in
the right place, and making sure that things I expect to be strings aren't
for example arrays.

--
Jeremy C B Nicoll - my opinions are my own.

Email sent to my from-address will be deleted. Instead, please reply
to newsre...@wingsandbeaks.org.uk replacing "aaa" by "284".

Sahananda

unread,
May 9, 2012, 3:49:39 PM5/9/12
to
You could use the isA method of the object class and therefore inherited by all.

a = 'hello'
say a~isA(.string)
b.2 = 'why do people still use stems?'
say b.~isA(.string)
say b.~isA(.stem)

hth

Jon

Glenn Knickerbocker

unread,
May 9, 2012, 6:55:26 PM5/9/12
to
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

Jeremy Nicoll - news posts

unread,
May 12, 2012, 8:59:00 AM5/12/12
to
Glenn Knickerbocker <No...@bestweb.net> wrote:

> 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...

Thanks for a fantastically thorough answer. I'd have replied earlier but my
internet connection provider generously provided me with 36 hours of no
connectivity...
0 new messages