libera/#lisp - IRC Chatlog
Search
22:19:02
edgar-rft
lexical variables are removed by the compiler whenever possible, so it makes very little sense to have lexical global variables
22:21:14
muurkha
in C, Scheme, Python, etc., I can define a global variable called "word" and use it inside a subroutine, without worrying about whether that subroutine's caller might also have a local variable called "word" used for something totally different
23:24:52
moon-child
muurkha: the convention is to define specials with *earmuffs*, so you should not accidentally stomp on one
23:26:30
moon-child
muurkha: there is this hack: (let ((global-holder (list init-value))) (define-symbol-macro -the-global- `(car ',global-holder)))
23:27:36
moon-child
errr apparently symbol-macro expansion is not evaluated. So either eval the d-s-m form, or something like (defconstant +global-holder+ ...) (define-symbol-macro -the-global- (car +global-holder+))
23:31:33
muurkha
it's useful to evaluate the form (gensym) every time it occurs, even though it doesn't take any parameters, so why not other things?
23:39:49
muurkha
if you follow that sense of it being a bad idea very far, you end up at syntax-rules or syntax-case.
23:41:02
muurkha
hacking pointers to shared anonymous variables into your source code is not the only possible use for such a thing ;)
23:43:59
muurkha
your example above is an interesting one, but others might include expanding to something that depends on which package is being compiled (assuming your compiler has some way to find out), looking at the compilation environment to see whether you're inside of some kind of problematic context, implicitly capturing a lexically enclosing transaction context, and so on
23:44:54
muurkha
in Python (the CWI one) there's a super() whose semantics depend on which class it's being compiled lexically inside of
23:46:14
muurkha
as it happens in that particular case it does take (optional) parameters, so an ordinary macro would work fine
23:47:21
muurkha
basically it comes down to defining "variables" that extend the language semantics in some nontrivial way
4:24:43
moon-child
<moon-child> muurkha: there is this hack: (let ((global-holder (list init-value))) (define-symbol-macro -the-global- `(car ',global-holder)))