annotate samples/reflect.tp @ 270:b74956a2196f

Add a propertiesOf method to the object module that returns the names of things that look like getter messages
author Michael Pavone <pavone@retrodev.com>
date Fri, 18 Jul 2014 20:45:50 -0700
parents 123e9468d55e
children
rev   line source
pavone@266 1 #{
pavone@266 2 main <- {
pavone@270 3 o <- #{
pavone@270 4 foo <- 42
pavone@270 5 bar <- 39
pavone@270 6 doStuff <- :blah {
pavone@270 7 foo <- bar * blah
pavone@270 8 foo
pavone@270 9 }
pavone@270 10 qux <- { 1337 }
pavone@270 11 + <- :right {
pavone@270 12 foo + right
pavone@270 13 }
pavone@270 14 }
pavone@270 15 print: (string: (object does: o understand?: "+")) . "\n"
pavone@270 16 print: (string: (object does: o understand?: "foobar")) . "\n"
pavone@270 17 print: (string: (object sendMessage: "qux" to: o)) . "\n"
pavone@270 18 print: "Messages understood:\n"
pavone@270 19 foreach: (object understoodBy: o) :idx el{
pavone@266 20 print: el . "\n"
pavone@266 21 }
pavone@270 22 print: "\nProperties of:\n"
pavone@270 23 foreach: (object propertiesOf: o) :idx el{
pavone@270 24 print: el . "\n"
pavone@270 25 }
pavone@266 26 0
pavone@266 27 }
pavone@266 28 }