Skip to content

Instantly share code, notes, and snippets.

@th0ma5w
Created May 22, 2011 15:10
Show Gist options
  • Save th0ma5w/985557 to your computer and use it in GitHub Desktop.
Save th0ma5w/985557 to your computer and use it in GitHub Desktop.
Python-like dir function for scheme
;Python-like dir function for Kawa scheme objects (but not the global namespace)
(require 'list-lib)
(require <kawa.lib.srfi95>)
;retrieve class name as string
(define classname (lambda (x) (invoke x 'getName)))
;make a one-dimensional array into a list
(define tolist (lambda (l) (map l (iota l:length))))
;list out a class's fields or methods
(define get-fields (lambda (class)
(tolist (invoke (class:getClass) 'getFields))))
(define get-methods (lambda (class)
(tolist (invoke (class:getClass) 'getMethods))))
;created a sorted list of fields and methods, denoting methods with ()
(define dir (lambda (class)
(sort (append
(map classname (get-fields class))
(map (lambda (x) (string-append x "()"))
(map classname (get-methods class)))
) string<=?)))
;;; Example
;(define f (java.io.File "."))
;(dir f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment