Consider the following class:

This class (assuming there aren't any typos...) remembers
functions and allows them to be invoked later by name.
-------------------------------
class A (services)

    method add(sName, func)
        services[sName] := func
    end

    method run(sName, args[])
        (\services[sName]) ! args
    end

    initially ()
        services := table()
end
-------------------------------

Now suppose it were written as:

-------------------------------
class A (services)

    method add(sName, func)
        services[sName] := func
    end

    method run(sName, args[])
        (\services[sName]) ! args
    end

    method help()
        write("Known services are: ")
        every write("\t",(!sort(services))[1])
    end

    initially ()
        services := table()
        add("help", help)
end
-------------------------------

which strikes me as semi-useful:  the class could invoke it's
own methods using the same mechanism used to invoke 'outside'
functions.

Unfortunately, it doesn't work.  Where it dies is a bit
odd, however: it dies on the line:

    add("help", help)

apparently trying to call (the string) "help" instead of the
method add().

Now, I'm not sure if it would work anyway - the f!a operator
would also have to recognize that f is a method in the the
'surrounding' class and munge the argument list properly -
but I'm wondering if this should be doing something different
than it does or if there is an explanation for the current
behavior?

(Note that any non-call reference of a method name produces
similar errors:  replacing the 'add("help", help)' line
with just:

   f := help

generates an error, even if f isn't dereferenced elsewhere.)

-- 
Steve Wampler <[EMAIL PROTECTED]>
National Solar Observatory


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to