Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can go wrong when I define a macro and just use a rare enough name for a temporary variable?

Tags:

scope

macros

lisp

Let Over Lambda Chapter 3 Section 'Unwanted Capture' says:

"Surely we can think of rare enough names so that the problem never shows up. Yes, in many cases, packages and smart variable naming can solve the problem of variable capture. However, most serious variable capture bugs don't arise in code directly created by a programmer. Most variable capture problems only surface when other macros use your macro (combine with your macro) in ways you didn't anticipate."

and then it doesn't give me an example for the bold part. What would be one of such examples? Imagine a hypothetical Lisp dev team where its mad boss banned the use of gensym or anything that creates uninterned symbols and the programmers simply resort to throwing alphanumeric dice to come up with random variable names like temp-27s63f8sk2n or sum-3t84hj4df whenever they miss gensym. What would be an example where the team will get in trouble?

Speaking of which, Emacs 24.3.1 defines dotimes and dolist without using uninterned symbols. Weird.

like image 441
Le Curious Avatar asked Jul 02 '13 22:07

Le Curious


1 Answers

OK, then I'd propose automating that process of "throwing alphanumeric dice". Of course, it doesn't have to be random, you could just use a counter. Additionally, it would be nice to be able to specify a prefix, for debugging. Oh wait, that is exactly what gensym does.

like image 113
Svante Avatar answered Nov 05 '22 04:11

Svante