| I learned somewhat recently that Scheme has this 'namespace-mapped-symbols procedure that returns a list of all symbols bound in the given namespace (defaulting to the current namespace). Now, all Arc symbols show up in the Scheme namespace with an underscore in front of them (e.g. as _def). Given a way to execute Scheme expressions (with my version of ac.scm, this is done by wrapping the expression in 'mz; Anarki does something similar with '$), we can get all Arc symbols like this: arc> (map [sym:cut _ 1] (keep [is _.0 #\_] (map string (mz
(namespace-mapped-symbols)))))
(username-taken goodname vals thatexpr equal ... [and 900 more symbols])
We can use this to construct a nice "apropos" function, sort of like what Common Lisp provides. The following code works in Anarki (the only thing not in vanilla Arc is the $ thing for raw Scheme code): (def arc-environment ()
(map [sym:cut _ 1] (keep [is _.0 #\_]
(map string ($.namespace-mapped-symbols)))))
(def apropos-fn (x)
(map sym (keep [findsubseq x _]
(map string (arc-environment)))))
(mac aps (x) `(apropos-fn (string ',x)))
Here it is in action (most of these functions are mine): arc> (aps cli)
(clipboard click tclick reclist click-sleeps click-secs click-drag
unclick client-ip)
We can even use the dot notation! I find it very pleasant to type a dot instead of two parentheses into the REPL. arc> aps.cli
(clipboard click tclick reclist click-sleeps click-secs click-drag
unclick client-ip)
For how to make raw Scheme expressions work without the whole Anarki package, consult either http://arclanguage.org/item?id=8719 or http://awwx.ws/scheme0. Then replace the $ in my code with mz or scheme. |