1 21 22 package org.armedbear.lisp; 23 24 public final class describe extends Lisp 25 { 26 private static final Primitive DESCRIBE = 29 new Primitive("describe", "object &optional stream") 30 { 31 public LispObject execute(LispObject[] args) throws ConditionThrowable 32 { 33 if (args.length != 1) 34 return signal(new WrongNumberOfArgumentsException(this)); 35 LispObject obj = args[0]; 36 StringBuffer sb = new StringBuffer (obj.writeToString()); 37 if (obj instanceof Symbol) { 38 Symbol symbol = (Symbol) obj; 39 LispObject pkg = symbol.getPackage(); 40 sb.append(" is an "); 41 if (pkg == NIL) 42 sb.append("uninterned"); 43 else if (((Package )pkg).findExternalSymbol(symbol.getName()) == symbol) 44 sb.append("external"); 45 else 46 sb.append("internal"); 47 sb.append(" symbol"); 48 if (pkg != NIL) { 49 sb.append(" in the "); 50 sb.append(pkg.getName()); 51 sb.append(" package"); 52 } 53 sb.append(".\n"); 54 LispObject value = symbol.getSymbolValue(); 55 if (symbol.isSpecialVariable()) { 56 sb.append("It is a "); 57 sb.append(symbol.isConstant() ? "constant" : "special variable"); 58 sb.append("; "); 59 if (value != null) { 60 sb.append("its value is "); 61 sb.append(value.writeToString()); 62 } else 63 sb.append("it is unbound"); 64 sb.append(".\n"); 65 } else if (value != null) { 66 sb.append("It is an undefined variable; its value is "); 67 sb.append(value.writeToString()); 68 sb.append(".\n"); 69 } 70 LispObject function = symbol.getSymbolFunction(); 71 if (function != null) { 72 sb.append("Its function binding is "); 73 sb.append(function.writeToString()); 74 sb.append(".\n"); 75 if (function instanceof Function) { 76 LispObject arglist = ((Function)function).getArglist(); 77 if (arglist != null) { 78 LispThread thread = LispThread.currentThread(); 79 Environment oldDynEnv = thread.getDynamicEnvironment(); 80 thread.bindSpecial(_PRINT_ESCAPE_, NIL); 81 sb.append("Function argument list:\n "); 82 if (arglist instanceof AbstractString) 83 sb.append(arglist.getStringValue()); 84 else 85 sb.append(arglist.writeToString()); 86 sb.append('\n'); 87 thread.setDynamicEnvironment(oldDynEnv); 88 } 89 } 90 LispObject documentation = 91 symbol.getFunctionDocumentation(); 92 if (documentation instanceof AbstractString) { 93 sb.append("Function documentation:\n "); 94 sb.append(documentation.getStringValue()); 95 sb.append('\n'); 96 } 97 } 98 LispObject plist = symbol.getPropertyList(); 99 if (plist != NIL) { 100 sb.append("Its property list has these indicator/value pairs:\n"); 101 LispObject[] array = plist.copyToArray(); 102 for (int i = 0; i < array.length; i += 2) { 103 sb.append(" "); 104 sb.append(array[i].writeToString()); 105 sb.append(' '); 106 sb.append(array[i+1].writeToString()); 107 sb.append('\n'); 108 } 109 } 110 } 111 Stream out = getStandardOutput(); 112 out.freshLine(); 113 out._writeString(sb.toString()); 114 out.freshLine(); 115 return LispThread.currentThread().nothing(); 116 } 117 }; 118 } 119 | Popular Tags |