SlideShare a Scribd company logo
Macros in Lisp
CL macro facility allows the user to define arbitrary functions that convert certain lisp forms into different forms before evaluating or compiling them.Macros makes it possible to write codes that are clear and elegant.In CL, macros are not functionsIn particular, macros cannot be used as the functional arguments to functions such as apply, funcall, or map.
overviewMacro definitionMacro expansionDestructuringCompiler macrosEnvironments
Macro definitiondefmacro construct is used to define a macro.Macro-function determines whether the given function is the name of the macro.macro-function symbolThe argument must be a symbol, if the function has a global function definition( macro definition) then the expansion function is returned else nil is returned.Macro-function cannot work on local variables it can only determine the global definitions.Setf is used as a macro function to install a macro as a symbols global function definitionTo add an optional environment argument to macro-function:macro-function symbol &optional env(setf (macro-function symbol)  fn)
defmacro has the same syntax as the defunHere, name is the symbol whose macro definition we are creating.Lambda-list is similar in form to a lambda-list, Forms constitute the body of the expander function.The defmacro function returns the name.defmacro name lambda-list [[ {declaration}* | doc-string ]]  {form}* [Macro]
Defmacro lambda-list keywordsSome of the lambda-list key words are: &optional, &rest, &key, &allow-other-keys, &aux&body:  this is identical in function to &rest, it informs certain output-formatting and editing functions that the remainder of the form is treated as a body and should be intended accordingly.&whole: this is followed by a single variable that is bound to the entire macro-call form.&environment: this is followed by a single variable that is bound to an environment representing the lexical environment in which the macro call is to be interpreted.
Macro-expansionIf form is a macro call, then macroexpand-1 will expand the macro call once and return two values.( the expansion and t) if form is not macro call then two values ( form and nil) are returned.A form is said to be a macro call only if it is a cons whose car is a symbol that names a macro.The macro expansion function is used for expanding a macro call.
Macro-expansion steps followedOnce the macroexpand-1 has determined that a symbol names a macro, it obtains the expansion function for that macro.The value of the variable *macro-expand-hook* is then called as a function of three arguments: the expansion function, the form, and the environment env.The value returned from this call is taken to be the expansion of the macro call.The evaluator makes use of the macro calls as if through the use of macroexpand-1; eval also makes use of *macroexpand-hook*Macroexpand is similar to macroexpand-1, but repeatedly expands forms until it is no longer a macro call.
DestructingTo make the destructing feature of the defmacro available use:This macro binds the variables specified in lambda-list to the corresponding values in the tree structure resulting from evaluating the expression, then executes the forms as the an implicit progn.If the result of the evaluating expression does not match the destructuring pattern, an error should be signaled.Destructuring-bind lambda-list expression {declaration}* {form}[Macro]
Compiler macrosCompiler macros are used to transform the selective source code when the compiler is processing the code.This is similar to defmacro except the definition is not stored in the symbol function cell of name and is not seen by macroexpand-1The lambda-list may include &environment, &whole and may include destructuring.Return-form is used to exit from the function.define-compiler-macro name lambda-list                         {declaration | doc-string}* {form}*
Name must be a symbol, if it has been defined as a compiler macro, then the compiler-macro-function returns the macro expansion function, else returns nil.Expander function is obtained as if by a call to compiler-macro-function on the car of the form rather than by a call to macro-function.Two values are returned, the expansion and the value if expansion is true else nil.compiler macro function name &optional envcompiler-macroexpand from &optional  envcompiler-macroexpand-1 from &optional  env
Three cases when no expansion occurs:There is no compiler macro definition for the car of the form.There is such a definition but there is also a not inline declaration, either globally or in lexical environment env.A global compiler macro definition is shadowed by a local function or macro definition.
EnvironmentsThere is a minimal set of accessors and a constructor for environments.Define-declaration is used to define all the standard declaration specifiers, with the exception of special.The function returns the interpretation  of the symbol variable when it appears as a variable within the lexical environment env.Three values are returned:The first value indicates the type of definition in the env which may be :special, :lexical, :symbol-macro, :constantVariable-information variable &optional env
2. The second value is true if there is a local binding else it returns nil.3.  The third value is an a-list containing information about the declarations that apply to the apparent binding of the variable.Returns the information about the  interpretation of the function when it appears in the functional position of the lexical environment env.This function also returns three values:Type of definition or binding of the function name which is apparent in env (nil, :function, :macro, :special-form) The second value is true if the function is local else nil.The third value is an a-list containing information about declarations that apply to the apparent binding of the function.function-information function  &optional env
argument-environment env &key :variable  :symbol-macro :fuction :macro :declarereturns a new environment containing the information present in enc augmented with the information provided by the key word arguments.The arguments used are::variable list of symbols that will be visible as bound variable in the new environment,.
:symbol-macro  list of symbol macro definitions
:function  list of function-names that will be visible as local function bindings in the new environment.
:macro list of local macro definitions
:declare list of declaration specifiersdefine-declaration decl-name lambda-list {form}*The macro defines a macro for the named declaration.The function defined by this macro will be called with two augments, a declaration specifier whose car is decl-name and the env argument to augment-environment.
Ad

