Thank you for your reply.
The compiler generally will not execute the LET and then compile the WITH-FREE-PORTS form with the new binding
Here is an example when the compiler does exactly that:
(defmacro with-free-ports (start end &body body)
`(list ,start ,end ,@body))
(let ((start 1)
(end 3))
(with-free-ports start end NIL))
So, why does it work?
Thanks a lot!
Yes, but I do not know how many of them. The purpose of this macro is to create a lexical environment to test a network code. Some functions take just one port as a parameter, but the others - two and more. With this macro it would be very easy to call these functions and to link their IO through the port numbers:
(with-free-ports 0 10 (fn-1 port-1 port-2 port-3) (fn-2 port-1))
And with the first posted version of
with-free-ports
I achieved it. The problems appeared when I tried to bindstart
in run-time. From your reply and from the u/lispm comments I understood that this is not a good idea. What I do not understand, is how to use such macros inside another macros/functions, which can supplywith-free-ports
withstart
andend
parameters ? Also, I cannot figure out, when exactly macro-expansions take place if I use many enclosed macros. Are they expanded all at once when I compile my code?Anyway, I am very grateful for your suggestions. This helps a lot to learn CL.