質問

My class:

declare
class Collection
   attr list

   meth init
      list := nil
   end

   meth put(X)
      list := X|@list
   end

   meth get($)
      if @list == nil then
         nil
      else
         local X in
            X = @list.1
            list := @list.2
            X
         end
      end
   end
end

My test usage:

declare
C = {New Collection init}
{C put(4)}
{C put(5)}
{Browse {C get}}

Error:

%********************** static analysis error *******************
%**
%** illegal number of arguments in object application
%**
%** Object:       C
%** Number found: 2
%** Expected:     1
%** in file "Oz", line 62, column 9
%** ------------------ rejected (1 error)

Line 62 is the line with "Browse"


Is this because Oz tries to use the object procedure like a function by passing a result argument? If so, what is the point of functional methods? How does one use them?

役に立ちましたか?

解決

The syntax for calling such a method is:

{Browse {C get($)}}

The reason is that objects are basically stateful procedures that receive messages. (The syntax is unusual and initially difficult to grok. It is, however, highly regular and powerful.)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top