More Related Content

What's hot (20)

Assignment#01
Assignment#01Assignment#01
Assignment#01
Sunita Milind Dol
 
Oracle plsql and d2 k interview question1
Oracle plsql and d2 k interview question1Oracle plsql and d2 k interview question1
Oracle plsql and d2 k interview question1
Arunkumar Gurav
 
Oracle plsql and d2 k interview questions
Oracle plsql and d2 k interview questionsOracle plsql and d2 k interview questions
Oracle plsql and d2 k interview questions
Arunkumar Gurav
 
Class 10
Class 10Class 10
Class 10
SIVASHANKARIRAJAN
 
Functions
FunctionsFunctions
Functions
Septi Ratnasari
 
4. function
4. function4. function
4. function
Shankar Gangaju
 
BAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureBAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 Lecture
Wake Tech BAS
 
Programming style guideline very good
Programming style guideline very goodProgramming style guideline very good
Programming style guideline very good
Dang Hop
 
ELENA MICROPROCESSOR
ELENA MICROPROCESSORELENA MICROPROCESSOR
ELENA MICROPROCESSOR
ranjeetdon
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
venkatam
 
functions
functionsfunctions
functions
Itishree Soni
 
Complete list of all sap abap keywords
Complete list of all sap abap keywordsComplete list of all sap abap keywords
Complete list of all sap abap keywords
Prakash Thirumoorthy
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
Milind Patil
 
Ism normalization pine valley 2012
Ism normalization pine valley 2012Ism normalization pine valley 2012
Ism normalization pine valley 2012
Akshit R Shah
 
SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2
venkatam
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)
RajKumarSingh213
 
SQL / PL
SQL / PLSQL / PL
SQL / PL
srijanani2030
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
koolkampus
 
Modularisation techniques new
Modularisation techniques newModularisation techniques new
Modularisation techniques new
Jeet Thombare
 
Oracle plsql and d2 k interview question1
Oracle plsql and d2 k interview question1Oracle plsql and d2 k interview question1
Oracle plsql and d2 k interview question1
Arunkumar Gurav
 
Oracle plsql and d2 k interview questions
Oracle plsql and d2 k interview questionsOracle plsql and d2 k interview questions
Oracle plsql and d2 k interview questions
Arunkumar Gurav
 
BAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 LectureBAS 150 Lesson 8 Lecture
BAS 150 Lesson 8 Lecture
Wake Tech BAS
 
Programming style guideline very good
Programming style guideline very goodProgramming style guideline very good
Programming style guideline very good
Dang Hop
 
ELENA MICROPROCESSOR
ELENA MICROPROCESSORELENA MICROPROCESSOR
ELENA MICROPROCESSOR
ranjeetdon
 
SAS Macros part 3
SAS Macros part 3SAS Macros part 3
SAS Macros part 3
venkatam
 
Complete list of all sap abap keywords
Complete list of all sap abap keywordsComplete list of all sap abap keywords
Complete list of all sap abap keywords
Prakash Thirumoorthy
 
Lecture11 abap on line
Lecture11 abap on lineLecture11 abap on line
Lecture11 abap on line
Milind Patil
 
Ism normalization pine valley 2012
Ism normalization pine valley 2012Ism normalization pine valley 2012
Ism normalization pine valley 2012
Akshit R Shah
 
SAS Macros part 2
SAS Macros part 2SAS Macros part 2
SAS Macros part 2
venkatam
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)
RajKumarSingh213
 
6. Integrity and Security in DBMS
6. Integrity and Security in DBMS6. Integrity and Security in DBMS
6. Integrity and Security in DBMS
koolkampus
 
Modularisation techniques new
Modularisation techniques newModularisation techniques new
Modularisation techniques new
Jeet Thombare
 

Viewers also liked (9)

LISP:Declarations In Lisp
LISP:Declarations In LispLISP:Declarations In Lisp
LISP:Declarations In Lisp
LISP Content
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
LISP Content
 
