chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] handle "unbound variable" exception for undefined pr


From: Shawn Rutledge
Subject: Re: [Chicken-users] handle "unbound variable" exception for undefined procedures?
Date: Thu, 8 Jan 2009 11:17:27 -0700

On Thu, Jan 8, 2009 at 2:56 AM, felix winkelmann <address@hidden> wrote:
> ##sys#unbound-in-eval is only for error-reporting - it
> records unbound variable while preparing s-expression
> for interpretation, so it has no direct relation to the unbound-variable-value
> thing.

I understand, but as it turns out, it's basically the same question as
this old one (which I found when I tried googling):

On Sat, Jan 28, 2006 at 2:43 PM, Arto Bendiken <address@hidden> wrote:
> Hi,
>
> Since it seems possible to set the value of
> `##sys#unbound-variable-value-hook' to a procedure, I was trying to do
> the following:
>
> ;;; dynamic c*****r handler
> (unbound-variable-value
>  (lambda (list)
>    ; how to find out the symbol by which we ended up here?
>    ...))
>
> (cadadar a-list-of-lists)
>
> I found a similar question in the mailing list archives, relating to
> an attempt to use `invalid-procedure-call-handler' for this purpose,
> followed by a suggestion by Felix to use `unbound-variable-value'
> instead:
> http://lists.gnu.org/archive/html/chicken-users/2005-03/msg00044.html
>
> However, presumably there must be some way for the hook procedure to
> decide whether to perform, say, a `cadadar' operation instead of a
> `cadddar', but I haven't managed to figure it out. I looked at the
> variables beginning with ##sys... to see if there was some global I
> could peruse in the handler, and skimmed through the relevant portions
> of runtime.c for Chicken 2.2, but no luck so far.
>
> Suggestions, or a "no, not possible", appreciated :-)


On Sun, Jan 29, 2006 at 10:11 PM, felix winkelmann <address@hidden> wrote:
> Unfortunately this is currently not possible. I could
> come up with a C-based solution, but the retrieval (and check)
> of a toplevel variable is not done in a context that allows
> calling a user-supplied Scheme procedure.
> That said, with some minor modifications it is possible to
> code this in C, but callbacks into Scheme are not possible,
> so it's use may be somewhat awkward.


I still think this would be a really cool feature to have.  It seems
natural in such a dynamic language, that when catching an unbound
symbol, one should be able to figure out what it ought to have been
bound to, bind it and continue as if nothing happened.

But in the meantime I'll have to try to architect my code so I can
avoid having to ask that question "is this unbound variable actually a
generic function which is bound to an applicable method on the
connected client?"  In the context in which it comes up, so far the
solution is to just pre-define those methods.

At least, I can handle setting variables on proxy objects
transparently.  I have been using => as shorthand for slot-set! (this
idea came from MODDS) and so I just defined => as a generic function,
so if the object is a proxy it sends an equivalent (=> ...) expression
across the link, and if the object is a local one it calls slot-set!
I just wish I could do the same thing for any kind of method, but I
can do it if I pre-define each method that can apply to a proxy
object.  (And there is still the question of whether using proxy
objects is a good idea at all.)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]