Jump to content

Reflection/List methods: Difference between revisions

added PicoLisp
(Added Wren)
(added PicoLisp)
Line 866:
}
</pre>
 
 
=={{header|PicoLisp}}==
The function <code>methods</code> can be used to print all methods of an object (only in debug mode):
 
First we define a rectangle class <code>+Rectangle</code> as subclass of a shape class <code>+Shape</code>:
 
<lang PicoLisp>
# The Rectangle class
(class +Rectangle +Shape)
# dx dy
 
(dm T (X Y DX DY)
(super X Y)
(=: dx DX)
(=: dy DY) )
 
(dm area> ()
(* (: dx) (: dy)) )
 
(dm perimeter> ()
(* 2 (+ (: dx) (: dy))) )
 
(dm draw> ()
(drawRect (: x) (: y) (: dx) (: dy)) ) # Hypothetical function 'drawRect'
</lang>
 
Then we can create an object of the +Rectangle class and check its methods using the <code>method</code> function.
 
<lang>
: (setq R (new '(+Rectangle) 0 0 30 20))
-> $177356065126400
 
: (methods R)
-> ((draw> . +Rectangle) (perimeter> . +Rectangle) (area> . +Rectangle) (T . +Rectangle) (move> . +Shape))
</lang>
 
 
 
 
=={{header|Python}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.