ABSTRACT

This chapter discusses implementing an object-oriented design pattern and macros. State pattern is a design pattern that is used in object-oriented programming. The pattern's crux is that a value has an internal state represented by a set of state objects, and the value's behavior changes depending on the internal state. Metaprogramming is a useful programming tool for reducing the amount of code that must be written and maintained, which is also one of the roles of functions. On the other hand, Macros have some additional capabilities that functions do not. Procedural macros, which behave more like functions, are the second type of macro (and are a type of procedure). Procedural macros accept some code as input, operate on that code, and produce some code as output, as opposed to declarative macros, which match against patterns and replace the code with other code.