Arc Forumnew | comments | leaders | submitlogin
Reflection in arc?
8 points by applepie 6154 days ago | 3 comments
Is there a way of reifying environments (probably into tables)?

Or a function similar to Python's dir?



9 points by sacado 6154 days ago | link

add this to ac.scm :

  (xdef 'all-symbols
      (lambda ()
        (let ((result '()))
          (for-each (lambda (sym)
                      (let ((s-sym (symbol->string sym)))
                        (if (eqv? #\_ (string-ref s-sym 0))
                            (set! result (cons (string->symbol (substring s-sym 1)) result)))))
                    (namespace-mapped-symbols))
          result)))
After that, in arc, the call (all-symbols) returns you the list of all global symbols. Then it should be easy to get what you want...

-----

3 points by sacado 6154 days ago | link

(listtab:map [list _ eval._] (all-symbols)) then gives you the above as a table.

-----

2 points by bogomipz 6154 days ago | link

When you say environment, do you mean lexical environment or global namespace? Neither is possible today, I believe, but when someoneā„¢ writes a module system for Arc, namespaces will hopefully be right at your finger tips (if implemented as Arc tables).

-----