LISP: Control Structures In Lisp
LISP: Control Structures In LispLISP: Control Structures In Lisp
LISP: Control Structures In Lisp
LISP Content
 
LISP: Loops In Lisp
LISP: Loops In LispLISP: Loops In Lisp
LISP: Loops In Lisp
LISP Content
 
LISP: Errors In Lisp
LISP: Errors In LispLISP: Errors In Lisp
LISP: Errors In Lisp
LISP Content
 
LISP: Object Sytstem Lisp
LISP: Object Sytstem LispLISP: Object Sytstem Lisp
LISP: Object Sytstem Lisp
LISP Content
 
Hipogonadizm
HipogonadizmHipogonadizm
Hipogonadizm
Perviz Haciyev
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
LISP Content
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
Yaser Jaradeh
 
LISP:Declarations In Lisp
LISP:Declarations In LispLISP:Declarations In Lisp
LISP:Declarations In Lisp
LISP Content
 
LISP: Input And Output
LISP: Input And OutputLISP: Input And Output
LISP: Input And Output
LISP Content
 
LISP: Control Structures In Lisp
LISP: Control Structures In LispLISP: Control Structures In Lisp
LISP: Control Structures In Lisp
LISP Content
 
LISP: Loops In Lisp
LISP: Loops In LispLISP: Loops In Lisp
LISP: Loops In Lisp
LISP Content
 
LISP: Errors In Lisp
LISP: Errors In LispLISP: Errors In Lisp
LISP: Errors In Lisp
LISP Content
 
LISP: Object Sytstem Lisp
LISP: Object Sytstem LispLISP: Object Sytstem Lisp
LISP: Object Sytstem Lisp
LISP Content
 
LISP: Introduction To Lisp
LISP: Introduction To LispLISP: Introduction To Lisp
LISP: Introduction To Lisp
LISP Content
 
Lisp Programming Languge
Lisp Programming LangugeLisp Programming Languge
Lisp Programming Languge
Yaser Jaradeh
 
Ad

Similar to LISP: Macros in lisp (20)

LISP: Program structure in lisp
LISP: Program structure in lispLISP: Program structure in lisp
LISP: Program structure in lisp
LISP Content
 
LISP:Program structure in lisp
LISP:Program structure in lispLISP:Program structure in lisp
LISP:Program structure in lisp
DataminingTools Inc
 
C language 3
C language 3C language 3
C language 3
Arafat Bin Reza
 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
Infinity Tech Solutions
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
acsmadurai
 
Module 5.pdf
Module 5.pdfModule 5.pdf
Module 5.pdf
SE14Darshan
 
programlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jgprogramlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jg
uleAmet
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
Functions
FunctionsFunctions
Functions
zeeshan841
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
Cpp functions
Cpp functionsCpp functions
Cpp functions
NabeelaNousheen
 
Function in C++
Function in C++Function in C++
Function in C++
Prof Ansari
 
functions notes.pdf python functions and opp
functions notes.pdf python functions and oppfunctions notes.pdf python functions and opp
functions notes.pdf python functions and opp
KirtiGarg71
 
Java script function
Java script functionJava script function
Java script function
suresh raj sharma
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
Krushal Kakadia
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobol
Srinimf-Slides
 
2-functions.pptx_20240619_085610_0000.pdf
2-functions.pptx_20240619_085610_0000.pdf2-functions.pptx_20240619_085610_0000.pdf
2-functions.pptx_20240619_085610_0000.pdf
amiyaratan18
 
LISP: Program structure in lisp
LISP: Program structure in lispLISP: Program structure in lisp
LISP: Program structure in lisp
LISP Content
 
Task Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdfTask Perform addition subtraction division and multiplic.pdf
Task Perform addition subtraction division and multiplic.pdf
acsmadurai
 
programlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jgprogramlama fonksiyonlar c++ hjhjghjv jg
programlama fonksiyonlar c++ hjhjghjv jg
uleAmet
 
Functions-Computer programming
Functions-Computer programmingFunctions-Computer programming
Functions-Computer programming
nmahi96
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
home
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
User defined function in C.pptx
User defined function in C.pptxUser defined function in C.pptx
User defined function in C.pptx
Rhishav Poudyal
 
functions notes.pdf python functions and opp
functions notes.pdf python functions and oppfunctions notes.pdf python functions and opp
functions notes.pdf python functions and opp
KirtiGarg71
 
Writing command macro in stratus cobol
Writing command macro in stratus cobolWriting command macro in stratus cobol
Writing command macro in stratus cobol
Srinimf-Slides
 
