1 / 12

JDB-Lisp Version 2.0

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

zanthe
Download Presentation

JDB-Lisp Version 2.0

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JDB-Lisp Version 2.0 CarineIskander PiaChakrabarti

  2. 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*

  3. 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

  4. 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.”

  5. 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.

  6. But there are still problems… This is wrong because there should be an error when using static scoping!

  7. 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*

  8. We Also Added Dynamic Scoping • What is dynamic scoping? • We give it the most recent symbol table • *Demonstration*

  9. Division Problem • 1/9 = .1111111111111111111111111111…

  10. 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

  11. 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*

  12. 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

More Related