How do I pass objects to functions in ooRexx?

267 views Asked by At

I'm a long-time mainframe Rexx programmer who is trying out objects in ooRexx. The results are surprising. For example, here is a program:

#!/usr/bin/rexx

a = .number~new(3.14)

say "a =" a
say "a~val =" a~val

call say_number a

exit 0

say_number:
procedure
parse arg num

    say "In say_number"
    say "num =" num
    say "num~val =" num~val

return

::class number public

::attribute val get public

::method init   ; expose val ; use arg val
::method new    ; expose val ; use arg val
::method string ; return "'"self~val"'"

The result is:

> number
a = '3.14'
a~val = 3.14
In say_number
num = '3.14'
    18 *-*   say "num~val =" num~val
     8 *-* call say_number a
REX0097E: Error 97 running /home/tony/bin/.scripts/number line 18:  Object method not found
REX0476E: Error 97.1:  Object "'3.14'" does not understand message "VAL"

It appears that the object is being resolved to its string value before it's passed to the say_number function. Weird! Am I missing something obvious?

1

There are 1 answers

0
Tony On BEST ANSWER

Well, that didn't take long. I changed parse to use in the function, and everything worked as expected. Per the Reference manual:

USE ARG retrieves the argument objects provided in a program, routine, function, or method and assigns them to variables or message term assignments.

PARSE assigns data from various sources to one or more variables according to the rules of parsing. ... If you specify UPPER, the strings to be parsed are translated to uppercase before parsing. If you specify LOWER, the strings are translated to lowercase. Otherwise no translation takes place.

Presumably PARSE converts the arguments to a string so that it can change case as requested (or defaulted).