Search code examples
squeak

Passing functions as parameters in Squeak


Since Squeak is purely Object Oriented I'm fairly certain that you should be able to pass functions as parameters to other functions, but when I was researching on this I couldn't find any information about this. Is my intuition correct? And if so, how is it done and how do I invoke them afterwards?


Solution

  • You're confusing two different things. The only real "functions" you pass around in Smalltalk are blocks, which you pass just by writing a block as an argument (like you do with every ifTrue:). If you want to send a message to an object but have the message be determined dynamically, you can pass the message name as a symbol (e.g. #value) and send it to some object (e.g. with perform:). You don't pass instance methods themselves. Either pass a selector symbol or pass a block that sends a message to call the method.