代码之家  ›  专栏  ›  技术社区  ›  Vijay Mathew Chor-ming Lung

smalltalk中的函数对象(或执行不带“value:`”的块)

  •  6
  • Vijay Mathew Chor-ming Lung  · 技术社区  · 14 年前

    是否可以向对象发送匿名消息?我想组合三个这样的对象(想想fp):

     " find inner product "
     reduce + (applyToAll * (transpose #(1 2 3) #(4 5 6)))
    

    哪里 reduce , applyToAll transpose 是对象和 + , * 这两个数组是传递给发送给这些对象的匿名消息的参数。是否可以实现相同的使用块?(但没有明确使用 value: )

    3 回复  |  直到 14 年前
        2
  •  5
  •   Stephan Eggermont    14 年前
    aRealObject reduceMethod: +; 
                applyToAll: *; 
                transpose: #(#(1 2 3) #(4 5 6));
                evaluate
    

        3
  •  3
  •   codefrau    14 年前

    doesNotUnderstand: reduce +

    Reduce

    doesNotUnderstand: aMessage
        ^aMessage argument reduce: aMessage selector
    

    Reduce + (#(1 2 3) * #(4 5 6))
    

    *

    ApplyToAll

    doesNotUnderstand: aMessage
        ^aMessage argument collect: [:e | e reduce: aMessage selector]
    

    SequenceableCollection

    transposed
        ^self first withIndexCollect: [:c :i | self collect: [:r | r at: i]]
    

    Reduce + (ApplyToAll * #((1 2 3) #(4 5 6)) transposed)