[Q] using local variables in fn for binding?

From: Moises Lejter <mlm_at_cs.brown.edu>
Date: Fri, 24 Feb 1995 05:38:24 -0500

Hi!

I wanted to pop up a labeled entry field, so that it would do
validation of its input. This is what I wrote at first:

  (define (getTextItem fieldName valid?)
    (set! *entryText* nil)
    (catch '(destroy ".query"))
    (toplevel ".query")
    (frame ".query.frame")
    (pack ".query.frame" :side 'top :fill 'x)
    (label ".query.frame.label")
    (.query.frame.label 'config :text fieldName)
    (entry ".query.frame.entry" :relief 'sunken :borderwidth 1 :width 20
           :textvariable '*entryText*)
    (bind ".query.frame.entry" "<Return>"
          `(force ,(delay (if (valid? *entryText*) (destroy ".query")
               (display "Wrong input!\n")))))
    (pack ".query.frame.label" ".query.frame.entry" :side 'left)
    (tkwait 'visibility .query)
    (grab ".query")
    (tkwait 'window .query)
    *entryText*)

which I thought would do the right thing - it would eval the argument
to force in the environment of the call, thus using the value passed
in for #'valid? - delaying that expression. What would be stored as
the binding for <Return> would be the forcing of that delayed
expression. STk-2.1.5 complains, apparently because it cannot read
the string equiv to the delay construct.

An example in the doc suggests I should have done this, instead:

    (bind ".query.frame.entry" "<Return>"
          (address-of (lambda () (if (valid? *entryText*) (destroy ".query")
                                     (display "Wrong input!\n")))))

which works. But would it not be nicer to do it my way, rather than
using this #'address-of here? Does this not have to special-case
address-of lambda expressions in the evaluation of the strings used
for bindings (and, I imagine, commands as well)?

Am I missing something?

Thanks!

Moises

P.S> BTW, if there is a FAQ for STk, please let me know how to get
it... :-)

-----------------------------------------------------------------------------
Internet/CSnet: Moises_Lejter_at_brown.edu BITNET: mlm_at_browncs.BITNET
UUCP: ...!uunet!cs.brown.edu!mlm Phone: (401)863-7671
USmail: Moises Lejter, Box 1910 Brown University, Providence RI 02912
Received on Fri Feb 24 1995 - 11:40:02 CET

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