TK and "scale"(slider) interaction with newlisp

Q&A's, tips, howto's
Locked
Rovingeye
Posts: 7
Joined: Thu Feb 19, 2004 3:23 pm

TK and "scale"(slider) interaction with newlisp

Post by Rovingeye »

Just like to say I am new to lisp, but seem to have settled with newlisp as a very clean, concise language that is allowing me to get all kinds of work done.

I have one problem, I am new to both lisp, newlisp, and TK, so there is a chance its a silly mistake on my part. On win32 I create a scale control, but when I link it with a -command to newlisp I get:

wrong # args: should be "Newlisp command"
wrong # args: should be "Newlisp command"
while executing
"Newlisp {(set-value)} 0"
(command executed by scale)

I assume (and by playing with the slider) I have found the 0 is the current value of the slide.

Thanks
Darren

P.S.
My only other problem is the xml-parser is way to slow :) I cheat, and convert my xml into s-expression for debugging code. But I would be laughed at if anyone here saw how slow the reader was.
(print "hello, World!")

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Thanks for the compliment about newLISP.

I never tried the Tk slider and don't fully understand the problem, but perhaps it helps reading the section "Writing applications with newLISP and Tcl/Tk" how to pass variable values back and forth between Tcl/Tk and newLISP in the newLISP-tk manual.

About XML: I always thought the xml-parse in newLISP was fast, at least in benchmarks with Java it came out much faster, but if there are improvements possible, we will do it!. Perhaps you can post you XML and explain how you want to use it in newLISP. Are you using 'xml-type-tags' the appropiate way?

The program in newlisp-blog-32.tgz uses XML to store and receive blog content. The best way is to parse XML is with "(xml-type-tags nil nil nil nil)" into SXML expressions and then use 'assoc'' or 'lookup' to extract attributes/variables.

Very welcome to our group ...

Lutz

Rovingeye
Posts: 7
Joined: Thu Feb 19, 2004 3:23 pm

Post by Rovingeye »

I looked back at the newLisp-tk manuals, and followed the example, but I still seem to get the same problem, everything works fine, upto the point I drag the control, then I get the error I supplied. To me it looks like TK is supplying the value of the control as a parameter, but newlist doesn't expect this.

I will try next week to get the ok to send you some files, the latest one I was playing with was around 650k, newlisp seemed to be taking seconds to read this file instead of msec. I was using your solution to convert the file into an SXML and saving that, once converted the files is much faster to load.

I had some other problems about editing XML trees in memory, but I think after re-reading the manual I could write some helpers that should help ease the pain, and keep the performance, I'll let you know how I get on.

I have been playing around with the blog code, with an eye to using it to build a website. although with my experience gained from playing with the XML I am tempted to switch the file format to SXML.
(print "hello, World!")

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

The 'Newlisp' function in the Tcl/Tk interface code only takes one argument, but there is a workaround writing a wrapper. Paste the following code into a file and load it from newLISP-tk:

Code: Select all

(context 'SCALE)

(define (run )
  (tk "proc ScaleValue { val } { Newlisp \"(silent (SCALE:set-value $val ) )\" }")
  (tk "if {[winfo exists .example] == 1} {destroy .example}")
  (tk "toplevel .example")
  (tk "scale .example.scale -from -10 -to 20 -length 200 -orient horizontal")
  (tk ".example.scale configure -command {ScaleValue}")
  (tk "pack .example.scale"))

(define (set-value x) 
  (print x " "))

(context 'MAIN)

(SCALE:run)

Note that the \" around the (silent ...) statement. Curly braces will not do it here becuase they would prevent $val from beeing evaluated inside Tcl.

Here comes a second version of the same code, but all Tcl/Tk code together and more readable if you do program editing with a normal editor and/or have bigger portions of Tcl/Tk code:

Code: Select all

(context 'SCALE)

(define (run )
  (tk 
[text]

proc ScaleValue { val } { 
    Newlisp "(silent (SCALE:set-value $val ) )" 
    }


if {[winfo exists .example] == 1} {destroy .example}

toplevel .example
scale .example.scale -from -10 -to 20 -length 200 -orient horizontal
.example.scale configure -command {ScaleValue}
pack .example.scale

[/text]
  ))

(define (set-value x) 
  (print x " "))

(context 'MAIN)

(SCALE:run)
The [text], [/text] tags enclose the whole Tcl/Tk portion. Inside [text] tags everything stays unprocessed by newLISP, so you can do more readable code without using escaped \". Of course in the newLISP-tk function browser it looks ugly again.

About XML: if you can work in SXML that is of course much better and faster, as it is a LISP native format. If other programs use XML you could just have a routine to convert it back.

SXML is a pretty nice format, perhaps even more readable than XML itself including for people who never have learned LISP. I know that many hardware people / ASIC designers use HDL's which look like LISP. All LISP programmers of course say SXML is what XML should have been in the first place :). Because SXML has less parenthesis using symbols as tags it produces smaller more readable files.

Look also in to the functions 'nth' 'nth-set' and 'set-nth', they all can take multiple indices for accessing / modifying deeply nested SXML.

Lutz

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

I found a bottleneck in the XML routines which slowed down the conversion of bigger files. On a 500Kbyte file I have now an almost 1000 times speed improvement (previously 40seconds now 50ms) just by changing a strncpy() 'C' call to memcpy().

Stepping through assembly I realized that strncpy() of course is calling strlen(), this caused an exponential increase with filesize of the time needed to do the XML parsing.

This will be in an upcoming developers release 7504.

Lutz

Rovingeye
Posts: 7
Joined: Thu Feb 19, 2004 3:23 pm

Thank you

Post by Rovingeye »

Thanks a lot for the very quick response, the code for the scale was some stuff I was playing with at work, and I wanted to wait until I had tried it until I replied.

Well I tried it and it works wonderfully. I have even tweaked things a little, so I can pass back a control id into newlisp so I know which slider was played with :)

The XML performance improvments I look forward too, and will let you know how I get on.

I'm still thinking about the sxml tree access/manipulation. Having written my own library, I have gotten used to a way of doing things that doesn't exactly seem to map to newlisp, but then perhaps I should just take my C/C++ head off :)
(print "hello, World!")

Rovingeye
Posts: 7
Joined: Thu Feb 19, 2004 3:23 pm

Version 7.5.4 is out

Post by Rovingeye »

I see the new version is out, I have something to look forward to now when I go into work :)

Thanks
(print "hello, World!")

Rovingeye
Posts: 7
Joined: Thu Feb 19, 2004 3:23 pm

Too Fast :)

Post by Rovingeye »

Well I tried it, I think its a little too fast, I had to do it again just to make sure it had done it right the first time.

Very cool

Thanks Again.
Darren
(print "hello, World!")

Locked