SlideShare a Scribd company logo
1 of 7
3.4 Expressions
A Scheme program is composed of expressions and definitions (we cover
definitions in Section 3.5). An expression is a syntactic element that has a value.
The act of determining the value associated with an expression is calledevaluation.
A Scheme interpreter, such as the one provided in DrRacket, is a machine for evaluating
Scheme expressions.
If you enter an expression into a Scheme interpreter, the interpreter evaluates the
expression and displays its value.
Expressions may be primitives. Scheme also provides means of combination
for producing complex expressions from simple expressions.
The next subsections describe primitive expressions and application
proceduresexpressions.Section 3.6 describes expressions for making
and Section 3.7 describes expressions that can be used to make decisions.
β€’ 3.4.1 Primitives
β€’ 3.4.2 Application expressions
3.4.1 Primitives
An expression can be replaced with a primitive:
Expression ::β‡’β‡’ PrimitiveExpression
As with natural languages, primitives are the smallest units of meaning. Hence,
the value of a primitive is its pre-defined meaning.
Scheme provides many different primitives. Three useful types of primitives
are described next: numbers, Booleans, and primitive procedures.
Numbers. Numbers represent numerical values. Scheme provides all the kinds of
numbers you are familiar with including whole numbers, negative numbers, decimals,
and rational numbers.
Example numbers include:
expression 1120 is 1120.
Booleans. Booleans represent truth values. There are two primitives for representing
true and false:
PrimitiveExpression ::β‡’β‡’ true | false
150 0 -12
3.14159 3/4 999999999999999999999
Numbers evaluate to their value. For example, the value of the primitive
The meaning of |true| is true, and the meaning of |false| is false. In the
DrRacket interpreter, #t and #f are used to represent the primitive truth values.
So, the value
|true| appears as #t in the interactions window.
Table 3.1: Selected Scheme Primitive Procedures.
All of these primitive procedures operate on numbers. The first four are the basic
arithmetic operators; the rest are comparison procedures.
Some of these procedures are defined for more inputs than just the ones shown
here (e.g., the subtract procedure also works on one number, producing its negation).
Symbol Description Inputs Output
+ add
zero or more sum of the input numbers (0 if there
are
numbers no inputs)
* multiply
zero or more product of the input numbers (1 if there
numbers are no inputs)
- subtract two numbers
the value of the first number minus the
value the second number
/ divide two numbers
the value of the first number divided by
the value of the second number
zero? is zero? one number true if the input value is 0,
otherwise false
= is equal to? two numbers
true if the input values have the same
value, otherwise false
true if the first input value has lesser value
< is less than? two numbers than the second input
value,
otherwise false
true if the first input value has greater
> is greater than? two numbers value than the
second input value,
otherwise false
true if the first input value is not greater
< = is less than or
two numbers than the
second input value, equal to?
otherwise false
> =
is greater than or two numbers
true if the first input value is not less than
equal to? the second input value, otherwise false
Primitive Procedures. Scheme provides primitive procedures corresponding to many
common functions. Mathematically, a function is a mapping from inputs to outputs.
For each valid input to the function, there is exactly one associated output. For
example, + is a procedure that takes zero or more inputs, each of which must be
a number. Its output is the sum of the values of the inputs.
Table 3.1 describes some primitive procedures for performing arithmetic
and comparisons on numbers.
3.4.2 Application expressions
Most of the actual work done by a Scheme program is done by application
expressions that apply procedures to operands.
The expression (+ 1 2) is anApplicationExpression, consisting of three
subexpressions. Although this example is probably simple enough that you can
probably guess that it evaluates to 3, we will show in detail how it is evaluated by
breaking down into its subexpressions using the grammar rules.
The same process will allow us to understand how any expression is evaluated.
The grammar rule for application is:
Expression
:: β‡’β‡’
ApplicationExpression
ApplicationExpression
:: β‡’β‡’
(Expression MoreExpressions)
MoreExpressions
:: β‡’β‡’
ΡΡ | Expression MoreExpressions
This rule produces a list of one or more expressions surrounded by parentheses.
The value of the first expression should be a procedure; the remaining expressions are
the inputs to the procedure known as operands. Another name for operands is
arguments. Here is a parse tree for the expression (+ 1 2):
Following the grammar rules, we replace Expression with ApplicationExpressionat the
top of the parse tree.
Then, we replace ApplicationExpression with(Expression MoreExpressions).
The Expression term is replacedPrimitiveExpression, and finally, the primitive addition
procedure +. This is the first subexpression of the application, so it is the procedure to
be applied. TheMoreExpressions term produces the two operand expressions: 1 and
2, both of which are primitives that evaluate to their own values.
The application expression is evaluated by applying the value of the first expression (the
primitive procedure +) to the inputs given by the values of the other expressions.
Following the meaning of the primitive procedure, (+ 1 2) evaluates to 3 as expected.
The Expression nonterminals in the application expression can be replaced
with anything that appears on the right side of an expression rule,
including anApplicationExpression.
We can build up complex expressions like (+ (* 10 10) (+ 25 25)). Its parse tree
is:
This tree is similar to the previous tree, except instead of the subexpressions of the first
application expression being simple primitive expressions, they are now
application expressions.
To evaluate the output application, we need to evaluate all the subexpressions. The first
subexpression, +, evaluates to the primitive procedure. The second subexpression, (* 10
10), evaluates to 100, and the third expression, (+ 25 25), evaluates to 50.
Now, we can evaluate the original expression using the values for its three component
subexpressions: (+ 100 50) evaluates to 150.
The Expression nonterminals in the application expression can be replaced
with anything that appears on the right side of an expression rule,
including anApplicationExpression.
We can build up complex expressions like (+ (* 10 10) (+ 25 25)). Its parse tree
is:
This tree is similar to the previous tree, except instead of the subexpressions of the first
application expression being simple primitive expressions, they are now
application expressions.
To evaluate the output application, we need to evaluate all the subexpressions. The first
subexpression, +, evaluates to the primitive procedure. The second subexpression, (* 10
10), evaluates to 100, and the third expression, (+ 25 25), evaluates to 50.
Now, we can evaluate the original expression using the values for its three component
subexpressions: (+ 100 50) evaluates to 150.

