Re: Building STk on HP-UX

From: <>
Date: Tue, 14 Feb 95 10:10:07 +0100

> I'm trying to build an application using STk and I ran into an unexpected
> (though documented) problem.
> Basically, the code bound to, say, a button widget that is to be executed when
> the button is pressed, is evaluated in the global environment.
> I want to be able to control the environment in which it is evaluated; I'd
> like to be able to do, for instance
> (let* ((foo 1)
> (bar 2))
> (button "Frob" :command (lambda ()
> (frob foo bar))))
> When I try it I get
> *** Read from string error:
> bad # syntax: "#"
> because STk cannot deal with the "#[closure 0xfdo92c]" it gets back from Tk.
> My question is, how hard would it be to support closures as widget actions?
> If it's a GC problem (in that the lambda might get collected before it's
> called, because Tk doesn't cooperate in GC) then why can't a thin layer of
> glue code notice that this closure is being bound to that button, and hold
> onto a live pointer so it won't be collected? It seems to me (though I
> haven't dived into the code to see) that it would not be hard for the
> interpreter evaluating the "string" of code from Tk to notice that it starts
> "#[closure..." and do the right magic closure-invoking stuff. Yes? No?
> Or perhaps the problem is more subtle (or more obvious) than I can see.
> --berry
> Berry Kercheval ::

I think, your facing two problems here:
local environment && lambda call-backs.
I only have an answer for the second part : (from the FAQ ;-)


Subject : [3.3] Using lambda as call-backs

Using something like

   (.scrollbar 'configure :command '(lambda (pos) (display pos)))

won't work. This is due to the way Tk and STk communicate. For the
time being the call-back command are stored in strings. When Tk calls
the call-back, the string is sent to STk, if the string doesn't start
with a bracket it is bracketed first. Thus

    :command "callback" is called by (callback args)
    :command '(lambda (pos) ...) is called by (lambda ...) args
      which is obviously false.
    :command "apply (lambda ....)" is called by (apply (lambda..) args)
      which the only current working alternative.

Eventually, this problem will be solved in future release.

Received on Tue Feb 14 1995 - 10:12:13 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST