How to resolve the algorithm Reflection/List methods step by step in the PicoLisp programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Reflection/List methods step by step in the PicoLisp programming language

Table of Contents

Problem Statement

The goal is to get the methods of an object, as names, values or both. Some languages offer dynamic methods, which in general can only be inspected if a class' public API includes a way of listing them.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Reflection/List methods step by step in the PicoLisp programming language

Source code in the picolisp programming language

# 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'

: (setq R (new '(+Rectangle) 0 0 30 20)) 
-> $177356065126400

: (methods R)
-> ((draw> . +Rectangle) (perimeter> . +Rectangle) (area> . +Rectangle) (T . +Rectangle) (move> . +Shape))


  

You may also check:How to resolve the algorithm Casting out nines step by step in the Lua programming language
You may also check:How to resolve the algorithm FizzBuzz step by step in the Retro programming language
You may also check:How to resolve the algorithm Superellipse step by step in the jq programming language
You may also check:How to resolve the algorithm Sorting algorithms/Cocktail sort with shifting bounds step by step in the Groovy programming language
You may also check:How to resolve the algorithm Tonelli-Shanks algorithm step by step in the Nim programming language