Yeah, this is an area that is a bit confusing.  The UNKNOWN method
described in section 4.2.6 is not the same concept that the directory class
uses with SETMETHOD.

Section 4.2.6 describes the general concept of an UNKNOWN method that gets
invoked if an object does not implement a method. The directory SETMETHOD
capability defines methods that are used by the directory object for index
lookups.  These methods can be named, which means if one uses SETMETHOD to
define a 'FOO' method, then lookups for 'FOO' will invoke that method to
retrieve the result.  This applies to both the "d~foo" and "d["FOO"]"
syntaxes.  AN UNKNOWN method defined using SETMETHOD is special and will be
used whenever an index is not found (either directly or by having a defined
SETMETHOD method that matches the index). The setmethod methods are
intended just for index retrieval, not a generalized UNKNOWN capability. In
fact the directory class uses the generalized UNKNOWN capability to
implement lookups like "d~foo".  The directory object's UNKNOWN method gets
invoked first, which drives the index lookup code, which might then result
in an UNKNOWN method that had been setup via SETMETHOD getting invoked.

The lookup mechanism does not pass on arguments, and in fact, since the
same code is used for both the "d~foo" and "d['FOO'}" forms, is not even
aware that additional arguments were passed.  If anything, the directory
UNKNOWN method should be giving an error message if any arguments are
specified.

Rick

On Mon, Apr 18, 2016 at 10:13 AM, Jeremy Nicoll <
jn.ml.sfrg...@letterboxes.org> wrote:

> Using: REXX-ooRexx_4.2.0(MT)_64-bit 6.04 22 Feb 2014    on W8.1, 64-bit
>
> I ran a copy of the  'directory' class telephone-book example that's
> example 5.166 in the Reference manual,
> and tried to explore the 'unknown' method part of that more. According
> to example 4.9 in section 4.2.6 on
> "defining an unknown method" one can see both the method name and
> original arguments on an unknown
> method call, and that latter example shows:
>
> ::method unknown
> expose target -- will receive all of the messages
> use arg name, arguments
> say name "invoked with" arguments~toString
>
> so I ended up in my version of the telephone directory program with
> mainline code:
>
> say "Look-up by unknown index:"
> say
> say '- book["M"]'
> say '-' book["M"]       /* -> "Mike H. ...... 555-6123, Mark C. ......
> 555-5017" */
>
> say
> say '- book~P'
> say '-' book~P                          /* -> "No listing found for P"
> */
>
> say
> say '- book~Q(4,5)'
> say '-' book~Q(4,5)                     /* -> "No listing found for Q"
> */
>
> and was hoping that in my adapted unknown method code I'd be able to
> access the arguments "4,5" shown
> on that last call.  My unknown method, activated by
>
> book = .directory~new~~setMethod("UNKNOWN", .methods["LOOKUPUNKNOWN"])
>
> (because unlike the example in the manual I wanted to differentiate
> between the first and second parameters
> of setMethod, which in the phone book example were both "UNKNOWN")
> starts off with:
>
> ::Method lookupunknown
>    use arg at_index, origargsarray
>    say "lookupunknown: at_index="at_index
>       say "lookupunknown: origargsarray:" origargsarray
>    /* say "lookupunknown: origargsarray:" origargsarray~toString */
>
> If I run that, output for the ~Q(4,5) call shows:
> - book~Q(4,5)
> lookupunknown: at_index=Q
> lookupunknown: origargsarray: ORIGARGSARRAY
>
> If I uncomment the line with  ~toString in it, I get
>
> Error 97 running C:\Dropbox\JN_RexxExecs\test _JN_Common Code
> Routines.rexp line 95:  Object method not found
> Error 97.1:  Object "ORIGARGSARRAY" does not understand message
> "TOSTRING"
>
>
> If I change the method code to display at_index~class and
> origargsarray~class, both tell me that those are "The String class".
>
> So, is example 4.9 in section 4.2.6 wrong, or have I misapplied it in my
> method?
>
> --
> Jeremy Nicoll - my opinions are my own.
>
>
> ------------------------------------------------------------------------------
> Find and fix application performance issues faster with Applications
> Manager
> Applications Manager provides deep performance insights into multiple
> tiers of
> your business applications. It resolves application problems quickly and
> reduces your MTTR. Get your free trial!
> https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
> _______________________________________________
> Oorexx-users mailing list
> Oorexx-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-users
>
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to