120 likes | 228 Views
JDB-Lisp Version 2.0. Carine Iskander Pia Chakrabarti. Additional Functionality Implemented. Cadr – gets the second element by getting the car of the cdr Equals – checks to see whether sexp in a list are equal List? – checks to see if it is a list Num? – checks to see if it is a num
E N D
JDB-Lisp Version 2.0 CarineIskander PiaChakrabarti
Additional Functionality Implemented • Cadr – gets the second element by getting the car of the cdr • Equals – checks to see whether sexp in a list are equal • List? – checks to see if it is a list • Num? – checks to see if it is a num • Atomic? – checks to see if it is atomic • Last – returns last element of a list • *Demonstration*
Major Scoping Problem • (let ((z 17)) (let ((z 3) (a 5) (x (lambda (x y) (- x (+ y z))))) (let ((z 19) (a 5)) (funcall x z a)))) Static Scoping (break down by JDB himself): 1. Start with (FUNCALL X Z A) 2. Resolve X to get: ((LAMBDA (X Y) (- X (+ Y Z))) Z A) 3. Resolve Z and A in the calling scope, Scope 3 in this case. So far we have: ((LAMBDA (X Y) (- X (+ Y Z))) 19 5) 4. Apply the parameters: (- 19 (+ 5 Z)) 5. Calculate -3
Major Scoping Problem cont. Looks like dynamic scoping but it’s not! “ FunctionEntry.call() makes an assumption, that the SymbolTable passed to call() represents the calling context of the function. But the Lambda class breaks this assumption. It interjects a new symbol table based on the union of the calling context and the closure context.”
Major Scoping Problem Fixed by JDB Seq evaledArguments; ArrayList<SExp> temp = new ArrayList<SExp>(); for (;arguments != null; arguments = arguments.cdr) temp.add(arguments.car.eval(symbolTable)); evaledArguments = new Seq(temp.toArray(new SExp[]{})); return super.call(new ClosureSymbolTable(symbolTable, closure), evaledArguments); He resolves the arguments in the symbol tables in the proper scope before passing them on.
But there are still problems… This is wrong because there should be an error when using static scoping!
How We Fixed It • We created 2 tables: - symbol table - closure table • If the closure table is empty, throw an exception • Else look in the closure table first, then look in the symbol table for the rest • *Demonstration of something that should work* • *Demonstration of something that shouldn’t work*
We Also Added Dynamic Scoping • What is dynamic scoping? • We give it the most recent symbol table • *Demonstration*
Division Problem • 1/9 = .1111111111111111111111111111…
Division Problem cont. • JDB’s division algorithm: computes 1/9 if no more arguments return 1/9 else continue computation • Program errors out on first step so it never gets to compute 9/3
How We Fixed It • We restructured the algorithm so that it did not by default do 1/n first. However, when we explicitly wanted it to compute something like 1/9, it would still error out. • To fix that problem we used a BigDecimal division method that rounds as it goes – which took some time to find • *Demonstration*
What’s Left • We hoped to make static scoping and dynamic scoping both possible in one program • We attempted writing a letd method • Due to the structure of the program, it is impossible as of right now because every function call is a new instance of SpecialFormsEntry class so a flag cannot be stored and accessed properly