SlideShare ist ein Scribd-Unternehmen logo
1 von 28
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: ,[object Object]
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.
overview Constants and variables References Assignment Generalized variables Function invocation Simple sequencing Conditionals Blocks and Exits Iterations  Mapping
Constants and variables CL 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 object function 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.
References Symbol-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 definition Special-form-p symbol returns a non-nil value if the symbol globally names a special form, else returns nil
Assignment The 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 variables The 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 invocation Any 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))6 If 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,….an Ex: (cons 2 3)( 2 . 3 )     (setq cons  (symbol-function ‘+)#<Function +>        (funcall cons 2 3) 5 funcall fn &rest arguments
Simple sequencing These 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))
conditionals The 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 exits The 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.
Iteration Loop 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*.
Mapping Mapping 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-lists maplist function list &rest more-lists mapcfunction list &rest more-lists mapl function list &rest more-lists mapcan function list &rest more-lists mapcon function list &rest more-lists
mapcar function list &rest more-lists ,[object Object]

Weitere ähnliche Inhalte

Was ist angesagt?

Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Shameer Ahmed Koya
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04IIUM
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABShameer Ahmed Koya
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4Shameer Ahmed Koya
 
Storage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageStorage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageJenish Bhavsar
 
Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1IIUM
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiSowmya Jyothi
 
Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsqlArun Sial
 
Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlabharman kaur
 
Bsc cs pic u-3 handling input output and control statements
Bsc cs  pic u-3 handling input output and control statementsBsc cs  pic u-3 handling input output and control statements
Bsc cs pic u-3 handling input output and control statementsRai University
 
C language presentation
C language presentationC language presentation
C language presentationbainspreet
 
PLSQL CURSOR
PLSQL CURSORPLSQL CURSOR
PLSQL CURSORArun Sial
 
Functional programing in Javascript (lite intro)
Functional programing in Javascript (lite intro)Functional programing in Javascript (lite intro)
Functional programing in Javascript (lite intro)Nikos Kalogridis
 
Recursive Function
Recursive FunctionRecursive Function
Recursive FunctionHarsh Pathak
 

Was ist angesagt? (20)

Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1
 
Csc1100 lecture04 ch04
Csc1100 lecture04 ch04Csc1100 lecture04 ch04
Csc1100 lecture04 ch04
 
Anonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLABAnonymous and Inline Functions in MATLAB
Anonymous and Inline Functions in MATLAB
 
User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4User Defined Functions in MATLAB Part-4
User Defined Functions in MATLAB Part-4
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
Storage classes arrays & functions in C Language
Storage classes arrays & functions in C LanguageStorage classes arrays & functions in C Language
Storage classes arrays & functions in C Language
 
Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1
 
Java 8
Java 8Java 8
Java 8
 
Functions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothiFunctions in c mrs.sowmya jyothi
Functions in c mrs.sowmya jyothi
 
Triggers in plsql
Triggers in plsqlTriggers in plsql
Triggers in plsql
 
Working with functions in matlab
Working with functions in matlabWorking with functions in matlab
Working with functions in matlab
 
Bsc cs pic u-3 handling input output and control statements
Bsc cs  pic u-3 handling input output and control statementsBsc cs  pic u-3 handling input output and control statements
Bsc cs pic u-3 handling input output and control statements
 
C language presentation
C language presentationC language presentation
C language presentation
 
PLSQL CURSOR
PLSQL CURSORPLSQL CURSOR
PLSQL CURSOR
 
Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
 
SQL / PL
SQL / PLSQL / PL
SQL / PL
 
Functional programing in Javascript (lite intro)
Functional programing in Javascript (lite intro)Functional programing in Javascript (lite intro)
Functional programing in Javascript (lite intro)
 
Some basic FP concepts
Some basic FP conceptsSome basic FP concepts
Some basic FP concepts
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 

Ähnlich wie LISP: Control Structures In Lisp

LISP: Loops In Lisp
LISP: Loops In LispLISP: Loops In Lisp
LISP: Loops In LispLISP Content
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 
LISP: Program structure in lisp
LISP: Program structure in lispLISP: Program structure in lisp
LISP: Program structure in lispLISP Content
 
Presentatioon on type conversion and escape characters
Presentatioon on type conversion and escape charactersPresentatioon on type conversion and escape characters
Presentatioon on type conversion and escape charactersfaala
 
LISP: Macros in lisp
LISP: Macros in lispLISP: Macros in lisp
LISP: Macros in lispLISP Content
 
Functions in C++
Functions in C++Functions in C++
Functions in C++home
 
Functional programming with clojure
Functional programming with clojureFunctional programming with clojure
Functional programming with clojureLucy Fang
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfarjuntelecom26
 
The Ring programming language version 1.5.2 book - Part 31 of 181
The Ring programming language version 1.5.2 book - Part 31 of 181The Ring programming language version 1.5.2 book - Part 31 of 181
The Ring programming language version 1.5.2 book - Part 31 of 181Mahmoud Samir Fayed
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptxRhishav Poudyal
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsMegha V
 

Ähnlich wie LISP: Control Structures In Lisp (20)

LISP: Loops In Lisp
LISP: Loops In LispLISP: Loops In Lisp
LISP: Loops In Lisp
 
