SlideShare a Scribd company logo
Program structure in Lisp
overviewFormsVariablesMacrosFunction callsNamed functionsLambda expressionsTop-level formsDeclaring global variables and named constantsControl of time and evaluation
formsForms are the standard units of iteration in CL implementation.A form is simply a data object meant to be evaluated as a program to produce one or more values.Meaning full forms may be further divided into:Self-evaluating forms(numbers)
Symbols(variables)
ListsLists can further be divided as: special forms, macro calls and function calls.All characters, numbers, string, and bit-vectors are all self-evaluating forms.When such an object is evaluated, that object is returned as the value of the form.
VariablesSymbols are used as the names for the variables in CL programs.When a symbol is evaluated as the form, the value of the variable it names is produced.Ex: (setq w 8)produces 8Types of variables:Lexical (static)
Special (dynamic)Special formsCommon lisp special forms:While the lisp is being evaluated as a form, if the first element is one of the element in the above table, then it is called a special form.Ex: (if p (+ x 4) 5) means if p then x+4 else 5block                                           if                                                    progvcatch                                           labels                                            quote[compiler-let]                          let                                                  return-fromdeclare                                       let*	                                     setqeval-when                                  macrolet                                       tagbodyflet                                               multiple-value-call                      thefunction                                      multiple-value-prog1                  throwgo                                                 progn                                            unwind-protect
It is recommended that the program-analyzing program process a form that is a list whose car is a symbol as follows:If the program has particular knowledge about the symbol, process the form using special –purpose code. All the symbols in the previous table fall under this category.
If the macro-function is true of the symbol, apply either macro-expand or macroexpand-1, as appropriate to the entire form and then start over.
Otherwise, assume it as a function call.MacrosA macro is essentially a function from forms to forms.Given a call to a macro, compute a new form to be evaluated in the place of the macro call.There are a number of standard forms in CL, to define a new form use defmacro.
Function callsWhile the list is being evaluated as a form, if the first element is not a symbol that names a special form or a macro, the it is considered as a function call.The first element of the list is taken as the name of the function.All the remaining elements of the list are evaluated and one value is obtained from each form, and these values become the arguments to the function.Whatever values the function returns becomes the values of the function-call forms.
Function calls continued..Ex: (+ 3 (* 1 2)) here, + is not a special form or macro. So 3 and (* 1 2) are considered as arguments of the function call, again 1 2 are taken as arguments of the function call (* 1 2) and the value 2 is returned. The values 2 and 3 are given as arguments for the addition function to produce the result 5. Thus, ( + 3 (* 1 2))5
FunctionsTwo ways to indicate the function as the function-call form are: using symbols to name the functions
 using a lambda-expression whose first element in the list is lambda.Lambda expressions or the symbols when used in programs as the name of the functions, can appear only as the first element of the function-call form, or the second element of the function special form.A global name can be given to a function using the defun construct.A local name is given to the function using the flet or labels construct.
Lambda-expressionsA lambda-expression has the following syntax:(lambda lambda-list .body)The first element must be lambda, the second element must be the list, and specifies names for the parameters of the listThe body may consists of zero or more number of forms.Each element in the lambda-list is either a parameter specifier or the lambda-list keyword.(lambda-list keywords begin with &)Var or svar must be a symbol( the name of the variable),Each keyword must be a keyword symbol, such as :start
A lambda-list has five partsSpecifiers for the required parameters: these are parameter specifiers up to the first lambda-list keyword.Specifiers for the optional parameters: these are the specifiers  following the lambda-list keyword &optional up to the next lambda-list keyword or the end of the list.A specifier for a rest parameterSpecifiers for the keyword parametersSpecifiers for the aux parameters: If the lambda-list keyword &key is present, all specifiers after it are auxiliary variable specifiers.
Top-level formsThe standard way to interact with CL implementation is via a read-eval-print loop.The system reads a form from the same input source, evaluates it and then prints the value to the output sink.Top-level special forms are used:To define globally named functions
Define macros
Make declarations
Define global values for special variablesIf progn appears at top-level, then all forms within that progn are considered by the compiler to be top-level forms.

More Related Content

What's hot (20)

PDF
Some basic FP concepts
Falko Riemenschneider
 
PPT
Csc1100 lecture04 ch04
IIUM
 
