On Tue, Apr 12, 2011 at 2:48 PM, Pablo Duboue pablo.duboue@gmail.com wrote:
Hello,
Hello, and welcome to the list!
How can I issue a Function.execute so that it executes in the context of a given package?
That is, I have an instance of the Function class, obtained from a .getSymbolFunction() call on a findAccessibleSymbol over a Package instance, per the examples in the source tree. This function call executes fine, but it runs on package "CL". I need it to run on package, say, "FOO".
I have tried a number of things, to no avail:
- Issuing an interpreter.evaluate("(in-package "FOO")") beforehand.
That seemed very reasonable, but doesn't work. Looking into the code, it seems related to packages being special bindings and said bindings being reset between calls to evaluate.
This doesn't sound right, as IN-PACKAGE sets the value of *PACKAGE*, it doesn't rebind it. So if you eval (in-package "FOO") and execute your function in the same thread, you should see the correct package. How do you determine that the function is really running with *PACKAGE* bound to the CL package? Try putting a (print *package*) form at the beginning of the function, for example.
- Fiddling with the thread.markSpecialBindings calls which seem to
reset in-package bindings in Lisp, Interpreter and Function. I haven't had much success there, am I on the right track at all?
That's the right track, as evaluating an in-package form is not thread-safe in general.
- Trying to use other calls instead of function.execute, which include
an environment and a thread, that was very cumbersome (and didn't work either). Might this work at all...?
Not sure, I'd have to check. The environment surely is ininfluential as it's the lexical environment, so it only makes sense when EVALuating expressions, not when you're directly calling a function.
- Using the JSR-223 interface. That did work, but as I'm planning to
put this in a Web service, I don't want any interpreter on the way (for security reasons). By the way, the JSR-223 page is the only instance of "in-package" in the whole wiki. (The mailing list search function for 'in-package' split it as two words and return half the mailing list as output.)
The JSR-223 API is not a separate interpreter, it does more or less the same things you'd have to do by hand, it just presents them under a different API. It is (imho) a little bit nicer to use because it handles conversions to-from LispObject for you. On the other hand, it's just a little subset of what you can do with the native ABCL API.
Any pointers will be appreciated and I'll add the information to the wiki afterward (suggesting where to put it will also be appreciated).
That would be really nice! I don't know if non-committers have write access to the wiki, I suspect not; if that is the case, feel free to post your contribution to me and I'll publish it on the wiki (giving proper credit, of course).
You can also reply on #abcl, my nick there is DrDub.
Gracias!
P.
Bye, Alessio