【问题标题】:Why can't I get functional methods to work?为什么我不能让函数式方法起作用?
【发布时间】:2014-05-27 08:32:31
【问题描述】:

我的班级:

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

我的测试用法:

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

错误:

%**********************静态分析错误********************
%**
%** 对象应用程序中的参数数量非法
%**
%** 对象:C
%** 找到的数字:2
%** 预期:1
%** 在文件“Oz”中,第 62 行,第 9 列
%** ------------------ 被拒绝(1 个错误)

第 62 行是带有“浏览”的行


这是因为 Oz 试图通过传递结果参数来像函数一样使用对象过程吗?如果是这样,函数式方法的意义何在?如何使用它们?

【问题讨论】:

    标签: oz mozart


    【解决方案1】:

    调用这种方法的语法是:

    {Browse {C get($)}}
    

    原因是对象基本上是接收消息的有状态过程。 (语法不寻常,最初难以理解。然而,它非常规则且功能强大。)

    【讨论】:

    • 谢谢。如果没有你告诉我,我不知道我怎么会想到这一点。 Oz 似乎不是记录最完整的语言。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    • 2015-03-14
    • 2014-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多