Refactored the built in function quote
This commit is contained in:
parent
38db0862ff
commit
35ef281733
|
@ -1,41 +1,23 @@
|
||||||
package function.builtin.special;
|
package function.builtin.special;
|
||||||
|
|
||||||
import function.LispFunction;
|
import function.*;
|
||||||
import function.builtin.cons.LENGTH;
|
|
||||||
import sexpression.*;
|
import sexpression.*;
|
||||||
|
|
||||||
/**
|
|
||||||
* <code>QUOTE</code> represents the QUOTE form in Lisp.
|
|
||||||
*/
|
|
||||||
public class QUOTE extends LispFunction {
|
public class QUOTE extends LispFunction {
|
||||||
|
|
||||||
// The number of arguments that QUOTE takes.
|
private ArgumentValidator argumentValidator;
|
||||||
private static final int NUM_ARGS = 1;
|
|
||||||
|
|
||||||
public SExpression call(Cons argList) {
|
public QUOTE() {
|
||||||
// retrieve the number of arguments passed to QUOTE
|
this.argumentValidator = new ArgumentValidator("QUOTE");
|
||||||
int argListLength = LENGTH.getLength(argList);
|
this.argumentValidator.setExactNumberOfArguments(1);
|
||||||
|
}
|
||||||
// make sure we have received exactly one argument
|
|
||||||
if (argListLength != NUM_ARGS) {
|
public SExpression call(Cons argumentList) {
|
||||||
Cons originalSExpr = new Cons(new Symbol("QUOTE"), argList);
|
argumentValidator.validate(argumentList);
|
||||||
String errMsg = "too " +
|
|
||||||
((argListLength > NUM_ARGS) ? "many" : "few") +
|
return argumentList.getCar();
|
||||||
" arguments given to QUOTE: " + originalSExpr;
|
|
||||||
|
|
||||||
throw new RuntimeException(errMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return argList.getCar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the arguments passed to this Lisp function should be
|
|
||||||
* evaluated.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* <code>false</code>
|
|
||||||
*/
|
|
||||||
public boolean evaluateArguments() {
|
public boolean evaluateArguments() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue