RosettaCodeData/Task/Delegates/PicoLisp/delegates.l
Ingy döt Net 80737d5a6a new tasks
2013-04-09 00:46:50 -07:00

30 lines
555 B
Text

(class +Delegator)
# delegate
(dm operation> ()
(if (: delegate)
(thing> @)
"default implementation" ) )
(class +Delegate)
# thing
(dm T (Msg)
(=: thing Msg) )
(dm thing> ()
(: thing) )
(let A (new '(+Delegator))
# Without a delegate
(println (operation> A))
# With delegate that does not implement 'thing>'
(put A 'delegate (new '(+Delegate)))
(println (operation> A))
# With delegate that implements 'thing>'
(put A 'delegate (new '(+Delegate) "delegate implementation"))
(println (operation> A)) )