SlideShare a Scribd company logo
Control structures in Lisp
Common Lisp provides with  a variety of special structures for organizing the programs.Some have to do with the flow of control. These are called as control structures.Locally defined functions(flet, labels) and macros( macrolet) are quite flexible.CL provides: simple one-way conditionals (when and unless.)
the simple two-way conditionals (if)
more general multi-way conditionals( cond, case)Constructs for performing non local exits with various scoping disciplines are provided: block, return, return-from, catch and throw.
overviewConstants and variablesReferencesAssignmentGeneralized variablesFunction invocationSimple sequencingConditionalsBlocks and ExitsIterations Mapping
Constants and variablesCL provides two kinds of variables: ordinary variables and function names. One of them is used to name defined function, macros, and special forms , and the other to name data objects. The name of the ordinary variable may be obtained by simply writing the name of the variable as a form to be executed.The following functions and variables allow reference to the values of constants and variables:quote object simply returns the objectfunction fn if fn is a symbol, the functional definition associated with that symbol is returned. If fn is a lambda-expression, then a “lexical closure” is returned.
ReferencesSymbol-value symbol returns the dynamic current value of the symbol, error occurs if the symbol has no values.Symbol-function-symbol returns the current global function definition named by the symbol, error is signaled if the symbol has no function definition.Symbol-function is applicable only for global functions its not applicable for lexical function name produced by flet or labels.
Symbol-function can be called on any function on which fbound function is true.fbound in turn returns true for symbols which define a macro or a special form.When symbol-function is used with typef, its new value must be type function.fdefinition function-name returns the current global function definition named by the argument function name.
boundp symbol returns true if the symbol  has a value, else returns false.fboundp symbol returns true if the function has global function definitionSpecial-form-p symbol returns a non-nil value if the symbol globally names a special form, else returns nil
AssignmentThe following allow the value associated with the current binding of the variable to be changed.(setq var1 form1 var2 form2 ….) here first the form1 is calculated and the value is stored in val1, then form2 is calculated and stored in form2 and so on..Setq returns the last value assigned, there must be even number of arguments forms.Ex: (setq  x (* 3 2) y (cons x nil))retains the first set value of x as 6 and returns 6.Psetq {form}* is similar to setq except that assignments happen in parallel.Ex: (setq a 4)       (setq b 6)        (psetq a b b a) a=6 and b=4, thus the values of a and b are exchanged  by using parallel assignment
Set symbol value1   allows the alteration of the dynamic variable , set allows the symbol to take value1 as its value.Ex: (set (if (eq a b) ‘c ‘d) ‘foo) sets either c to foo or d to foo depending on the outcome of the result, set returns the value as a result.makeunbound symbol causes the dynamic(special) variable named by symbol to become unbound.fmakeunbound symbol makes the analogous thing for the global function definition named by symbol.
Generalized variablesThe concept of the variables named by symbols can be generalized to any storage location that can remember one piece of data.Ex of such storage locations are the car and cdr of cons.Basic operations on variables are: access and update operations.The following table give the various access and update functions:
Setf is a macro that that examines an access form and produces a call to corresponding update function.Setf {place new-value}* takes a form place that when evaluated accesses a data object in some location and “inverts” it to produce a corresponding form to update the location.If more than one place-newvalue pair is specified, the pairs are processed sequentially; that is(setf place1 newvalue1,             place2 newvalue2,            ……             placen newvaluen)
Rotatef{place}* each place form may be any form acceptable as a generalized variable to setf.In the form (rotatef place1,place2,...placen) the values of place1 to placen are being accessed and saved.It is as if all the places from an end-round shift register that is rotated one place to the left, with the value of place1 being shifted around to the end to placen. (setf place1 value1 place2 value2…) the subforms of place1 and value1 are evaluated, the location specified by place1 is modified to contain the value returned by value1, and then the rest of setf form is processed in a like manner.
Function invocationAny list that has no other interpretation to as a macro call or special form is taken to be a function call.This applies function to a list of arguments.The arguments of the function consists of the last arguments to apply appended to the end of the list of all the other arguments to apply but the function itself.Ex:  (setf  a ‘*)  (apply a ‘( 3 2))6If the function takes keyword arguments , the keywords as well as the corresponding values must appear in the argument list.Ex: (apply # ‘(lamda (&key a b) (list a b)) ‘(:b 3))(nil 3)apply function arg &rest more-args
(funcall fn a1,a2,a3……an) applies the function fn to arguments a1,a2,….anEx: (cons 2 3)( 2 . 3 )    (setq cons  (symbol-function ‘+)#<Function +>       (funcall cons 2 3) 5funcall fn &rest arguments
Simple sequencingThese constructs simply evaluate all the argument forms in order. progn {form}*  progn construct takes a number of forms and evaluates them sequentially  in order from left to right.The values of all forms but the last are discarded, whatever the last form evaluates is returned as the result. prog1 first {form}*  is similar to progn but it returns the value of its first form.prog2 first second {form}* is similar to prog1, but it returns the value of the second form. prog2 ( a b c d…….) is similar to (prog a( prog1 b c…..z))
conditionalsThe traditional conditional construct in lisp is cond.CL also produces the dispatching constructs case and typecase.If test then [else] first the form is evaluated. If the result is not nil, then the form is selected.(If test then else) is similar to (cond (test then) (t else))(when test form1 form2…)first evaluates test. If the result is nil, then no form is evaluated, and nil is returned.Otherwise the forms constitute an implicit progn and are evaluated sequentially from left to right, and the value of the last one is returned .
(unless test form1 form2….) first evaluates test. If the result is not nil, then the forms are not evaluated, and nill is returned.Otherwise the form constitutes an implicit progn and are evaluated sequentially from left to right, and the value of the last one is returned.(cond (p…)               (q…)                (r…)     ………                (t…))Is similar to if p then…                         else if q then….                         else if r then…..                         …..                         else……
typecase keyform  {(type {form}* )}* typecase is a conditional that chooses one of it clauses by examining the type of an object. Its form is as follows:(typecase keyform       (type-1 consequent-1-1 consequent-1-2…..)       (type-2 consequent-2-1  …..)       (type-3 consequent-3-1 ….)        ….. )
Blocks and exitsThe block and return-form constructs provide a structured lexical non-local exit facility.block name {form}* the block construct executes each form from left to right, returning whatever is returned by the last form.
return-from name [result] return-from is used to return from a block or from such constraints as do and prog that implicitly establish a block.The name is not evaluated and must be a symbol.The evaluation of result produces multiple values, those multiple values are returned by the construct exited.return [result] (return form) is identical in meaning  to (return-from nil form)It returns from a block named nil.
IterationLoop construct provides a trivial iteration facility. It controls no variables, and simply executed its body repeatedly.loop {form}* each form is evaluated from left to right, when the last form has been evaluated, then the first form is evaluated again, and so on in a never ending cycle.Its execution must be terminated explicitly, using return or throw.
Do and do*Macro syntax:do ({var [init [step]])}*)    (end-test {result}*)   {declaration}* {tag|statement}*do* ({var [init [step]])}*)     (end-test {result}*)    {declaration}* {tag|statement}* The do special form provides a generalized iteration facility, with an arbitrary number of “index variables”.
Do form looks like this(do ((var1 init1 step1)        (var1 init1 step1)      …….(var1 init1 step1)      (end-test . result)    {declaration}*          .tagbody) The do* looks exactly the same except that the name do is replaced by do*.
MappingMapping is type of iteration in which a function is successively applied to pieces of one or more sequences.The result of the iteration is a sequence containing the respective results of the function applications.The function map may be used to map over any kind of sequence.
The following functions operate only on lists:mapcar function list &rest more-listsmaplist function list &rest more-listsmapcfunction list &rest more-listsmapl function list &rest more-listsmapcan function list &rest more-listsmapcon function list &rest more-lists
mapcar function list &rest more-listsmapcar operates on successive elements of lists, first the function is applied to the function of each list, then to the cadr of each list, and so on.
Ad

Recommended

PPT
Sets and disjoint sets union123
Ankita Goyal
 
PPT
Message passing interface
Md. Mahedi Mahfuj
 
PPT
Topic: Virtual circuit & message switching
Dr Rajiv Srivastava
 
PPTX
Computer graphics basic transformation
Selvakumar Gna
 
PPTX
TCP/IP Model
farhan516
 
PPTX
operator overloading & type conversion in cpp
gourav kottawar
 
PPT
Max flow min cut
Mayank Garg
 
PPTX
single linked list
Sathasivam Rangasamy
 
PPTX
Kruskal Algorithm
Snehasis Panigrahi
 
PDF
Johnson's algorithm
Kiran K
 
PPTX
Computer Graphics: Visible surface detection methods
Joseph Charles
 
PPTX
Halftoning in Computer Graphics
University of Potsdam
 
PPTX
Graph coloring using backtracking
shashidharPapishetty
 
PPTX
Graphics software standards
Ankit Garg
 
PPTX
Clipping
AMIT VIRAMGAMI
 
PPT
TCP/IP Protocols With All Layer Description
Shubham Khedekar
 
PPTX
The Application Layer
MSharmilaDeviITDEPT
 
PPTX
Graph traversals in Data Structures
Anandhasilambarasan D
 
PPT
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
PPTX
JAVA AWT
shanmuga rajan
 
PPTX
Binary tree and operations
varagilavanya
 
PPT
Java interfaces
Raja Sekhar
 
PPTX
Cyrus beck line clipping algorithm
Pooja Dixit
 
PDF
The Object Model
yndaravind
 
PDF
Difference between OSI Layer & TCP/IP Layer
Netwax Lab
 
PDF
Applications of stack
eShikshak
 
PPTX
LISP: Control Structures In Lisp
LISP Content
 
PPTX
LISP:Program structure in lisp
DataminingTools Inc
 

More Related Content

What's hot (20)

PPTX
Kruskal Algorithm
Snehasis Panigrahi
 
PDF
Johnson's algorithm
Kiran K
 
PPTX
Computer Graphics: Visible surface detection methods
Joseph Charles
 
PPTX
Halftoning in Computer Graphics
University of Potsdam
 
PPTX
Graph coloring using backtracking
shashidharPapishetty
 
PPTX
Graphics software standards
Ankit Garg
 
PPTX
Clipping
AMIT VIRAMGAMI
 
PPT
TCP/IP Protocols With All Layer Description
Shubham Khedekar
 
PPTX
The Application Layer
MSharmilaDeviITDEPT
 
PPTX
Graph traversals in Data Structures
Anandhasilambarasan D
 
PPT
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
PPTX
JAVA AWT
shanmuga rajan
 
PPTX
Binary tree and operations
varagilavanya
 
PPT
Java interfaces
Raja Sekhar
 
PPTX
Cyrus beck line clipping algorithm
Pooja Dixit
 
PDF
The Object Model
yndaravind
 
PDF
Difference between OSI Layer & TCP/IP Layer
Netwax Lab
 
PDF
Applications of stack
eShikshak
 
Kruskal Algorithm
Snehasis Panigrahi
 
Johnson's algorithm
Kiran K
 
Computer Graphics: Visible surface detection methods
Joseph Charles
 
Halftoning in Computer Graphics
University of Potsdam
 
Graph coloring using backtracking
shashidharPapishetty
 
Graphics software standards
Ankit Garg
 
Clipping
AMIT VIRAMGAMI
 
TCP/IP Protocols With All Layer Description
Shubham Khedekar
 
The Application Layer
MSharmilaDeviITDEPT
 
Graph traversals in Data Structures
Anandhasilambarasan D
 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
JAVA AWT
shanmuga rajan
 
Binary tree and operations
varagilavanya
 
Java interfaces
Raja Sekhar
 
Cyrus beck line clipping algorithm
Pooja Dixit
 
The Object Model
yndaravind
 
Difference between OSI Layer & TCP/IP Layer
Netwax Lab
 
Applications of stack
eShikshak
 

Viewers also liked (20)

PPTX
LISP: Control Structures In Lisp
LISP Content
 
PPTX
LISP:Program structure in lisp
DataminingTools Inc
 
PPTX
LISP: Introduction to lisp
DataminingTools Inc
 
PDF
Gentle Introduction To Lisp
Damien Garaud
 
PPTX
Lisp
sonukumar142
 
PPTX
LISP Programming Language (Artificial Intelligence)
wahab khan
 
PPT
Lisp Programming Languge
Yaser Jaradeh
 
PDF
Redesigning Common Lisp
fukamachi
 
PDF
Learn a language : LISP
Devnology
 
PPTX
A brief introduction to lisp language
David Gu
 
PDF
Introduction To Lisp
kyleburton
 
PPT
Expert systems
Jithin Zcs
 
PPT
Application of expert system
Dinkar DP
 
PPT
Introduction and architecture of expert system
premdeshmane
 
PPTX
Prolog & lisp
Ismail El Gayar
 
PPTX
LISP: Scope and extent in lisp
DataminingTools Inc
 
PPTX
LISP: Macros in lisp
DataminingTools Inc
 
PPTX
Data Applied: Association
DataminingTools Inc
 
PPT
Mphone
msprincess915
 
LISP: Control Structures In Lisp
LISP Content
 
LISP:Program structure in lisp
DataminingTools Inc
 
LISP: Introduction to lisp
DataminingTools Inc
 
Gentle Introduction To Lisp
Damien Garaud
 
LISP Programming Language (Artificial Intelligence)
wahab khan
 
Lisp Programming Languge
Yaser Jaradeh
 
Redesigning Common Lisp
fukamachi
 
Learn a language : LISP
Devnology
 
A brief introduction to lisp language
David Gu
 
Introduction To Lisp
kyleburton
 
Expert systems
Jithin Zcs
 
Application of expert system
Dinkar DP
 
Introduction and architecture of expert system
premdeshmane
 
Prolog & lisp
Ismail El Gayar
 
LISP: Scope and extent in lisp
DataminingTools Inc
 
LISP: Macros in lisp
DataminingTools Inc
 
Data Applied: Association
DataminingTools Inc
 
Ad

Similar to LISP:Control Structures In Lisp (20)

PPTX
LISP:Loops In Lisp
DataminingTools Inc
 
PPTX
LISP: Loops In Lisp
LISP Content
 
PDF
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
PPTX
LISP: Program structure in lisp
LISP Content
 
PPTX
Functions & Recursion
Nishant Munjal
 
PPTX
Presentatioon on type conversion and escape characters
faala
 
PDF
js_class_notes_for_ institute it is very useful for your study.pdf
Well82
 
PPTX
LISP: Macros in lisp
LISP Content
 
PPTX
Functions in C++
home
 
PPTX
advance algebra PPT Chapter 2 algebra alg
HannaniahJimanga3
 
PDF
Functional programming with clojure
Lucy Fang
 
PDF
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
PPSX
C++ quik notes
argusacademy
 
PPTX
C and C++ functions
kavitha muneeshwaran
 
DOC
Functions
zeeshan841
 
PPTX
functions
Makwana Bhavesh
 
PDF
The Ring programming language version 1.5.2 book - Part 31 of 181
Mahmoud Samir Fayed
 
PPTX
User defined function in C.pptx
Rhishav Poudyal
 
PDF
Functions
Pragnavi Erva
 
PPT
Evaluating function 1
Felina Victoria
 
LISP:Loops In Lisp
DataminingTools Inc
 
LISP: Loops In Lisp
LISP Content
 
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
LISP: Program structure in lisp
LISP Content
 
Functions & Recursion
Nishant Munjal
 
Presentatioon on type conversion and escape characters
faala
 
js_class_notes_for_ institute it is very useful for your study.pdf
Well82
 
LISP: Macros in lisp
LISP Content
 
Functions in C++
home
 
advance algebra PPT Chapter 2 algebra alg
HannaniahJimanga3
 
Functional programming with clojure
Lucy Fang
 
java write a program to evaluate the postfix expressionthe program.pdf
arjuntelecom26
 
C++ quik notes
argusacademy
 
C and C++ functions
kavitha muneeshwaran
 
Functions
zeeshan841
 
functions
Makwana Bhavesh
 
The Ring programming language version 1.5.2 book - Part 31 of 181
Mahmoud Samir Fayed
 
User defined function in C.pptx
Rhishav Poudyal
 
Functions
Pragnavi Erva
 
Evaluating function 1
Felina Victoria
 
Ad

More from DataminingTools Inc (20)

PPTX
Terminology Machine Learning
DataminingTools Inc
 
PPTX
Techniques Machine Learning
DataminingTools Inc
 
PPTX
Machine learning Introduction
DataminingTools Inc
 
PPTX
Areas of machine leanring
DataminingTools Inc
 
PPTX
AI: Planning and AI
DataminingTools Inc
 
PPTX
AI: Logic in AI 2
DataminingTools Inc
 
PPTX
AI: Logic in AI
DataminingTools Inc
 
PPTX
AI: Learning in AI 2
DataminingTools Inc
 
PPTX
AI: Learning in AI
DataminingTools Inc
 
PPTX
AI: Introduction to artificial intelligence
DataminingTools Inc
 
PPTX
AI: Belief Networks
DataminingTools Inc
 
PPTX
AI: AI & Searching
DataminingTools Inc
 
PPTX
AI: AI & Problem Solving
DataminingTools Inc
 
PPTX
Data Mining: Text and web mining
DataminingTools Inc
 
PPTX
Data Mining: Outlier analysis
DataminingTools Inc
 
PPTX
Data Mining: Mining stream time series and sequence data
DataminingTools Inc
 
PPTX
Data Mining: Mining ,associations, and correlations
DataminingTools Inc
 
PPTX
Data Mining: Graph mining and social network analysis
DataminingTools Inc
 
PPTX
Data warehouse and olap technology
DataminingTools Inc
 
PPTX
Data Mining: Data processing
DataminingTools Inc
 
Terminology Machine Learning
DataminingTools Inc
 
Techniques Machine Learning
DataminingTools Inc
 
Machine learning Introduction
DataminingTools Inc
 
Areas of machine leanring
DataminingTools Inc
 
AI: Planning and AI
DataminingTools Inc
 
AI: Logic in AI 2
DataminingTools Inc
 
AI: Logic in AI
DataminingTools Inc
 
AI: Learning in AI 2
DataminingTools Inc
 
AI: Learning in AI
DataminingTools Inc
 
AI: Introduction to artificial intelligence
DataminingTools Inc
 
AI: Belief Networks
DataminingTools Inc
 
AI: AI & Searching
DataminingTools Inc
 
AI: AI & Problem Solving
DataminingTools Inc
 
Data Mining: Text and web mining
DataminingTools Inc
 
Data Mining: Outlier analysis
DataminingTools Inc
 
Data Mining: Mining stream time series and sequence data
DataminingTools Inc
 
Data Mining: Mining ,associations, and correlations
DataminingTools Inc
 
Data Mining: Graph mining and social network analysis
DataminingTools Inc
 
Data warehouse and olap technology
DataminingTools Inc
 
Data Mining: Data processing
DataminingTools Inc
 

Recently uploaded (20)

PDF
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PDF
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
PDF
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
PDF
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
PDF
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
PDF
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
PDF
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
PPTX
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
PDF
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PDF
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
PDF
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
PDF
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
PDF
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
PPTX
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
PDF
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
WebdriverIO & JavaScript: The Perfect Duo for Web Automation
digitaljignect
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
The Growing Value and Application of FME & GenAI
Safe Software
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
 

LISP:Control Structures In Lisp

  • 2. Common Lisp provides with a variety of special structures for organizing the programs.Some have to do with the flow of control. These are called as control structures.Locally defined functions(flet, labels) and macros( macrolet) are quite flexible.CL provides: simple one-way conditionals (when and unless.)
  • 3. the simple two-way conditionals (if)
  • 4. more general multi-way conditionals( cond, case)Constructs for performing non local exits with various scoping disciplines are provided: block, return, return-from, catch and throw.
  • 5. overviewConstants and variablesReferencesAssignmentGeneralized variablesFunction invocationSimple sequencingConditionalsBlocks and ExitsIterations Mapping
  • 6. Constants and variablesCL provides two kinds of variables: ordinary variables and function names. One of them is used to name defined function, macros, and special forms , and the other to name data objects. The name of the ordinary variable may be obtained by simply writing the name of the variable as a form to be executed.The following functions and variables allow reference to the values of constants and variables:quote object simply returns the objectfunction fn if fn is a symbol, the functional definition associated with that symbol is returned. If fn is a lambda-expression, then a “lexical closure” is returned.
  • 7. ReferencesSymbol-value symbol returns the dynamic current value of the symbol, error occurs if the symbol has no values.Symbol-function-symbol returns the current global function definition named by the symbol, error is signaled if the symbol has no function definition.Symbol-function is applicable only for global functions its not applicable for lexical function name produced by flet or labels.
  • 8. Symbol-function can be called on any function on which fbound function is true.fbound in turn returns true for symbols which define a macro or a special form.When symbol-function is used with typef, its new value must be type function.fdefinition function-name returns the current global function definition named by the argument function name.
  • 9. boundp symbol returns true if the symbol has a value, else returns false.fboundp symbol returns true if the function has global function definitionSpecial-form-p symbol returns a non-nil value if the symbol globally names a special form, else returns nil
  • 10. AssignmentThe following allow the value associated with the current binding of the variable to be changed.(setq var1 form1 var2 form2 ….) here first the form1 is calculated and the value is stored in val1, then form2 is calculated and stored in form2 and so on..Setq returns the last value assigned, there must be even number of arguments forms.Ex: (setq x (* 3 2) y (cons x nil))retains the first set value of x as 6 and returns 6.Psetq {form}* is similar to setq except that assignments happen in parallel.Ex: (setq a 4) (setq b 6) (psetq a b b a) a=6 and b=4, thus the values of a and b are exchanged by using parallel assignment
  • 11. Set symbol value1  allows the alteration of the dynamic variable , set allows the symbol to take value1 as its value.Ex: (set (if (eq a b) ‘c ‘d) ‘foo) sets either c to foo or d to foo depending on the outcome of the result, set returns the value as a result.makeunbound symbol causes the dynamic(special) variable named by symbol to become unbound.fmakeunbound symbol makes the analogous thing for the global function definition named by symbol.
  • 12. Generalized variablesThe concept of the variables named by symbols can be generalized to any storage location that can remember one piece of data.Ex of such storage locations are the car and cdr of cons.Basic operations on variables are: access and update operations.The following table give the various access and update functions:
  • 13. Setf is a macro that that examines an access form and produces a call to corresponding update function.Setf {place new-value}* takes a form place that when evaluated accesses a data object in some location and “inverts” it to produce a corresponding form to update the location.If more than one place-newvalue pair is specified, the pairs are processed sequentially; that is(setf place1 newvalue1, place2 newvalue2, …… placen newvaluen)
  • 14. Rotatef{place}* each place form may be any form acceptable as a generalized variable to setf.In the form (rotatef place1,place2,...placen) the values of place1 to placen are being accessed and saved.It is as if all the places from an end-round shift register that is rotated one place to the left, with the value of place1 being shifted around to the end to placen. (setf place1 value1 place2 value2…) the subforms of place1 and value1 are evaluated, the location specified by place1 is modified to contain the value returned by value1, and then the rest of setf form is processed in a like manner.
  • 15. Function invocationAny list that has no other interpretation to as a macro call or special form is taken to be a function call.This applies function to a list of arguments.The arguments of the function consists of the last arguments to apply appended to the end of the list of all the other arguments to apply but the function itself.Ex: (setf a ‘*) (apply a ‘( 3 2))6If the function takes keyword arguments , the keywords as well as the corresponding values must appear in the argument list.Ex: (apply # ‘(lamda (&key a b) (list a b)) ‘(:b 3))(nil 3)apply function arg &rest more-args
  • 16. (funcall fn a1,a2,a3……an) applies the function fn to arguments a1,a2,….anEx: (cons 2 3)( 2 . 3 ) (setq cons (symbol-function ‘+)#<Function +> (funcall cons 2 3) 5funcall fn &rest arguments
  • 17. Simple sequencingThese constructs simply evaluate all the argument forms in order. progn {form}*  progn construct takes a number of forms and evaluates them sequentially in order from left to right.The values of all forms but the last are discarded, whatever the last form evaluates is returned as the result. prog1 first {form}*  is similar to progn but it returns the value of its first form.prog2 first second {form}* is similar to prog1, but it returns the value of the second form. prog2 ( a b c d…….) is similar to (prog a( prog1 b c…..z))
  • 18. conditionalsThe traditional conditional construct in lisp is cond.CL also produces the dispatching constructs case and typecase.If test then [else] first the form is evaluated. If the result is not nil, then the form is selected.(If test then else) is similar to (cond (test then) (t else))(when test form1 form2…)first evaluates test. If the result is nil, then no form is evaluated, and nil is returned.Otherwise the forms constitute an implicit progn and are evaluated sequentially from left to right, and the value of the last one is returned .
  • 19. (unless test form1 form2….) first evaluates test. If the result is not nil, then the forms are not evaluated, and nill is returned.Otherwise the form constitutes an implicit progn and are evaluated sequentially from left to right, and the value of the last one is returned.(cond (p…) (q…) (r…) ……… (t…))Is similar to if p then… else if q then…. else if r then….. ….. else……
  • 20. typecase keyform {(type {form}* )}* typecase is a conditional that chooses one of it clauses by examining the type of an object. Its form is as follows:(typecase keyform (type-1 consequent-1-1 consequent-1-2…..) (type-2 consequent-2-1 …..) (type-3 consequent-3-1 ….) ….. )
  • 21. Blocks and exitsThe block and return-form constructs provide a structured lexical non-local exit facility.block name {form}* the block construct executes each form from left to right, returning whatever is returned by the last form.
  • 22. return-from name [result] return-from is used to return from a block or from such constraints as do and prog that implicitly establish a block.The name is not evaluated and must be a symbol.The evaluation of result produces multiple values, those multiple values are returned by the construct exited.return [result] (return form) is identical in meaning to (return-from nil form)It returns from a block named nil.
  • 23. IterationLoop construct provides a trivial iteration facility. It controls no variables, and simply executed its body repeatedly.loop {form}* each form is evaluated from left to right, when the last form has been evaluated, then the first form is evaluated again, and so on in a never ending cycle.Its execution must be terminated explicitly, using return or throw.
  • 24. Do and do*Macro syntax:do ({var [init [step]])}*) (end-test {result}*) {declaration}* {tag|statement}*do* ({var [init [step]])}*) (end-test {result}*) {declaration}* {tag|statement}* The do special form provides a generalized iteration facility, with an arbitrary number of “index variables”.
  • 25. Do form looks like this(do ((var1 init1 step1) (var1 init1 step1) …….(var1 init1 step1) (end-test . result) {declaration}* .tagbody) The do* looks exactly the same except that the name do is replaced by do*.
  • 26. MappingMapping is type of iteration in which a function is successively applied to pieces of one or more sequences.The result of the iteration is a sequence containing the respective results of the function applications.The function map may be used to map over any kind of sequence.
  • 27. The following functions operate only on lists:mapcar function list &rest more-listsmaplist function list &rest more-listsmapcfunction list &rest more-listsmapl function list &rest more-listsmapcan function list &rest more-listsmapcon function list &rest more-lists
  • 28. mapcar function list &rest more-listsmapcar operates on successive elements of lists, first the function is applied to the function of each list, then to the cadr of each list, and so on.
  • 29. The value returned by the mapcar is a list of the results of the successive calls to the function.Ex: (mapcar #’abs ‘(3 -4 2 -5 -6))(3 4 2 5 6) (mapcar #’ cons ‘(a b c) ‘(1 2 3))((a.1) (b.2) (c.3))
  • 30. maplist function list &rest more-listsmaplist is similar to mapcar except that the function is applied to the lists and successive elements of the lists.Ex: (maplist #’ (lambda (x) (cons ‘foo x)) ‘(a b c d)) ((foo a b c d) (foo b c d) (foo c d) (foo d))
  • 31. Visit more self help tutorialsPick a tutorial of your choice and browse through it at your own pace.The tutorials section is free, self-guiding and will not involve any additional support.Visit us at www.dataminingtools.net