Logical functions and - Logical AND function. Example: (and (> 5 4) (< 5 4)) or - Logical OR function. Example: (and (> 5 4) (< 5 4)) not - Logical negation.

Slides:



Advertisements
Similar presentations
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Advertisements

Defining functions in lisp In lisp, all programming is in terms of functions A function is something which –takes some arguments as input –does some computing.
Commands and predicates LISP functions are divided into 2 classes. Predicates are functions that return boolean values i.e. t or nil. The rest are commands.
PZ07B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07B - Basic statements Programming Language Design.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
Returning values from functions You can return a value from a function by using the built- in function : ( return-from Function_name value) For example:
ECE122 L7: Conditional Statements February 20, 2007 ECE 122 Engineering Problem Solving with Java Lecture 7 Conditional Statements.
Symbolic Expressions (S Expressions) Syntax: Opening and Closing parenthesis having elements in between. List represented in LISP: (A B2 C3 Shahid) (A.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
C++ for Engineers and Scientists Third Edition
Boolean Expressions and If Flow of Control / Conditional Statements The if Statement Logical Operators The else Clause Block statements Nested if statements.
COMP 205 – Week 11 Dr. Chunbo Chu. Intro Lisp stands for “LISt Process” Invented by John McCarthy (1958) Simple data structure (atoms and lists) Heavy.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
Conditionals and Recursion "To iterate is human, to recurse divine." - L. Peter Deutsch.
1 Statement-Level Control Structures Levels of flow control Control Statements 1. Sequence 2. Selection 3. Iteration Unconditional branching Guarded commands.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
CSE 341, S. Tanimoto Lisp Defining Functions with DEFUN Functions are the primary abstraction mechanism available in Lisp. (Others are structures.
Programming in Java (COP 2250) Lecture 11 Chengyong Yang Fall, 2005.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
5-1 Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional statements,
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
Basic LISP Programming Common LISP follows the algorithm below when interacting with users: loop read in an expression from the console; evaluate the expression;
INTRODUCTION SELECTION STATEMENTS -Control Expression -Single/Compound Clauses -Dangling Else MUTLIPLE SELECTION CONSTRUCTS -C/Java Switch -C# Switch -Ada.
CSE S. Tanimoto Lisp Defining Macros in Lisp Extensibility: A language is extensible if the language can be extended. New Lisp control structures.
Introduction to LISP. Lisp Extensible: It lets you define new operators yourself Lisp programs are expressed as lisp data structures –You can write programs.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Review if imag(x) > 0 fprintf('Sorry, but I don''t understand complex numbers.\n'); return end if x < 10 % leave this out, type the next line first, and.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
The If Statement There are no switch statements in Python. You need to use just if statements. There are no switch statements in Python. You need to use.
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
Comparative Programming Languages Functional programming with Lisp/Scheme.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester,
PHP-language, conditional statements
Sequence, Selection, Iteration The IF Statement
Modern Programming Languages Lecture 20 Fakhar Lodhi
Operator Precedence Operators Precedence Parentheses () unary
Boolean Expressions and If
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
PZ10CX - LISP Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section Appendix A.6.
IF if (condition) { Process… }
Functional Languages Early in AI research, there was a need for symbolic computing handling symbols instead of numbers or strings parsing input recursion.
Lisp Tutorial Click on Xlisp icon – you enter the interpreter
Liquid Common Lisp On Suns.
Professor Jodi Neely-Ritz CGS3460
Visual Basic – Decision Statements
Summary Two basic concepts: variables and assignments Basic types:
Relational, Logical, and Equality Operators
Defining Macros in Lisp
A LESSON IN LOOPING What is a loop?
Program Flow.
Defining Functions with DEFUN
Abstraction and Repetition
DeMorgan's & related Laws
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
There many situations comes in real life when we need to make some decisions and based on these decisions, we decide what should we do next. Similar situations.
Comparing Data & the ‘switch’ Statement
Comparing Data & the ‘switch’ Statement
CprE 185: Intro to Problem Solving (using C)
CPS120: Introduction to Computer Science
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
PZ07B - Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Logical functions and - Logical AND function. Example: (and (> 5 4) (< 5 4)) or - Logical OR function. Example: (and (> 5 4) (< 5 4)) not - Logical negation. Example: (not (> 5 4))

Conditionals - when, unless (when condition statements) (when t (print “true”)) (when nil (print “true”)) (unless condition statements) (unless t (print “true”)) (unless nil (print “true”))

Conditionals - cond COND - This is similar to the familiar switch construct that you have encountered. Here is the syntax: (cond (cond1 command1) (cond1 command2) ……… )

Conditionals - cond Example of COND in use: (setq a 3) (cond ((evenp a) a) ;if a is even, return a ((> a 7) (/ a 2)) ((< a 5) (+ a 1)) (t 1000) )

Conditionals - case The LISP case statement is similar to that of C’s. For example: (setq greeting ‘n) (case greeting (m “Good morning”) (e “Good evening”) (n “Good nite”) )

Program block - progn Sometimes we may need to use more than one statement within the then and/or the else clause of an if statement. To achieve this, use the progn construct. For example: (if (> a 5) (progn (setq a (+ b 7)) (setq b (+ c 8))) (setq b 4)) ; the else clause The then clause