pharo

Is it possible to extend an individual object in Smalltalk

半城伤御伤魂 提交于 2019-11-29 01:56:36
I'm doing research in Smalltalk reflection, and I was wondering if it was possible to extend an individual object like that would be possible for instance in Ruby. With this I mean a selector that only particular objects respond to. Here is some Ruby code that states what I mean. For clarification: in Ruby this open a virtual class for this object, and extends it with a new definition. The vital part here is that nothing changes to the class definition! o = Object.new o.instance_eval {def foo;puts "foo";end} o.foo #=> "foo" #however this will fail: m = Object.new m.foo #=> NoMethod error More

Why shouldn't I store into literal arrays in Smalltalk?

白昼怎懂夜的黑 提交于 2019-11-28 12:23:59
Some style-guides and idioms suggest that you should not mutate literal arrays, like in this case: MyClass>>incrementedNumbers | numbers | numbers := #( 1 2 3 4 5 6 7 8 ). 1 to: numbers size: do: [:index | numbers at: index put: (numbers at: index) + 1]. ^ numbers Why should I not do that? Tobias Note: The following is implementation dependent. The ANSI Smalltalk Standard defines: It is unspecified whether the values of identical literals are the same or distinct objects. It is also unspecified whether the values of separate evaluations of a particular literal are the same or distinct objects.