From a8d8d6696c95d8cb6501baf6847464297695aff8 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Sun, 19 Nov 2017 11:17:32 -0500 Subject: [PATCH] LENGTH no longer creates a new instance --- src/function/builtin/cons/LENGTH.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/function/builtin/cons/LENGTH.java b/src/function/builtin/cons/LENGTH.java index ca1270e..2acade0 100644 --- a/src/function/builtin/cons/LENGTH.java +++ b/src/function/builtin/cons/LENGTH.java @@ -3,6 +3,7 @@ package function.builtin.cons; import static function.builtin.cons.LIST.makeList; import static recursion.TailCalls.done; import static recursion.TailCalls.tailCall; +import static table.FunctionTable.lookupFunction; import java.math.BigInteger; @@ -17,12 +18,15 @@ import sexpression.LispNumber; public class LENGTH extends LispFunction { public static BigInteger getLength(Cons list) { - LENGTH lengthFunction = new LENGTH("LENGTH"); - LispNumber length = lengthFunction.callWithoutArgumentValidation(makeList(list)); + LispNumber length = lookupLength().callWithoutArgumentValidation(makeList(list)); return length.getValue(); } + private static LENGTH lookupLength() { + return (LENGTH) lookupFunction("LENGTH"); + } + private ArgumentValidator argumentValidator; public LENGTH(String name) {