1 / 8

Is everyone signed up on piazza?

Is everyone signed up on piazza?. 10. High Level Languages. Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web). This Course. Jython in Java. Relation. Programming Language Concepts Substitution.

tameka
Download Presentation

Is everyone signed up on piazza?

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. Is everyone signed up on piazza?

  2. 10 High Level Languages Java (Object Oriented) ASP RDF (Horn Clause Deduction, Semantic Web) This Course Jython in Java Relation

  3. Programming Language Concepts Substitution Definition 8 (Substitution, take 4) To substitute identifier i in e with expression v, replace all non-binding identifiers in e having the name i with the expression v, except within nested scopes of i. Finally, we have a version of substitution that works. A different, more succint way of phrasing this definition is Definition 9 (Substitution, take 5) To substitute identifier i in e with expression v, replace all free instances of i in e with v.

  4. Develop Substitution for the Following Expressions Start with schema from Chapter 2 Get the following expressions to work: (subst (id 'x) 'x (id 'y)) (subst (num 2) 'x (num 1)) (subst (id 'x) 'x (num 1)) (subst (id 'y) 'x (num 1)) (subst (add (id 'x) (id 'x)) 'x (num 1)) (subst (with 'y (num 2) (id 'x)) 'x (num 1)) (subst (with 'y (num 2) (add (id 'x) (id 'y))) 'x (num 1)) (subst (with 'y (id 'x) (add (id 'x) (id 'y))) 'x (num 1)) (subst (with 'x (id 'x) (id 'x)) 'x (num 1)) (calc (subst (with 'y (add (num 2) (id 'x)) (add (id 'y)(id 'x))) 'x (num 1)))

  5. Scheme for Textbook Chapter 3 #langplai (define-type WAE [num (n number?)] [add (lhs WAE?) (rhs WAE?)] [sub (lhs WAE?) (rhs WAE?)] [with (name symbol?) (named-expr WAE?) (body WAE?)] [id (name symbol?)]) ;; subst : WAE symbol WAE!WAE (define (substexpr sub-idval) (type-case WAE expr [num (n) expr] [add (l r) (add (subst l sub-idval) (substr sub-idval))] [sub (l r) (sub (subst l sub-idval) (substr sub-idval))] [with (bound-id named-expr bound-body) (if (symbol=? bound-id sub-id) (with bound-id (substnamed-expr sub-idval) bound-body) (with bound-id (substnamed-expr sub-idval) (substbound-body sub-idval)))] [id (v) (if (symbol=? v sub-id) val expr)])) ;; calc : WAE!number (define (calcexpr) (type-case WAE expr [num (n) n] [add (l r) (+ (calc l) (calc r))] [sub (l r) (- (calc l) (calc r))] [with (bound-id named-expr bound-body) (calc (substbound-body bound-id (num (calc named-expr))))] [id (v) (error 'calc "free identifier")]))

  6. Programming Language Concepts • Chapters 1 and 2 • Concepts: • Concrete Sytax • Abstract Syntax • Token (Terminal) • Non-Terminal • BNF • s-expression • Parse • Interpret (calc) • Chapter 3 • Concepts: • Identifier • Substitution • Binding Instance • Bound Identifier • Free Instance (Free Identifier) • Scope • Eager Evaluation • Lazy Evaluation

  7. Programming Language Concepts Eager and Lazy Evaluation We began this material motivating the introduction of with: as a means for eliminating redundancy. Let’s revisit this sequence of substitutions (skipping a few intermediate steps): {with {x {+ 5 5}} {with {y {- x 3}} {+ y y}}} = {with {x 10} {with {y {- x 3}} {+ y y}}} = {with {y {- 10 3}} {+ y y}} = {with {y 7} {+ y y}} = {+ 7 7} = 14 Couldn’t we have also written it this way? {with {x {+ 5 5}} {with {y {- x 3}} {+ y y}}} = {with {y {- {+ 5 5} 3}} {+ y y}} = {+ {- {+ 5 5} 3} {- {+ 5 5} 3}} = {+ {- 10 3} {- {+ 5 5} 3}} = {+ {- 10 3} {- 10 3}} = {+ 7 {- 10 3}} = {+ 7 7} = 14 In the top example, we invoke calc before substitution (because the result of calc is what we supply as an argument to subst). This model of substitution is called eager: we “eagerly” reduce the named expression to a value before substituting it. This is in contrast to the second example of reductions above, which we call lazy, wherein we reduce the named expression to a value only when we need to (such as at the application of an arithmetic primitive).

More Related