jdb-lisp version 2.0

12
JDB-Lisp Version 2.0 JDB-Lisp Version 2.0 Carine Iskander Pia Chakrabarti

Upload: zanthe

Post on 12-Jan-2016

39 views

Category:

Documents


0 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: JDB-Lisp Version 2.0

JDB-Lisp Version 2.0JDB-Lisp Version 2.0Carine IskanderPia Chakrabarti

Page 2: JDB-Lisp Version 2.0

Additional Functionality Additional Functionality ImplementedImplementedCadr – 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 listNum? – checks to see if it is a numAtomic? – checks to see if it is atomicLast – returns last element of a list*Demonstration*

Page 3: JDB-Lisp Version 2.0

Major Scoping ProblemMajor 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

Page 4: JDB-Lisp Version 2.0

Major Scoping Problem cont.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.”

Page 5: JDB-Lisp Version 2.0

Major Scoping Problem Fixed Major Scoping Problem Fixed by JDBby 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.

Page 6: JDB-Lisp Version 2.0

But there are still But there are still problems…problems…

This is wrong because there should be an error when using static scoping!

Page 7: JDB-Lisp Version 2.0

How We Fixed ItHow We Fixed ItWe 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*

Page 8: JDB-Lisp Version 2.0

We Also Added Dynamic We Also Added Dynamic ScopingScoping

What is dynamic scoping?

We give it the most recent symbol table

*Demonstration*

Page 9: JDB-Lisp Version 2.0

Division ProblemDivision Problem

1/9 = .1111111111111111111111111111…

Page 10: JDB-Lisp Version 2.0

Division Problem cont.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

Page 11: JDB-Lisp Version 2.0

How We Fixed ItHow We Fixed ItWe 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*

Page 12: JDB-Lisp Version 2.0

What’s LeftWhat’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