Howdy Peter

I have to say, from the general style your code basically looks like
the code I would write.

Makes sense, since it's your code that I'm copying, hehe.

- what lisp are you using, SBCL has pi defined as a constant? 

I have both clisp 2.48 and sbcl 1.0.35 installed, and just discovered that clisp also has pi predefined.  I started with clisp because it was already included with slackware, and the logic of a slacker is:  if Pat thought it was good enough, then it must be.  However, I have since learned that sbcl compiles to machine code whereas clisp compiles to byte code, and even in the ltk package, clisp can't do the "serve-event" stuff.  My goal is to write code that does read-time conditionalization for clisp and sbcl, and to use clisp when working on non-profit projects and sbcl when working on commercial projects.

Thanks for this invaluable resource.  I've been trying out the different widgets, and just tried the notebook instance, and am using it  in my current endeavor of making a gui to help with the maintenance of my dns server (i'm tired of manually creating and editing zone files by hand)... hopefully everything will work and I won't be back here begging for deliverance from my confusion.

Thanks again,

--Everett

On Tue, Apr 13, 2010 at 1:43 PM, Peter Herth <herth@peter-herth.de> wrote:
Hi Everett,

I have to say, from the general style your code basically looks like
the code I would write.
Just a few comments, none of them ltk related:

- you set some variables, but never define them, rather use let*
- what lisp are you using, SBCL has pi defined as a constant?
- and the biggest one: DON'T use read on user input carelessly, try
for example entering #.(do-msg "huch!") instead of a number and press
calculate... read allows for evaluation of arbitrary lisp code.

Of course, the dialog layout could be different, but thats just fiddling a bit
with the options of pack...

So the code could look like:

(defun circularea ()
 (with-ltk (:debug-tcl nil)
   (wm-title *tk* "circularea")
   (let* ((label-d (make-instance 'label
                                  :text "A circle with a diameter of "))
          (entry-d (make-instance 'entry
                                  :text "0"))
          (label-u (make-instance 'label
                                  :text "units"))
          (label-a (make-instance 'label
                                  :text "has an area of "))
          (label-r (make-instance 'label
                                  :text "0"))
          (label-su (make-instance 'label
                                   :text "square units"))
          (b (make-instance 'button
                            :text "calculate"
                            :command
                            (lambda ()
                              (let* ((diameter (let ((*read-eval* nil))
                                                 (read-from-string
(text entry-d))))
                                     (radius (/ diameter 2))
                                     (area (* pi (* radius radius))))
                                (setf (text label-r) area))))))
     (pack label-d)
     (pack entry-d)
     (pack label-u)
     (pack label-a)
     (pack label-r)
     (pack label-su)
     (pack b) )))


Peter

_______________________________________________
ltk-user site list
ltk-user@common-lisp.net
http://common-lisp.net/mailman/listinfo/ltk-user