LISP:Loops In Lisp
LISP:Loops In LispLISP:Loops In Lisp
LISP:Loops In Lisp
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
LISP: Program structure in lisp
LISP: Program structure in lispLISP: Program structure in lisp
LISP: Program structure in lisp
 
Functions & Recursion
Functions & RecursionFunctions & Recursion
Functions & Recursion
 
Presentatioon on type conversion and escape characters
Presentatioon on type conversion and escape charactersPresentatioon on type conversion and escape characters
Presentatioon on type conversion and escape characters
 
LISP: Macros in lisp
LISP: Macros in lispLISP: Macros in lisp
LISP: Macros in lisp
 
LISP: Macros in lisp
LISP: Macros in lispLISP: Macros in lisp
LISP: Macros in lisp
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Functional programming with clojure
Functional programming with clojureFunctional programming with clojure
Functional programming with clojure
 
java write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdfjava write a program to evaluate the postfix expressionthe program.pdf
java write a program to evaluate the postfix expressionthe program.pdf
 
C++ quik notes
C++ quik notesC++ quik notes
C++ quik notes
 
C and C++ functions
C and C++ functionsC and C++ functions
C and C++ functions
 
Functions
FunctionsFunctions
Functions
 
functions
functionsfunctions
functions
 
The Ring programming language version 1.5.2 book - Part 31 of 181
The Ring programming language version 1.5.2 book - Part 31 of 181The Ring programming language version 1.5.2 book - Part 31 of 181
The Ring programming language version 1.5.2 book - Part 31 of 181
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
 
Functions
FunctionsFunctions
Functions
 
Evaluating function 1
Evaluating function 1Evaluating function 1
Evaluating function 1
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 

Mehr von LISP Content

LISP:Declarations In Lisp
LISP:Declarations In LispLISP:Declarations In Lisp
LISP:Declarations In LispLISP Content
 
LISP: Errors In Lisp
LISP: Errors In LispLISP: Errors In Lisp
LISP: Errors In LispLISP Content
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And OutputLISP Content
 
LISP: Object Sytstem Lisp
LISP: Object Sytstem LispLISP: Object Sytstem Lisp
LISP: Object Sytstem LispLISP Content
 
LISP: Type specifiers in lisp
LISP: Type specifiers in lispLISP: Type specifiers in lisp
LISP: Type specifiers in lispLISP Content
 
LISP: Symbols and packages in lisp
LISP: Symbols and packages in lispLISP: Symbols and packages in lisp
LISP: Symbols and packages in lispLISP Content
 
LISP: Scope and extent in lisp
LISP: Scope and extent in lispLISP: Scope and extent in lisp
LISP: Scope and extent in lispLISP Content
 
LISP: Predicates in lisp
LISP: Predicates in lispLISP: Predicates in lisp
LISP: Predicates in lispLISP Content
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lispLISP Content
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To LispLISP Content
 

Mehr von LISP Content (10)

LISP:Declarations In Lisp
LISP:Declarations In LispLISP:Declarations In Lisp
LISP:Declarations In Lisp
 
LISP: Errors In Lisp
LISP: Errors In LispLISP: Errors In Lisp
LISP: Errors In Lisp
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
 
LISP: Object Sytstem Lisp
LISP: Object Sytstem LispLISP: Object Sytstem Lisp
LISP: Object Sytstem Lisp
 
LISP: Type specifiers in lisp
LISP: Type specifiers in lispLISP: Type specifiers in lisp
LISP: Type specifiers in lisp
 
LISP: Symbols and packages in lisp
LISP: Symbols and packages in lispLISP: Symbols and packages in lisp
LISP: Symbols and packages in lisp
 
LISP: Scope and extent in lisp
LISP: Scope and extent in lispLISP: Scope and extent in lisp
LISP: Scope and extent in lisp
 
LISP: Predicates in lisp
LISP: Predicates in lispLISP: Predicates in lisp
LISP: Predicates in lisp
 
LISP: Data types in lisp
LISP: Data types in lispLISP: Data types in lisp
LISP: Data types in lisp
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
 

Kürzlich hochgeladen

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Kürzlich hochgeladen (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

LISP: Control Structures In Lisp

  • 2.
  • 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. overview Constants and variables References Assignment Generalized variables Function invocation Simple sequencing Conditionals Blocks and Exits Iterations Mapping
  • 6. Constants and variables CL 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 object function 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. References Symbol-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 definition Special-form-p symbol returns a non-nil value if the symbol globally names a special form, else returns nil
  • 10. Assignment The 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 variables The 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 invocation Any 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))6 If 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,….an Ex: (cons 2 3)( 2 . 3 ) (setq cons (symbol-function ‘+)#<Function +> (funcall cons 2 3) 5 funcall fn &rest arguments
  • 17. Simple sequencing These 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. conditionals The 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 exits The 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. Iteration Loop 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. Mapping Mapping 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-lists maplist function list &rest more-lists mapcfunction list &rest more-lists mapl function list &rest more-lists mapcan function list &rest more-lists mapcon function list &rest more-lists
  • 28.
  • 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.
  • 31. Visit more self help tutorials Pick 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