libera/#commonlisp - IRC Chatlog
Search
21:41:55
phantomics
Hey, another question. When a local binding is created for a dynamic variable, functions defined even outside the scope of that local binding will use the local binding, correct?
21:42:15
phantomics
(defvar foo 13) (defun set-foo (arg) (setf foo arg)) (let ((foo 3)) (set-foo 50) (+ foo 10)) foo
21:42:43
phantomics
The (set-foo) inside the (let) form doesn't actually change the top-level value of foo, even though the function is defined outside
21:47:02
pjb
lotuseater: the only advice I have for Bjarne, unfortunately, is to ask to be interned in a lunatic asylum.
21:48:01
pjb
phantomics: you don't have _local_ bindings for _dynamic_ variables. It's like asking what taste is the color blue? it's meaningless.
21:48:26
phantomics
I know that the dynamic vars have a value stack and a value gets pushed onto the stack within that (let) scope
21:49:43
pjb
phantomics: the set-foo mutates the binding of the dynamic variable foo that is active WHEN the function set-foo is called.
21:50:13
pjb
phantomics: in set-foo, there is absolutely no consideration for WHERE the variable foo is bound. Only WHEN it is bound.
21:51:28
pjb
Note: you can define global lexical variables using symbol macros. Search for a defglobal or deflex in libraries.
21:51:37
phantomics
The workaround, as far as the April compiler is concerned, is to prefix the internal representations of all lexical variables with something
21:53:56
phantomics
And then if they write a function like {foo←5 ⋄ foo+⍵}, a lexical variable called something like "𝕏foo" that shadows the value of the external "foo" is instantiated in a (let) form
21:54:08
pjb
So you're implementing lexical variables with dynamic variable when you have a language that already has lexical variable? Why? Are you masochist?
21:55:07
phantomics
It creates implicit shadowed lexical variables when you assign a value to something inside a function
21:55:47
pjb
Ok, so you have toplevel variables that are dynamic and local variables that are lexical, and the local lexical variable can shadow the the toplevel dynamic variable?
21:56:04
pjb
In that case, indeed, you need some kind of renaming or use a different namespace (package).
21:56:57
phantomics
The tricky part is that APL has a type of function that can reassign the global variable outside of a function's scope
21:57:35
phantomics
But given a lexical variable's name, I need to be able to find if it is shadowing a dynamic variable
21:58:44
pjb
(mapcar (lambda (lexical-apl-variable) (cons lexical-apl-variable (gensym))) lexical-apl-variables) to build an a-list mapping the lexical-apl-variables to lexical-lisp-variables.
21:58:48
phantomics
If I rename them to gensyms how do I find their corresponding external dynamic var symbol? Enter it all in a hash table? The prefix system is simpler, and double-struck letters are illegal in April var name so there's no chance of collision
21:59:19
pjb
You find that before, by looking up the apl-variable in a global-dynamic-apl-variables list.
22:00:18
phantomics
That seems cumbersome when I could just remove the lexical var prefix and look for the existence of a dynamic var by that name
22:01:43
phantomics
April is designed to produce relatively readable compiled code for the purpose of debugging
22:02:45
phantomics
APL converted into Lisp designed for readability, I've built a lot of stuff including some reader macros just to make the output more readable
22:03:06
pjb
note: lexical variables are not accessible from "outside" the function, while global variables are accessible from anywhere.
22:03:44
pjb
therefore I would use a package such as "APL-VARIABLES" to intern the names of the global dynamic variables, and another package "APL-INTERNALS" to intern the name of the lexical variables.
22:03:48
phantomics
The concept of "global lexical variables" is interesting though, I may check into those tools you mentioned in case they're useful
22:04:36
pjb
Well, you'd have APL-VARIABLES:FOO and APL-INTERNALS::FOO. You wouldn't have to export symbols from APL-INTERNALS.
22:04:51
phantomics
April already supports multiple workspaces, each of which is implemented as a package, so that means I would have to have two of those packages for each workspace
22:06:09
pjb
having APL code generate packages with exported symbols only for the "public" stuff and other packages for the internals would be clean.
22:06:31
phantomics
April is intended to be highly interactive with Lisp; each workspace is a package, all variables you create can be accessed from the Lisp instance.
22:06:58
phantomics
If all the lexical vars are interned in a "sub-package" that could be fairly clean, no one would need to do much with the lexical package
22:42:17
char
Is there any good forward+reverse proxy for common lisp? I couldn't find how to forward http tcp sockets with hunchentoot
4:29:27
kakuhen
pjb: regarding the macro from yesterday, it seems that restart-case does not place forms on the top level, and the cl spec only guarantees types exist when you defclass on the top level; it seems you can have implementation-specific behavior when you defclass below the top level
7:30:25
pjb
kakuhen: note that restart case in foo could have only been invoked by the compiler, since it wraps only defclass and defmethod.