Created
May 22, 2011 15:10
-
-
Save th0ma5w/985557 to your computer and use it in GitHub Desktop.
Python-like dir function for scheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;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