Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function objects in Smalltalk (or executing blocks with no `value:`)

Is it possible to send an anonymous message to an object? I want to compose three objects like this (think FP):

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

where reduce, applyToAll and transpose are objects and +, * and the two arrays are arguments passed to anonymous messages sent to those objects. Is it possible to achieve the same using blocks? (but no explicit usage of value:).

like image 822
Vijay Mathew Avatar asked Nov 08 '10 06:11

Vijay Mathew


2 Answers

Perhaps what you really want to do is define a DSL inside Smalltalk?

With HELVETIA we explore a lightweight approach to embed new languages into the host language. The approach reuses the existing toolchain of editor, parser, compiler and debugger by leveraging the abstract syntax tree (AST) of the host environment. Different languages cleanly blend into each other and into existing code.

like image 61
nes1983 Avatar answered Sep 21 '22 10:09

nes1983


aRealObject reduceMethod: +; 
            applyToAll: *; 
            transpose: #(#(1 2 3) #(4 5 6));
            evaluate

would work when aRealObject has defined the right methods. Where do you need a block?

like image 34
Stephan Eggermont Avatar answered Sep 21 '22 10:09

Stephan Eggermont