2-functions.pptx_20240619_085610_0000.pdf
2-functions.pptx_20240619_085610_0000.pdf2-functions.pptx_20240619_085610_0000.pdf
2-functions.pptx_20240619_085610_0000.pdf
amiyaratan18
 
Ad

Recently uploaded (20)

Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptxIn-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
aptyai
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Cybersecurity Tools and Technologies - Microsoft Certificate
Cybersecurity Tools and Technologies - Microsoft CertificateCybersecurity Tools and Technologies - Microsoft Certificate
Cybersecurity Tools and Technologies - Microsoft Certificate
VICTOR MAESTRE RAMIREZ
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
How Top Companies Benefit from Outsourcing
How Top Companies Benefit from OutsourcingHow Top Companies Benefit from Outsourcing
How Top Companies Benefit from Outsourcing
Nascenture
 
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdfGoogle DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
derrickjswork
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Vasileios Komianos
 
Master Data Management - Enterprise Application Integration
Master Data Management - Enterprise Application IntegrationMaster Data Management - Enterprise Application Integration
Master Data Management - Enterprise Application Integration
Sherif Rasmy
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025
Damco Salesforce Services
 
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Gary Arora
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptxIn-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
In-App Guidance_ Save Enterprises Millions in Training & IT Costs.pptx
aptyai
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Dark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanizationDark Dynamism: drones, dark factories and deurbanization
Dark Dynamism: drones, dark factories and deurbanization
Jakub Šimek
 
Cybersecurity Tools and Technologies - Microsoft Certificate
Cybersecurity Tools and Technologies - Microsoft CertificateCybersecurity Tools and Technologies - Microsoft Certificate
Cybersecurity Tools and Technologies - Microsoft Certificate
VICTOR MAESTRE RAMIREZ
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
How Top Companies Benefit from Outsourcing
How Top Companies Benefit from OutsourcingHow Top Companies Benefit from Outsourcing
How Top Companies Benefit from Outsourcing
Nascenture
 
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdfGoogle DeepMind’s New AI Coding Agent AlphaEvolve.pdf
Google DeepMind’s New AI Coding Agent AlphaEvolve.pdf
derrickjswork
 
React Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for SuccessReact Native for Business Solutions: Building Scalable Apps for Success
React Native for Business Solutions: Building Scalable Apps for Success
Amelia Swank
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Kit-Works Team Study_아직도 Dockefile.pdf_김성호
Wonjun Hwang
 
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Digital Technologies for Culture, Arts and Heritage: Insights from Interdisci...
Vasileios Komianos
 
Master Data Management - Enterprise Application Integration
Master Data Management - Enterprise Application IntegrationMaster Data Management - Enterprise Application Integration
Master Data Management - Enterprise Application Integration
Sherif Rasmy
 
Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025Top 5 Qualities to Look for in Salesforce Partners in 2025
Top 5 Qualities to Look for in Salesforce Partners in 2025
Damco Salesforce Services
 
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Harmonizing Multi-Agent Intelligence | Open Data Science Conference | Gary Ar...
Gary Arora
 
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
論文紹介:"InfLoRA: Interference-Free Low-Rank Adaptation for Continual Learning" ...
Toru Tamaki
 
fennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solutionfennec fox optimization algorithm for optimal solution
fennec fox optimization algorithm for optimal solution
shallal2
 

