user3496846
user3496846

Reputation: 1655

Writing a macro that has a named symbol correctly

The problem with the following code is multiple evaluation:

(defmacro with-object (name &body body)
  `(let ((,name (create-object)))
     ,@body
     (free-object ,name)))

but I don't know how to do this the right way.

Upvotes: 1

Views: 53

Answers (1)

RowPJ
RowPJ

Reputation: 529

In order to use name in the let binding in your code, it has to hold a symbol. There should be no multiple evaluation problem in the code you supplied, since the symbol held by name is just given a binding in the expansion and evaluated for the free-object call within the context of that binding.

Upvotes: 2

Related Questions