Skip to content
gdm9000 edited this page Jun 24, 2017 · 2 revisions

Rexx, introduced in 1979, is a scripting language. I really don't know much about it; I was able to bang this version of Euler1 out in about 15 minutes:

/* Euler1 in Rexx */

SAY Euler1(1000)
EXIT

Euler1:
    PROCEDURE
    PARSE ARG size
    retval = 0
    DO i = 1 TO size-1
        IF i//(3)==0 THEN
            retval = retval + i
        ELSE IF i//5==0 THEN
            retval = retval + i
    END
    RETURN retval

And here is a version using OOP. Yes, I know it's contrived; cut me some slack - this problem is too simple to lend itself to OOP cleanly. This is very much like OOP in other languages - just with different syntax. The constructor is defined with the keyword init, and a string representation of self with keyword string, analogous to Java's toString. Messages are passed using a tilde, as in the dot operator in C++/Java/C#. And the keyword EXPOSE is used to declare that class-level members are to be used instead of local variables, analogous to self or this in other OO languages. It took me maybe 45 minutes to figure out this example:

/* Euler1 in Rexx */

euler = .Euler1~new(1000)
euler~solve
SAY euler
EXIT

::CLASS Euler1
    ::ATTRIBUTE size
    ::ATTRIBUTE result

    ::METHOD init
        EXPOSE size
        USE ARG size

    ::METHOD solve
        EXPOSE size result
        result = 0
        DO i = 1 TO size-1
            IF i//(3)==0 THEN
                result = result + i
            ELSE IF i//5==0 THEN result = result + i
        END

    ::METHOD string
        EXPOSE result
        RETURN result

For these examples, I used Open Object Rexx. Yum-install rexx and rexx-devel. Then simply invoke Rexx's interpreter, passing it your script as an argument. Rexx doesn't care if you add the file extension or not:

$ rexx euler1
233168
Clone this wiki locally