λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°

University of California, Berkeley/ElectricalEngineering & ComputerSciences

Macros

Macros

- Macros are a more convenient way to transform or create expressions

- The define-macro special form will create a macro procedure

- Macros take in and return expressions, which are then evaluated in place of the call to the macro

Evaluating Macros

Recall evaluation procedure used for regular call expressions:

 1. Evaluate the operator sub-expression, which evaluates to a regular procedure.

 2. Evaluate the operand expressions in order.

 3. Apply the procedure to the evaluated operands.

Macros, on the other hand, do the following:

 1. Evaluate the operator sub-expression, which evaluates to a macro procedure.

 2. Apply the macro procedure to the operand expressions without evaluating them first.

 3. Evaluate the expression returned by the macro procedure in the frame the macro was called in

Writing Macros

Because macros take in and return expressions, when writing macros you should think about:

1. What types of expressions you’ll take in

2. What expression has equivalent behavior to your macro

Consider a macro add-to which should take in a symbol and an expression, and increment the value of the variable by the expression.

Quasi - Quotation

Quasi - quoting

-   Quasiquotation allows you to have some parts of a list be read literally and some parts be evaluated.

-   It's especially useful for constructing code in macros.

 

'University of California, Berkeley > ElectricalEngineering & ComputerSciences' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

Streams  (0) 2019.08.06
Week 7  (0) 2019.08.06
Interpreters lab  (0) 2019.08.01
Interpreters  (0) 2019.08.01
More Scheme  (0) 2019.07.31