LISP: Macros in lisp

  • 2. CL macro facility allows the user to define arbitrary functions that convert certain lisp forms into different forms before evaluating or compiling them.Macros makes it possible to write codes that are clear and elegant.In CL, macros are not functionsIn particular, macros cannot be used as the functional arguments to functions such as apply, funcall, or map.
  • 4. Macro definitiondefmacro construct is used to define a macro.Macro-function determines whether the given function is the name of the macro.macro-function symbolThe argument must be a symbol, if the function has a global function definition( macro definition) then the expansion function is returned else nil is returned.Macro-function cannot work on local variables it can only determine the global definitions.Setf is used as a macro function to install a macro as a symbols global function definitionTo add an optional environment argument to macro-function:macro-function symbol &optional env(setf (macro-function symbol) fn)
  • 5. defmacro has the same syntax as the defunHere, name is the symbol whose macro definition we are creating.Lambda-list is similar in form to a lambda-list, Forms constitute the body of the expander function.The defmacro function returns the name.defmacro name lambda-list [[ {declaration}* | doc-string ]] {form}* [Macro]
  • 6. Defmacro lambda-list keywordsSome of the lambda-list key words are: &optional, &rest, &key, &allow-other-keys, &aux&body: this is identical in function to &rest, it informs certain output-formatting and editing functions that the remainder of the form is treated as a body and should be intended accordingly.&whole: this is followed by a single variable that is bound to the entire macro-call form.&environment: this is followed by a single variable that is bound to an environment representing the lexical environment in which the macro call is to be interpreted.
  • 7. Macro-expansionIf form is a macro call, then macroexpand-1 will expand the macro call once and return two values.( the expansion and t) if form is not macro call then two values ( form and nil) are returned.A form is said to be a macro call only if it is a cons whose car is a symbol that names a macro.The macro expansion function is used for expanding a macro call.
  • 8. Macro-expansion steps followedOnce the macroexpand-1 has determined that a symbol names a macro, it obtains the expansion function for that macro.The value of the variable *macro-expand-hook* is then called as a function of three arguments: the expansion function, the form, and the environment env.The value returned from this call is taken to be the expansion of the macro call.The evaluator makes use of the macro calls as if through the use of macroexpand-1; eval also makes use of *macroexpand-hook*Macroexpand is similar to macroexpand-1, but repeatedly expands forms until it is no longer a macro call.
  • 9. DestructingTo make the destructing feature of the defmacro available use:This macro binds the variables specified in lambda-list to the corresponding values in the tree structure resulting from evaluating the expression, then executes the forms as the an implicit progn.If the result of the evaluating expression does not match the destructuring pattern, an error should be signaled.Destructuring-bind lambda-list expression {declaration}* {form}[Macro]
  • 10. Compiler macrosCompiler macros are used to transform the selective source code when the compiler is processing the code.This is similar to defmacro except the definition is not stored in the symbol function cell of name and is not seen by macroexpand-1The lambda-list may include &environment, &whole and may include destructuring.Return-form is used to exit from the function.define-compiler-macro name lambda-list {declaration | doc-string}* {form}*
  • 11. Name must be a symbol, if it has been defined as a compiler macro, then the compiler-macro-function returns the macro expansion function, else returns nil.Expander function is obtained as if by a call to compiler-macro-function on the car of the form rather than by a call to macro-function.Two values are returned, the expansion and the value if expansion is true else nil.compiler macro function name &optional envcompiler-macroexpand from &optional envcompiler-macroexpand-1 from &optional env
  • 12. Three cases when no expansion occurs:There is no compiler macro definition for the car of the form.There is such a definition but there is also a not inline declaration, either globally or in lexical environment env.A global compiler macro definition is shadowed by a local function or macro definition.
  • 13. EnvironmentsThere is a minimal set of accessors and a constructor for environments.Define-declaration is used to define all the standard declaration specifiers, with the exception of special.The function returns the interpretation of the symbol variable when it appears as a variable within the lexical environment env.Three values are returned:The first value indicates the type of definition in the env which may be :special, :lexical, :symbol-macro, :constantVariable-information variable &optional env
  • 14. 2. The second value is true if there is a local binding else it returns nil.3. The third value is an a-list containing information about the declarations that apply to the apparent binding of the variable.Returns the information about the interpretation of the function when it appears in the functional position of the lexical environment env.This function also returns three values:Type of definition or binding of the function name which is apparent in env (nil, :function, :macro, :special-form) The second value is true if the function is local else nil.The third value is an a-list containing information about declarations that apply to the apparent binding of the function.function-information function &optional env
  • 15. argument-environment env &key :variable :symbol-macro :fuction :macro :declarereturns a new environment containing the information present in enc augmented with the information provided by the key word arguments.The arguments used are::variable list of symbols that will be visible as bound variable in the new environment,.
  • 16. :symbol-macro  list of symbol macro definitions
  • 17. :function  list of function-names that will be visible as local function bindings in the new environment.
  • 18. :macro list of local macro definitions
  • 19. :declare list of declaration specifiersdefine-declaration decl-name lambda-list {form}*The macro defines a macro for the named declaration.The function defined by this macro will be called with two augments, a declaration specifier whose car is decl-name and the env argument to augment-environment.
  • 20. The function must return two values: the first value must be one of the following keywords :variable, :function, :declare
  • 21. If the first value is :variable or :function, then the second value must be a list, the elements of which are of the form (binding-name key value)
  • 22. If the first value is :declare, the second value must be a cons of the form ( key. Value)parse-macro name lambda-list body &optional envThe function is used to process a macro definition, it returns a lambda-expression that accepts two argument, a form and an environment.The function returns an object of type function that is equivalent to what would be obtained by evaluating ‘(function, lambda-expression) in a syntactic environment env.
  • 23. 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
  翻译: