Macros in LISP Last Updated : 18 Nov, 2021 Comments Improve Suggest changes Like Article Like Report Macro is similar to a function in popular languages like C++, java, etc. that takes arguments and returns a LISP form to be evaluated. It is useful when the same code has to be executed with a few variable changes.For example, rather than writing the same code for squaring a number, we can define a macro that holds the code for squaring. Defining a Macro: To define a named macro in LISP, a default macro - defmacro is used.Syntax: (defmacro macroName (parameters) expressions ) Where, macroName: It is the identifier of the macro, wherever it is used the macro expressions will be executedparameters: Parameters that can be passed whenever calling a macroexpressions: Statements executed wherever the macro is used.Example Lisp (defmacro sayHello () ; This statement will be executed whenever ; we use the macro sayHello (write-line "Hello everyone") ) ; Using macro sayHello (sayHello) (write-line "GfG") (sayHello) (terpri) (defmacro greet (name) ; This statement will be executed whenever ; we use the macro greet ; substituting name with the parameter value (format t "Welcome ~S ~%" name) ) ; Calling macro square with parameter strings (greet "GfG audience") (greet "Awesome people") (terpri) (defmacro sumup (a b) ; This line will be executed whenever ; we use the macro sum ; with two integer parameters (format t "~D + ~D : ~D" a b (+ a b)) ) ; Calling macro sumup with parameters 7 and 18 (sumup 7 18) (terpri) (defmacro square (num) ; This line will be executed ; whenever we use the macro square ; with the parameter name (format t "Square of ~D is ~D " num (* num num)) ) ; Calling macro square with parameter 5 (square 5) (terpri) Output: Hello everyone GfG Hello everyone Welcome "GfG audience" Welcome "Awesome people" 7 + 18 : 25 Square of 5 is 25 Comment More infoAdvertise with us Next Article Macros in LISP O omkarphansopkar Follow Improve Article Tags : LISP LISP-Basics Similar Reads Numbers in LISP LISP is a list processing programming language. It is widely used in the manipulation of data strings. It provides an input and output library. LISP provides a macro system and provides well control structures for the manipulation of data. LISP Math Function:floor:Â floor returns the nearest smalles 2 min read Vectors in LISP In this article, we will discuss Vectors in LISP. Vectors in LISP are one-dimensional arrays which are also known as sequences. We can create a vector using vector function and # symbol Syntax: variable_name(vector element1 element2 ... element n) or variable_name #(element1 element2 ... element n) 2 min read Symbols in LISP Symbols are lisp data objects and every type of symbol object has a name called its print name. Symbol names may contain any combination of letters and numbers, plus some special characters such as hyphens. A symbol can contain any alphabetic, numeric, or any characters except delimiter characters l 4 min read Loops in LISP Loops allow executing a set of instructions repeatedly while some condition is true. LISP provides the following types of loops: 1. dotimes loop: The dotimes loop allows executing instructions for a fixed number of times.Syntax:Â (dotimes( variableName numberOfIterations ) ( expressions )) Where, va 4 min read Macros In C++ C++ is a powerful and versatile programming language that offers many features to enhance code flexibility and maintainability. One such feature is macros, which are preprocessor directives used for code generation and substitution. Macros are an essential part of C++ programming and play a crucial 8 min read Like