Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

An obvious way to extend our arthmetic expressions is by also allowing the declaration of variables with immediately assigning a value computed by an expression.

image text in transcribed

An obvious way to extend our arthmetic expressions is by also allowing the declaration of variables with immediately assigning a value computed by an expression. This type of expression is commonly referred to as Let-expression. So we have additionally Syntax: A Let-expression is a tuple let (X 2) where is an atom giving the variable name and Y and 2 are expressions. Semantics: The first expression inside a let-expression defines the alue to be assigned to the variable introduced in the let-expression. The second expression can refer to the variable introduced. In some sense, a let expression i similar with a lac statement excep he aet tha he or mer returns he value o ar express on an eas e ia er s a statement ust does some computa ons Example (Eval ltlt (int (2) int (4)) a (ar(x) int (2)en should return 11. The va able x will be bound to the value o the express on malt int 2) 1nt 4 w ich is evaluated o 8 After that he second express on add ar/x) int 3) is evaluated to a +3, and its result 11 is returned Hints: One needs environment adjunction as well here which is implemented by record adjunction. The Mozart system provides a specific function for adding features and values to the records, namely Ad o1nAt R takes a record R a feature E and a new eld x and returns a record which has a e ture r with he value x n addition to all eatures and eds ron R except Examples: (of using AdjoinAt) Adjoinat a (x:1 y:2) z 7} returns a (x: 1 y:2 z:7> OZ Programming Language djoinat a(: y2) x 7 returns a (x:7 y:2) An obvious way to extend our arthmetic expressions is by also allowing the declaration of variables with immediately assigning a value computed by an expression. This type of expression is commonly referred to as Let-expression. So we have additionally Syntax: A Let-expression is a tuple let (X 2) where is an atom giving the variable name and Y and 2 are expressions. Semantics: The first expression inside a let-expression defines the alue to be assigned to the variable introduced in the let-expression. The second expression can refer to the variable introduced. In some sense, a let expression i similar with a lac statement excep he aet tha he or mer returns he value o ar express on an eas e ia er s a statement ust does some computa ons Example (Eval ltlt (int (2) int (4)) a (ar(x) int (2)en should return 11. The va able x will be bound to the value o the express on malt int 2) 1nt 4 w ich is evaluated o 8 After that he second express on add ar/x) int 3) is evaluated to a +3, and its result 11 is returned Hints: One needs environment adjunction as well here which is implemented by record adjunction. The Mozart system provides a specific function for adding features and values to the records, namely Ad o1nAt R takes a record R a feature E and a new eld x and returns a record which has a e ture r with he value x n addition to all eatures and eds ron R except Examples: (of using AdjoinAt) Adjoinat a (x:1 y:2) z 7} returns a (x: 1 y:2 z:7> OZ Programming Language djoinat a(: y2) x 7 returns a (x:7 y:2)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions