From: Harag
Subject: lisp2wish extension?
Date: 
Message-ID: <bs1qn1$7oc$1@ctb-nnrp2.saix.net>
I have been playing with lisp2wish and wnat to make it easier to work with I
have thought of wrapping TK widgets in lisp functions to do that like this:

;;; The parent-name is appended to the name of the widget to emulate the
;;; style for widget naming used in ActiveTCL's demos.
;;; The options used 'most' for the widget is pared with &keys to make their
use
;;; simple.
(defun tk_button (parent-name name &rest args &key (text "") (image "")
height width state command options)
  "Converts a its args into a string representinf a TK_button defenition."
  (format nil "button $~A.~A ~A" parent-name name (args-to-tk args)))

;;;Helper functions
(defun args-to-tk (args)
  (let ((tk "")
 (end nil))
    (mapc #'(lambda (arg)
       (if (equal arg :options)
    (setf end T)
    (if end
        (setf tk (format nil "~A ~A" tk arg))
        (if (stringp arg)
     (setf tk (format nil "~A \"~A\"" tk arg))
     (setf tk (format nil "~A -~A" tk (string arg)))))))
   args)
    tk))


Results in the following:

20. Break [3]> (tk_button "w" "button" :text "help" :height "100" :options
"- state \"normal\"")
"$w.button  -TEXT \"help\" -HEIGHT \"100\" - state \"normal\""


Is this the best way to wrap the TK widgets without going to objects?

Any suggestions would be welcome.


Harag

From: Harag
Subject: Re: lisp2wish extension?
Date: 
Message-ID: <bs1qul$7r1$1@ctb-nnrp2.saix.net>
I pasted the wrong results. The following would be more usefull

20. Break [3]> (tk_button "w" "button" :text "help" :height "100" :options
"- state \"normal\"")
"button $w.button  -TEXT \"help\" -HEIGHT \"100\" - state \"normal\""
From: Henrik Motakef
Subject: Re: lisp2wish extension?
Date: 
Message-ID: <x7k74ra0kx.fsf@henrik-motakef.de>
"Harag" <·········@psychedelic.co.za> writes:

> (defun tk_button (parent-name name &rest args &key (text "") (image "")
> height width state command options)
>   "Converts a its args into a string representinf a TK_button defenition."
>   (format nil "button $~A.~A ~A" parent-name name (args-to-tk args)))
> 
> ;;;Helper functions
> (defun args-to-tk (args)
>   (let ((tk "")
>  (end nil))
>     (mapc #'(lambda (arg)
>        (if (equal arg :options)
>     (setf end T)
>     (if end
>         (setf tk (format nil "~A ~A" tk arg))
>         (if (stringp arg)
>      (setf tk (format nil "~A \"~A\"" tk arg))
>      (setf tk (format nil "~A -~A" tk (string arg)))))))
>    args)
>     tk))

Some quick comments:

- Using both &rest and &key is not often a good idea. (Peter Seibel's
  book-in-progress has a section on that topic, see
  <http://www.gigamonkeys.com/book/functions.html>). On the other
  hand, declaring keyword args in the lambda list and not using a
  single one of them ever is unusual as well...

- If I understand correctly, your code depends on :options always
  being the last keyword arg given. This will confuse people - the
  very reason for keyword args is that they are /not/ position
  dependent, after all.

- In args-to-tk, your way to build the result string is not quite
  elegant. You might want to use a string-output-stream, as in
  (special-casing :options ommitted):

  (defun args-to-tk (args)
    (with-output-to-string (stream)
      (dolist (arg args)
        (typecase arg
          (string (format stream " ~S" arg))
          (t (format stream " -~A" (string arg)))))))

- Generally, I'd prefer a more heavy wrapper, probably something
  CLOS-based, with a tk:button class or something. This is probably
  more work, though.

- Your indentation style could be improved, but that might be a
  cut-and-paste problem :-)
From: Peter Seibel
Subject: Re: lisp2wish extension?
Date: 
Message-ID: <m3ptej6yrx.fsf@javamonkey.com>
Henrik Motakef <············@henrik-motakef.de> writes:

> "Harag" <·········@psychedelic.co.za> writes:
> 
> > (defun tk_button (parent-name name &rest args &key (text "") (image "")
> > height width state command options)
> >   "Converts a its args into a string representinf a TK_button defenition."
> >   (format nil "button $~A.~A ~A" parent-name name (args-to-tk args)))
> > 
> > ;;;Helper functions
> > (defun args-to-tk (args)
> >   (let ((tk "")
> >  (end nil))
> >     (mapc #'(lambda (arg)
> >        (if (equal arg :options)
> >     (setf end T)
> >     (if end
> >         (setf tk (format nil "~A ~A" tk arg))
> >         (if (stringp arg)
> >      (setf tk (format nil "~A \"~A\"" tk arg))
> >      (setf tk (format nil "~A -~A" tk (string arg)))))))
> >    args)
> >     tk))
> 
> Some quick comments:
> 
> - Using both &rest and &key is not often a good idea. (Peter
> Seibel's book-in-progress has a section on that topic, see
> <http://www.gigamonkeys.com/book/functions.html>). On the other
> hand, declaring keyword args in the lambda list and not using a
> single one of them ever is unusual as well...

Hmmm. I think I warned against combining &optional and &key. Combining
&rest and &key can be done though you do need to understand how they
interact.

-Peter

-- 
Peter Seibel                                      ·····@javamonkey.com

         Lisp is the red pill. -- John Fraser, comp.lang.lisp
From: Harag
Subject: Re: lisp2wish extension?
Date: 
Message-ID: <bs26i9$dpc$1@ctb-nnrp2.saix.net>
"Henrik Motakef" <············@henrik-motakef.de> wrote in message
···················@henrik-motakef.de...
...
> Some quick comments:
>
> - Using both &rest and &key is not often a good idea. (Peter Seibel's
>   book-in-progress has a section on that topic, see
>   <http://www.gigamonkeys.com/book/functions.html>). On the other
>   hand, declaring keyword args in the lambda list and not using a
>   single one of them ever is unusual as well...
>

The &rest &key word combination was suggested as a way to get at the args as
a list making it easy for the caller to 'use' and it makes it easy for me to
iterate. Some how passing a list does not seem to be the answer either, &key
pairs just make this kind of function more readable dont you think?

> - If I understand correctly, your code depends on :options always
>   being the last keyword arg given. This will confuse people - the
>   very reason for keyword args is that they are /not/ position
>   dependent, after all.
>

Thats a 'oops', will fix it. Most probabilly a left over froma previous
attempt at the function.

> - In args-to-tk, your way to build the result string is not quite
>   elegant. You might want to use a string-output-stream, as in
>   (special-casing :options ommitted):
>
>   (defun args-to-tk (args)
>     (with-output-to-string (stream)
>       (dolist (arg args)
>         (typecase arg
>           (string (format stream " ~S" arg))
>           (t (format stream " -~A" (string arg)))))))
>

Thanks will do that. Much of what I do in LISP is still far from elegant
;o{   , but I will persevere...

> - Generally, I'd prefer a more heavy wrapper, probably something
>   CLOS-based, with a tk:button class or something. This is probably
>   more work, though.
>

Why would I go through all that trouble if I'm going to en up passing a
string to the wish listner in the end anyway?
Or let me restate that what benefits would the CLOS version have over the
functions one? Maybe you can convince me to do it the CLOS way (at least as
much as clisp has of it) ;o}

> - Your indentation style could be improved, but that might be a
>   cut-and-paste problem :-)

paste-problem :o}
From: Harag
Subject: Re: lisp2wish extension?
Date: 
Message-ID: <bs286p$em3$1@ctb-nnrp2.saix.net>
This is a multi-part message in MIME format.

------=_NextPart_000_0008_01C3C740.EF8AC7F0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

After looking at your version of the helper function and reading about =
parameter combinations I have the following:

;;; The parent-name is appended to the name of the widget to emulate the
;;; style fo widget naming used in ActiveTCL's demos.
;;; The TK options can be passed in pair like used for &keys(see =
example).
(defun tk_button (parent-name name &rest options)
  "Converts a its args into a string representinf a TK_button =
defenition."
  (format nil "button $~A.~A ~A" parent-name name (args-to-tk options)))

;;;Helper functions

;;;args-to-tk was provide by Henrik Motakef" =
<············@henrik-motakef.de> (my own version sucked ;o})
(defun args-to-tk (args)
  (with-output-to-string (stream)
    (dolist (arg args)
      (typecase arg
 (string (format stream " ~S" arg))
 (t (format stream " -~A" (string arg)))))))


Results in the following:

21. Break [1]> (tk_button "w" "button" :text "help" :height "100" :state =
"normal")
"button $w.button  -TEXT \"help\" -HEIGHT \"100\" -STATE \"normal\""
------=_NextPart_000_0008_01C3C740.EF8AC7F0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV>After looking at your version of the helper function and reading =
about=20
parameter combinations I have the following:</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Microsoft Sans Serif" size=3D2>;;; The parent-name is =
appended to=20
the name of the widget to emulate the<BR>;;; style fo widget naming used =
in=20
ActiveTCL's demos.<BR>;;; The TK options can be passed in pair like used =
for=20
&amp;keys(see example).<BR>(defun tk_button (parent-name name &amp;rest=20
options)<BR>&nbsp; "Converts a its args into a string representinf a =
TK_button=20
defenition."<BR>&nbsp; (format nil "button $~A.~A ~A" parent-name name=20
(args-to-tk options)))</FONT></DIV>
<DIV><FONT face=3D"Microsoft Sans Serif" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Microsoft Sans Serif" size=3D2>;;;Helper =
functions</FONT></DIV>
<DIV><FONT face=3D"Microsoft Sans Serif" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Microsoft Sans Serif" size=3D2>;;;args-to-tk was =
provide by <FONT=20
face=3D"Times New Roman" size=3D3>Henrik Motakef" &lt;</FONT><A=20
···························@henrik-motakef.de"><FONT face=3D"Times New =
Roman"=20
size=3D3>············@henrik-motakef.de</FONT></A><FONT face=3D"Times =
New Roman"=20
size=3D3>&gt; (my own version sucked ;o})</FONT><BR>(defun args-to-tk=20
(args)<BR>&nbsp; (with-output-to-string (stream)<BR>&nbsp;&nbsp;&nbsp; =
(dolist=20
(arg args)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (typecase =
arg<BR>&nbsp;(string=20
(format stream " ~S" arg))<BR>&nbsp;(t (format stream " -~A" (string=20
arg)))))))</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Results in =
the&nbsp;following:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT><FONT=20
face=3DArial size=3D2></FONT><BR><FONT face=3D"Microsoft Sans Serif" =
size=3D2>21. Break=20
[1]&gt; (tk_button "w" "button" :text "help" :height "100" :state=20
"normal")<BR>"button $w.button&nbsp; -TEXT \"help\" -HEIGHT \"100\" =
-STATE=20
\"normal\""</FONT></DIV></BODY></HTML>

------=_NextPart_000_0008_01C3C740.EF8AC7F0--
From: vsync
Subject: Re: lisp2wish extension?
Date: 
Message-ID: <87ad55gqqk.fsf@piro.quadium.net>
Henrik Motakef <············@henrik-motakef.de> writes:

> - Generally, I'd prefer a more heavy wrapper, probably something
>   CLOS-based, with a tk:button class or something. This is probably
>   more work, though.

Something like http://quadium.net/code/splash/ perhaps...

I have some more generic stuff that I worked up, if anyone's interested,
but I think I'm now convinced that Lisp<->Java via sockets is the Wave
Of The Future.

-- 
vsync
http://quadium.net/
Banking on my hopes that whoever grades this will just look at the
pictures, I drew an exponential through my noise. I believe the
apparent legitimacy is enhanced by the fact that I used a complicated
computer program to make the fit.
	-- http://www.cs.wisc.edu/~kovar/hall.html