PDF
C intro
SHIKHA GAUTAM
 
PDF
Programming with Lambda Expressions in Java
langer4711
 
PPTX
Matlab m files and scripts
Ameen San
 
PDF
Java 8
Sheeban Singaram
 
PDF
Scala qq
羽祈 張
 
PDF
Java 8 Lambda Expressions & Streams
NewCircle Training
 
PPTX
Anonymous and Inline Functions in MATLAB
Shameer Ahmed Koya
 
PPTX
Programming in java - Concepts- Operators- Control statements-Expressions
LovelitJose
 
PPT
C++ rajan
Deep Rajan
 
PDF
C++ tokens and expressions
NabeelaNousheen
 
PPTX
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
PPTX
Java 8 presentation
Van Huong
 
PPT
Csc1100 lecture06 ch06_pt1
IIUM
 
PDF
C programming session5
Keroles karam khalil
 
PDF
What's new in java 8
Dian Aditya
 
PDF
Java8
Felipe Mamud
 
PDF
Java 8 features
NexThoughts Technologies
 
PPTX
An Introduction to MATLAB for beginners
Murshida ck
 
Some basic FP concepts
Falko Riemenschneider
 
Csc1100 lecture04 ch04
IIUM
 
C intro
SHIKHA GAUTAM
 
Programming with Lambda Expressions in Java
langer4711
 
Matlab m files and scripts
Ameen San
 
Scala qq
羽祈 張
 
Java 8 Lambda Expressions & Streams
NewCircle Training
 
Anonymous and Inline Functions in MATLAB
Shameer Ahmed Koya
 
Programming in java - Concepts- Operators- Control statements-Expressions
LovelitJose
 
C++ rajan
Deep Rajan
 
C++ tokens and expressions
NabeelaNousheen
 
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
Java 8 presentation
Van Huong
 
Csc1100 lecture06 ch06_pt1
IIUM
 
C programming session5
Keroles karam khalil
 
What's new in java 8
Dian Aditya
 
Java 8 features
NexThoughts Technologies
 
An Introduction to MATLAB for beginners
Murshida ck
 

Viewers also liked (20)

PPTX
LISP: Introduction to lisp
DataminingTools Inc
 
PPTX
A brief introduction to lisp language
David Gu
 
PDF
Introduction To Lisp
kyleburton
 
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
 
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
Art, Culture, and Technology
TVWS, LLC
 
PPTX
Quick Look At Classification
DataminingTools Inc
 
PPTX
Txomin Hartz Txikia
irantzugoitia86
 
ODP
Oratoria E RetóRica Latinas
lara
 
PPT
PresentacióN De Quimica
guestf6a53c
 
PPT
Facebook: An Innovative Influenza Pandemic Early Warning System
Chen Luo
 
LISP: Introduction to lisp
DataminingTools Inc
 
A brief introduction to lisp language
David Gu
 
Introduction To Lisp
kyleburton
 
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
 
Expert systems
Jithin Zcs
 
Application of expert system
Dinkar DP
 
Introduction and architecture of expert system
premdeshmane
 
Prolog & lisp
Ismail El Gayar
 
Art, Culture, and Technology
TVWS, LLC
 
Quick Look At Classification
DataminingTools Inc
 
Txomin Hartz Txikia
irantzugoitia86
 
Oratoria E RetóRica Latinas
lara
 
PresentacióN De Quimica
guestf6a53c
 
Facebook: An Innovative Influenza Pandemic Early Warning System
Chen Luo
 
Ad

Similar to LISP:Program structure in lisp (20)

PPTX
LISP: Macros in lisp
LISP Content
 
PPTX
LISP: Macros in lisp
DataminingTools Inc
 
PPTX
Functions in C++
home
 
PPTX
Functions in C++
home
 
PPTX
C language 3
Arafat Bin Reza
 
PPTX
User defined function in C.pptx
Rhishav Poudyal
 
PDF
User defined functions in matlab
Infinity Tech Solutions
 
PPTX
Function overloading
Selvin Josy Bai Somu
 
PPTX
c & c++ logic building concepts practice.pptx
rawatsatish0327
 
PPTX
Functions
Septi Ratnasari
 
PPTX
04. WORKING WITH FUNCTIONS-2 (1).pptx
Manas40552
 
PDF
1669958779195.pdf
venud11
 
PPT
Unit 3 principles of programming language
Vasavi College of Engg
 
PDF
programlama fonksiyonlar c++ hjhjghjv jg
uleAmet
 
PDF
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
PDF
scala.reflect, Eugene Burmako
Vasil Remeniuk
 
PDF
Евгений Бурмако «scala.reflect»
e-Legion
 
PDF
final pl paper
AADIL AHMED ADAM
 
PDF
Function in C++
Prof Ansari
 
PPTX
FUNCTION CPU
Krushal Kakadia
 
LISP: Macros in lisp
LISP Content
 
LISP: Macros in lisp
DataminingTools Inc
 
Functions in C++
home
 
Functions in C++
home
 
C language 3
Arafat Bin Reza
 
User defined function in C.pptx
Rhishav Poudyal
 
User defined functions in matlab
Infinity Tech Solutions
 
Function overloading
Selvin Josy Bai Somu
 
c & c++ logic building concepts practice.pptx
rawatsatish0327
 
Functions
Septi Ratnasari
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
Manas40552
 
1669958779195.pdf
venud11
 
Unit 3 principles of programming language
Vasavi College of Engg
 
programlama fonksiyonlar c++ hjhjghjv jg
uleAmet
 
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
jacobdiriba
 
scala.reflect, Eugene Burmako
Vasil Remeniuk
 
Евгений Бурмако «scala.reflect»
e-Legion
 
final pl paper
AADIL AHMED ADAM
 
Function in C++
Prof Ansari
 
FUNCTION CPU
Krushal Kakadia
 
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
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
“MPU+: A Transformative Solution for Next-Gen AI at the Edge,” a Presentation...
Edge AI and Vision Alliance
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
Practical Applications of AI in Local Government
OnBoard
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
The Growing Value and Application of FME & GenAI
Safe Software
 