More Related Content

What's hot (19)

Function
FunctionFunction
Function
Β 
Operator precedence and associativity
Operator precedence and associativityOperator precedence and associativity
Operator precedence and associativity
Β 
Basic python part 1
Basic python part 1Basic python part 1
Basic python part 1
Β 
Programming with matlab session 4
Programming with matlab session 4Programming with matlab session 4
Programming with matlab session 4
Β 
Ch03
Ch03Ch03
Ch03
Β 
Ch08
Ch08Ch08
Ch08
Β 
How to Remove First 4 Characters in Excel
How to Remove First 4 Characters in ExcelHow to Remove First 4 Characters in Excel
How to Remove First 4 Characters in Excel
Β 
Ch05
Ch05Ch05
Ch05
Β 
Chapter 3.3
Chapter 3.3Chapter 3.3
Chapter 3.3
Β 
0.1 bzca5e
0.1 bzca5e0.1 bzca5e
0.1 bzca5e
Β 
04 a ch03_programacion
04 a ch03_programacion04 a ch03_programacion
04 a ch03_programacion
Β 
Ch09
Ch09Ch09
Ch09
Β 
Arrays in c++
Arrays in c++Arrays in c++
Arrays in c++
Β 
Lar calc10 ch05_sec1
Lar calc10 ch05_sec1Lar calc10 ch05_sec1
Lar calc10 ch05_sec1
Β 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5
Β 
[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++[ITP - Lecture 04] Variables and Constants in C/C++
[ITP - Lecture 04] Variables and Constants in C/C++
Β 
How to use vlookup in MS Excel
How to use vlookup in MS ExcelHow to use vlookup in MS Excel
How to use vlookup in MS Excel
Β 
MS Excel Function
MS Excel FunctionMS Excel Function
MS Excel Function
Β 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
Β 

Viewers also liked

Regular expressions h1
Regular expressions h1Regular expressions h1
Regular expressions h1Rajendran
Β 
modeling computing
modeling computingmodeling computing
modeling computingRajendran
Β 
mutable pairs_and_lists
mutable pairs_and_listsmutable pairs_and_lists
mutable pairs_and_listsRajendran
Β 
developing complex_programs
developing complex_programsdeveloping complex_programs
developing complex_programsRajendran
Β 
decisions
decisionsdecisions
decisionsRajendran
Β 
inheritance
inheritanceinheritance
inheritanceRajendran
Β 
histry of_computing_machines
histry of_computing_machineshistry of_computing_machines
histry of_computing_machinesRajendran
Β 
processes
processesprocesses
processesRajendran
Β 
1.3 applications, issues
1.3 applications, issues1.3 applications, issues
1.3 applications, issuesRajendran
Β 
recursive transition_networks
recursive transition_networksrecursive transition_networks
recursive transition_networksRajendran
Β 
languages
languageslanguages
languagesRajendran
Β 
measuring computing_power
measuring computing_powermeasuring computing_power
measuring computing_powerRajendran
Β 
Binary trees
Binary treesBinary trees
Binary treesRajendran
Β 
Quicksort
QuicksortQuicksort
QuicksortRajendran
Β 
Normal forms cfg
Normal forms   cfgNormal forms   cfg
Normal forms cfgRajendran
Β 
TM - Techniques
TM - TechniquesTM - Techniques
TM - TechniquesRajendran
Β 
Pumping lemma for regular set h1
Pumping lemma for regular set h1Pumping lemma for regular set h1
Pumping lemma for regular set h1Rajendran
Β 
Basics of data structure
Basics of data structureBasics of data structure
Basics of data structureRajendran
Β 

Viewers also liked (19)

Regular expressions h1
Regular expressions h1Regular expressions h1
Regular expressions h1
Β 
modeling computing
modeling computingmodeling computing
modeling computing
Β 
mutable pairs_and_lists
mutable pairs_and_listsmutable pairs_and_lists
mutable pairs_and_lists
Β 
developing complex_programs
developing complex_programsdeveloping complex_programs
developing complex_programs
Β 
decisions
decisionsdecisions
decisions
Β 
inheritance
inheritanceinheritance
inheritance
Β 
histry of_computing_machines
histry of_computing_machineshistry of_computing_machines
histry of_computing_machines
Β 
processes
processesprocesses
processes
Β 
1.3 applications, issues
1.3 applications, issues1.3 applications, issues
1.3 applications, issues
Β 
recursive transition_networks
recursive transition_networksrecursive transition_networks
recursive transition_networks
Β 
languages
languageslanguages
languages
Β 
parser
parserparser
parser
Β 
measuring computing_power
measuring computing_powermeasuring computing_power
measuring computing_power
Β 
Binary trees
Binary treesBinary trees
Binary trees
Β 
Quicksort
QuicksortQuicksort
Quicksort
Β 
Normal forms cfg
Normal forms   cfgNormal forms   cfg
Normal forms cfg
Β 
TM - Techniques
TM - TechniquesTM - Techniques
TM - Techniques
Β 
Pumping lemma for regular set h1
Pumping lemma for regular set h1Pumping lemma for regular set h1
Pumping lemma for regular set h1
Β 
Basics of data structure
Basics of data structureBasics of data structure
Basics of data structure
Β 

Similar to expressions

This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxabhi353063
Β 
3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.pptAllanGuevarra1
Β 
3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.pptJosephIThomas
Β 
C program
C programC program
C programAJAL A J
Β 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdfpaijitk
Β 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptxAnisZahirahAzman
Β 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.pptsnowflakebatch
Β 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++bajiajugal
Β 
Data Transformation
Data TransformationData Transformation
Data TransformationArmanArafatAnik
Β 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.pptjaba kumar
Β 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperatorteach4uin
Β 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III TermAndrew Raj
Β 
What is algorithm
What is algorithmWhat is algorithm
What is algorithmlilyMalar1
Β 
procedures
proceduresprocedures
proceduresRajendran
Β 
5th chapter Relational algebra.pptx
5th chapter Relational algebra.pptx5th chapter Relational algebra.pptx
5th chapter Relational algebra.pptxkavitha623544
Β 
Basics of c++
Basics of c++ Basics of c++
Basics of c++ Gunjan Mathur
Β 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxSahajShrimal1
Β 
As Level Computer Science Book -2
As Level Computer Science  Book -2As Level Computer Science  Book -2
As Level Computer Science Book -2DIGDARSHAN KUNWAR
Β 

Similar to expressions (20)

c programming2.pptx
c programming2.pptxc programming2.pptx
c programming2.pptx
Β 
This first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docxThis first assignment will focus on coding in Python, applying kno.docx
This first assignment will focus on coding in Python, applying kno.docx
Β 
3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt
Β 
3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt3 Formulas, Ranges, Functions.ppt
3 Formulas, Ranges, Functions.ppt
Β 
Python_Module_2.pdf
Python_Module_2.pdfPython_Module_2.pdf
Python_Module_2.pdf
Β 
C program
C programC program
C program
Β 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdf
Β 
component of c language.pptx
component of c language.pptxcomponent of c language.pptx
component of c language.pptx
Β 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
Β 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
Β 
Data Transformation
Data TransformationData Transformation
Data Transformation
Β 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
Β 
Cprogrammingoperator
CprogrammingoperatorCprogrammingoperator
Cprogrammingoperator
Β 
C programming | Class 8 | III Term
C programming  | Class 8  | III TermC programming  | Class 8  | III Term
C programming | Class 8 | III Term
Β 
What is algorithm
What is algorithmWhat is algorithm
What is algorithm
Β 
procedures
proceduresprocedures
procedures
Β 
5th chapter Relational algebra.pptx
5th chapter Relational algebra.pptx5th chapter Relational algebra.pptx
5th chapter Relational algebra.pptx
Β 
Basics of c++
Basics of c++ Basics of c++
Basics of c++
Β 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
Β 
As Level Computer Science Book -2
As Level Computer Science  Book -2As Level Computer Science  Book -2
As Level Computer Science Book -2
Β 

More from Rajendran

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower boundsRajendran
Β 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsRajendran
Β 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower boundsRajendran
Β 
Red black tree
Red black treeRed black tree
Red black treeRajendran
Β 
Hash table
Hash tableHash table
Hash tableRajendran
Β 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statisticsRajendran
Β 
Proof master theorem
Proof master theoremProof master theorem
Proof master theoremRajendran
Β 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree methodRajendran
Β 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theoremRajendran
Β 
Master method
Master method Master method
Master method Rajendran
Β 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
Β 
Hash tables
Hash tablesHash tables
Hash tablesRajendran
Β 
Lower bound
Lower boundLower bound
Lower boundRajendran
Β 
Master method theorem
Master method theoremMaster method theorem
Master method theoremRajendran
Β 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithmsRajendran
Β 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisRajendran
Β 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisRajendran
Β 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of QuicksortRajendran
Β 
Np completeness
Np completenessNp completeness
Np completenessRajendran
Β 
computer languages
computer languagescomputer languages
computer languagesRajendran
Β 

More from Rajendran (20)

Element distinctness lower bounds
Element distinctness lower boundsElement distinctness lower bounds
Element distinctness lower bounds
Β 
Scheduling with Startup and Holding Costs
Scheduling with Startup and Holding CostsScheduling with Startup and Holding Costs
Scheduling with Startup and Holding Costs
Β 
Divide and conquer surfing lower bounds
Divide and conquer  surfing lower boundsDivide and conquer  surfing lower bounds
Divide and conquer surfing lower bounds
Β 
Red black tree
Red black treeRed black tree
Red black tree
Β 
Hash table
Hash tableHash table
Hash table
Β 
Medians and order statistics
Medians and order statisticsMedians and order statistics
Medians and order statistics
Β 
Proof master theorem
Proof master theoremProof master theorem
Proof master theorem
Β 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Β 
Recurrence theorem
Recurrence theoremRecurrence theorem
Recurrence theorem
Β 
Master method
Master method Master method
Master method
Β 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Β 
Hash tables
Hash tablesHash tables
Hash tables
Β 
Lower bound
Lower boundLower bound
Lower bound
Β 
Master method theorem
Master method theoremMaster method theorem
Master method theorem
Β 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
Β 
Longest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm AnalysisLongest common subsequences in Algorithm Analysis
Longest common subsequences in Algorithm Analysis
Β 
Dynamic programming in Algorithm Analysis
Dynamic programming in Algorithm AnalysisDynamic programming in Algorithm Analysis
Dynamic programming in Algorithm Analysis
Β 
Average case Analysis of Quicksort
Average case Analysis of QuicksortAverage case Analysis of Quicksort
Average case Analysis of Quicksort
Β 
Np completeness
Np completenessNp completeness
Np completeness
Β 
computer languages
computer languagescomputer languages
computer languages
Β 

Recently uploaded

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
Β 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
Β 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
Β 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
Β 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
Β 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
Β 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
Β 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
Β 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
Β 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
Β 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
Β 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
Β 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
Β 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
Β 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
Β 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
Β 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
Β 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
Β 

Recently uploaded (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Β 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
Β 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
Β 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)β€”β€”β€”β€”IMP.OF KSHARA ...
Β 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
Β 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
Β 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
Β 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
Β 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Β 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
Β 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
Β 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Β 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
Β 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
Β 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
Β 
Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”
Model Call Girl in Tilak Nagar Delhi reach out to us at πŸ”9953056974πŸ”
Β 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
Β 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
Β 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
Β 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Β 

expressions

  • 1. 3.4 Expressions A Scheme program is composed of expressions and definitions (we cover definitions in Section 3.5). An expression is a syntactic element that has a value. The act of determining the value associated with an expression is calledevaluation. A Scheme interpreter, such as the one provided in DrRacket, is a machine for evaluating Scheme expressions. If you enter an expression into a Scheme interpreter, the interpreter evaluates the expression and displays its value. Expressions may be primitives. Scheme also provides means of combination for producing complex expressions from simple expressions. The next subsections describe primitive expressions and application proceduresexpressions.Section 3.6 describes expressions for making and Section 3.7 describes expressions that can be used to make decisions. β€’ 3.4.1 Primitives β€’ 3.4.2 Application expressions
  • 2. 3.4.1 Primitives An expression can be replaced with a primitive: Expression ::β‡’β‡’ PrimitiveExpression As with natural languages, primitives are the smallest units of meaning. Hence, the value of a primitive is its pre-defined meaning. Scheme provides many different primitives. Three useful types of primitives are described next: numbers, Booleans, and primitive procedures. Numbers. Numbers represent numerical values. Scheme provides all the kinds of numbers you are familiar with including whole numbers, negative numbers, decimals, and rational numbers. Example numbers include: expression 1120 is 1120. Booleans. Booleans represent truth values. There are two primitives for representing true and false: PrimitiveExpression ::β‡’β‡’ true | false 150 0 -12 3.14159 3/4 999999999999999999999 Numbers evaluate to their value. For example, the value of the primitive
  • 3. The meaning of |true| is true, and the meaning of |false| is false. In the DrRacket interpreter, #t and #f are used to represent the primitive truth values. So, the value |true| appears as #t in the interactions window. Table 3.1: Selected Scheme Primitive Procedures. All of these primitive procedures operate on numbers. The first four are the basic arithmetic operators; the rest are comparison procedures. Some of these procedures are defined for more inputs than just the ones shown here (e.g., the subtract procedure also works on one number, producing its negation). Symbol Description Inputs Output + add zero or more sum of the input numbers (0 if there are numbers no inputs) * multiply zero or more product of the input numbers (1 if there numbers are no inputs) - subtract two numbers the value of the first number minus the value the second number / divide two numbers the value of the first number divided by the value of the second number zero? is zero? one number true if the input value is 0, otherwise false = is equal to? two numbers true if the input values have the same value, otherwise false true if the first input value has lesser value < is less than? two numbers than the second input value, otherwise false true if the first input value has greater > is greater than? two numbers value than the second input value, otherwise false true if the first input value is not greater < = is less than or two numbers than the second input value, equal to? otherwise false > = is greater than or two numbers true if the first input value is not less than equal to? the second input value, otherwise false
  • 4. Primitive Procedures. Scheme provides primitive procedures corresponding to many common functions. Mathematically, a function is a mapping from inputs to outputs. For each valid input to the function, there is exactly one associated output. For example, + is a procedure that takes zero or more inputs, each of which must be a number. Its output is the sum of the values of the inputs. Table 3.1 describes some primitive procedures for performing arithmetic and comparisons on numbers. 3.4.2 Application expressions Most of the actual work done by a Scheme program is done by application expressions that apply procedures to operands. The expression (+ 1 2) is anApplicationExpression, consisting of three subexpressions. Although this example is probably simple enough that you can probably guess that it evaluates to 3, we will show in detail how it is evaluated by breaking down into its subexpressions using the grammar rules. The same process will allow us to understand how any expression is evaluated. The grammar rule for application is: Expression :: β‡’β‡’ ApplicationExpression ApplicationExpression :: β‡’β‡’ (Expression MoreExpressions) MoreExpressions :: β‡’β‡’ ΡΡ | Expression MoreExpressions
  • 5. This rule produces a list of one or more expressions surrounded by parentheses. The value of the first expression should be a procedure; the remaining expressions are the inputs to the procedure known as operands. Another name for operands is arguments. Here is a parse tree for the expression (+ 1 2): Following the grammar rules, we replace Expression with ApplicationExpressionat the top of the parse tree. Then, we replace ApplicationExpression with(Expression MoreExpressions). The Expression term is replacedPrimitiveExpression, and finally, the primitive addition procedure +. This is the first subexpression of the application, so it is the procedure to be applied. TheMoreExpressions term produces the two operand expressions: 1 and 2, both of which are primitives that evaluate to their own values. The application expression is evaluated by applying the value of the first expression (the primitive procedure +) to the inputs given by the values of the other expressions. Following the meaning of the primitive procedure, (+ 1 2) evaluates to 3 as expected.
  • 6. The Expression nonterminals in the application expression can be replaced with anything that appears on the right side of an expression rule, including anApplicationExpression. We can build up complex expressions like (+ (* 10 10) (+ 25 25)). Its parse tree is: This tree is similar to the previous tree, except instead of the subexpressions of the first application expression being simple primitive expressions, they are now application expressions. To evaluate the output application, we need to evaluate all the subexpressions. The first subexpression, +, evaluates to the primitive procedure. The second subexpression, (* 10 10), evaluates to 100, and the third expression, (+ 25 25), evaluates to 50. Now, we can evaluate the original expression using the values for its three component subexpressions: (+ 100 50) evaluates to 150.
  • 7. The Expression nonterminals in the application expression can be replaced with anything that appears on the right side of an expression rule, including anApplicationExpression. We can build up complex expressions like (+ (* 10 10) (+ 25 25)). Its parse tree is: This tree is similar to the previous tree, except instead of the subexpressions of the first application expression being simple primitive expressions, they are now application expressions. To evaluate the output application, we need to evaluate all the subexpressions. The first subexpression, +, evaluates to the primitive procedure. The second subexpression, (* 10 10), evaluates to 100, and the third expression, (+ 25 25), evaluates to 50. Now, we can evaluate the original expression using the values for its three component subexpressions: (+ 100 50) evaluates to 150.