01: package gnu.commonlisp.lang;
02:
03: import gnu.mapping.*;
04: import gnu.lists.*;
05:
06: /** Support for Lisp Symbols.
07: * The special symbol `nil' is actually the value gnu.lists.LList.Empty. */
08:
09: public class Symbols {
10: private Symbols() {
11: }
12:
13: public static boolean isSymbol(Object val) {
14: return val instanceof String || val == Lisp2.FALSE
15: || val instanceof Symbol;
16: }
17:
18: public static boolean isBound(Object sym) {
19: if (sym == Lisp2.FALSE)
20: return true;
21: Environment env = Environment.getCurrent();
22: Symbol symbol;
23: if (sym instanceof Symbol)
24: symbol = (Symbol) sym;
25: else
26: symbol = env.defaultNamespace().lookup((String) sym);
27: return symbol != null && env.isBound(symbol);
28: }
29:
30: public static Symbol getSymbol(Environment env, Object sym) {
31: if (sym == Lisp2.FALSE)
32: sym = "nil";
33: return sym instanceof Symbol ? (Symbol) sym : env
34: .defaultNamespace().getSymbol((String) sym);
35: }
36:
37: public static Symbol getSymbol(Object sym) {
38: if (sym == Lisp2.FALSE)
39: sym = "nil";
40: return sym instanceof Symbol ? (Symbol) sym : Namespace
41: .getDefaultSymbol((String) sym); // FIXME
42: }
43:
44: public static Object getPrintName(Object sym) {
45: return sym == Lisp2.FALSE ? "nil" : Lisp2
46: .getString(((Symbol) sym).getName());
47: }
48:
49: public static Object getFunctionBinding(Object symbol) {
50: return Environment.getCurrent().getFunction(getSymbol(symbol));
51: }
52:
53: public static Object getFunctionBinding(Environment environ,
54: Object symbol) {
55: return environ.getFunction(getSymbol(symbol));
56: }
57:
58: public static void setFunctionBinding(Environment environ,
59: Object symbol, Object newValue) {
60: environ.put(getSymbol(symbol), EnvironmentKey.FUNCTION,
61: newValue);
62: }
63:
64: }
|