LISP:Program structure in lisp

  • 2. overviewFormsVariablesMacrosFunction callsNamed functionsLambda expressionsTop-level formsDeclaring global variables and named constantsControl of time and evaluation
  • 3. formsForms are the standard units of iteration in CL implementation.A form is simply a data object meant to be evaluated as a program to produce one or more values.Meaning full forms may be further divided into:Self-evaluating forms(numbers)
  • 5. ListsLists can further be divided as: special forms, macro calls and function calls.All characters, numbers, string, and bit-vectors are all self-evaluating forms.When such an object is evaluated, that object is returned as the value of the form.
  • 6. VariablesSymbols are used as the names for the variables in CL programs.When a symbol is evaluated as the form, the value of the variable it names is produced.Ex: (setq w 8)produces 8Types of variables:Lexical (static)
  • 7. Special (dynamic)Special formsCommon lisp special forms:While the lisp is being evaluated as a form, if the first element is one of the element in the above table, then it is called a special form.Ex: (if p (+ x 4) 5) means if p then x+4 else 5block if progvcatch labels quote[compiler-let] let return-fromdeclare let* setqeval-when macrolet tagbodyflet multiple-value-call thefunction multiple-value-prog1 throwgo progn unwind-protect
  • 8. It is recommended that the program-analyzing program process a form that is a list whose car is a symbol as follows:If the program has particular knowledge about the symbol, process the form using special –purpose code. All the symbols in the previous table fall under this category.
  • 9. If the macro-function is true of the symbol, apply either macro-expand or macroexpand-1, as appropriate to the entire form and then start over.
  • 10. Otherwise, assume it as a function call.MacrosA macro is essentially a function from forms to forms.Given a call to a macro, compute a new form to be evaluated in the place of the macro call.There are a number of standard forms in CL, to define a new form use defmacro.
  • 11. Function callsWhile the list is being evaluated as a form, if the first element is not a symbol that names a special form or a macro, the it is considered as a function call.The first element of the list is taken as the name of the function.All the remaining elements of the list are evaluated and one value is obtained from each form, and these values become the arguments to the function.Whatever values the function returns becomes the values of the function-call forms.
  • 12. Function calls continued..Ex: (+ 3 (* 1 2)) here, + is not a special form or macro. So 3 and (* 1 2) are considered as arguments of the function call, again 1 2 are taken as arguments of the function call (* 1 2) and the value 2 is returned. The values 2 and 3 are given as arguments for the addition function to produce the result 5. Thus, ( + 3 (* 1 2))5
  • 13. FunctionsTwo ways to indicate the function as the function-call form are: using symbols to name the functions
  • 14. using a lambda-expression whose first element in the list is lambda.Lambda expressions or the symbols when used in programs as the name of the functions, can appear only as the first element of the function-call form, or the second element of the function special form.A global name can be given to a function using the defun construct.A local name is given to the function using the flet or labels construct.
  • 15. Lambda-expressionsA lambda-expression has the following syntax:(lambda lambda-list .body)The first element must be lambda, the second element must be the list, and specifies names for the parameters of the listThe body may consists of zero or more number of forms.Each element in the lambda-list is either a parameter specifier or the lambda-list keyword.(lambda-list keywords begin with &)Var or svar must be a symbol( the name of the variable),Each keyword must be a keyword symbol, such as :start
  • 16. A lambda-list has five partsSpecifiers for the required parameters: these are parameter specifiers up to the first lambda-list keyword.Specifiers for the optional parameters: these are the specifiers following the lambda-list keyword &optional up to the next lambda-list keyword or the end of the list.A specifier for a rest parameterSpecifiers for the keyword parametersSpecifiers for the aux parameters: If the lambda-list keyword &key is present, all specifiers after it are auxiliary variable specifiers.
  • 17. Top-level formsThe standard way to interact with CL implementation is via a read-eval-print loop.The system reads a form from the same input source, evaluates it and then prints the value to the output sink.Top-level special forms are used:To define globally named functions
  • 20. Define global values for special variablesIf progn appears at top-level, then all forms within that progn are considered by the compiler to be top-level forms.
  • 21. Defining named functionsdefun special form is used for defining named functions. evaluating the defun form causes the symbol name to be a global name for the function specified by the lambda-expression.(defun (setf cadr)…) is used to define a setf expansion function to cadr.Forms constitute the body of the defined function, they are executed as an implicit progn.defun name lambda-list [[ {declaration}* | doc-string]] {form}*
  • 22. Declaring global variables and named constantsThe following special forms are used to specify globally defined variables: defvar
  • 24. defconstant (used for defining named constants)Syntax:defvar name [initial-value [documentation]]defparameter name initial-value [documentation]defconstant name initial-value [documentation]
  • 25. (defvar variable) proclaims the variable to be special.defvar also gives a good option to provide the comment for the variableEx: (defvar *visible-windows* 0 “number of visual windows at least partially visible on the screen”)defparameter is similar to defvar, but it requires an initial value-form, always evaluates the form, and assigns the result to the variable.defconstant is like defparameter but does assert that the value of the variable name is fixed and does license the compiler to build assumptions about the value into program being compiled.
  • 26. Control of time and executionThe eval-when special code allows pieces of code to be executed only at compile-time, only at load time, or when interrupted but not compiled.eval-when ({situation}*) {from}*The body of the eval-when form is processed as an implicit progn only if the situation is a symbol, either compile, eval or load.Eval specifies that the interpreter should process the body.Compile specifies that the compiler should evaluate the body at compile time.Load specifies that the compiler should arrange to evaluate the forms in the body when the compiled file containing the eval-when form is loaded.
  • 27. Procedure for processing a form:If the form is an eval-formif the situation load is specified:
  • 28. if the situation compile is specified, or if the current processing mode is compile-time-too and the situation eval is specified, the process each of the forms in the body in compile-time-too mode.
  • 29. else, process each of the forms in the body in not-compile-time mode
  • 30. if the situation load is not specified:
  • 31. if the situation compile is specified, or if the current processing mode is compile-time-too and the situation eval is specified, then evaluate each of the forms in the body in the compiler’s executing environment.
  • 32. else, ignore the eval-when form entirelyEx: the use of eval-when is that if the compiler is to be able to properly read a file that uses user defined reader macro characters , it is necessary to write(eval-when (compile load eval) (set-macro-character #\$ #’(lambda (stream char) (declare (ignore char)) (list ‘dollar (read stream))))) This causes the call to set-macro-character to be executed in the compiler’s execution environment, thereby modifying its readers syntax table.
  • 33. 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