Hello,
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. * 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? * 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...? * 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.)
Any pointers will be appreciated and I'll add the information to the wiki afterward (suggesting where to put it will also be appreciated).
You can also reply on #abcl, my nick there is DrDub.
Gracias!
P.
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
On Tue, Apr 12, 2011 at 3:17 PM, Alessio Stalla alessiostalla@gmail.com wrote:
- 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.
I forgot to mention that if you look into the ABCL sources for markSpecialBindings, you'll find how it is typically used, since the implementation itself relies on that method and its friends.
Cheers, Ale
Ciao Alessio!
I'll give your suggestions a try, thanks so much for your reply.
I forgot to mention that last week, Erik got me set-up with Wiki write privileges.
My interest is to get FUF/SURGE[1] running well under ABCL. It is a text generation component, which does some heave symbolic computation (unification of feature descriptions).
Besides the problem I mailed about, I am bumping into issues with ABCL (current) lack of tail recursion elimination. We discussed about it a little bit on #abcl, I'll send some e-mail on this topic once I get a better feeling for the code.
Thanks!
P.
armedbear-devel@common-lisp.net