I'm trying to create a simple CLISP script and I'd like to find out what are the most efficient and common ways of loading a library.
The script should take a line from stdin and display a message box containing this line. I'm using LTK.
This is the Python prototype:
Code: Select all
#!/usr/bin/env python3
# show-message.py
from tkinter import *
from tkinter import messagebox
def show_message(txt):
root = Tk()
root.withdraw()
messagebox.showinfo("", txt)
root.destroy()
def main():
show_message(input())
main()
Code: Select all
$ time echo hello world | ./show-message.py
real 0m1.381s
user 0m0.132s
sys 0m0.020s
Basicly I'm not sure about what the Lisp counterpart of the import statements should be.
I use quicklisp, so the straightforward solution was as follows:
Code: Select all
#!/usr/bin/env clisp
(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname)))
(ql:quickload :ltk)
(in-package :ltk)
(defun show-message (txt)
(with-ltk ()
(format-wish "wm withdraw .")
(do-msg txt)
(exit-wish)))
(defun main ()
(let ((msg (read-line nil nil nil)))
(when msg
(show-message msg))))
(main)
Code: Select all
$ time echo hello world | ./show-message.lisp >> /dev/null
real 0m1.449s
user 0m0.508s
sys 0m0.080s
I also tried to use asdf directly. I copied asdf.lisp into the same directory as the script, compiled it, created the directory `asdf' in my home directory, and created a symlink to ltk.asd (sitting deep in the quicklisp dir) in `asdf'. My preamble became as follows:
Code: Select all
(load 'asdf)
(push (merge-pathnames "asdf/" (user-homedir-pathname)) asdf:*central-registry*)
(asdf:load-system 'ltk)
Code: Select all
$ time echo hello world | ./show-message.lisp >> /dev/null
WARNING: Replacing method
#<CLOS:STANDARD-WRITER-METHOD
(#<BUILT-IN-CLASS T> #<STANDARD-CLASS TREEITEM>)>
in #<STANDARD-GENERIC-FUNCTION (SETF TEXT)>
WARNING: Replacing method
#<CLOS:STANDARD-WRITER-METHOD
(#<BUILT-IN-CLASS T> #<STANDARD-CLASS TREEITEM>)>
in #<STANDARD-GENERIC-FUNCTION (SETF IMAGE)>
0 errors, 2 warnings
real 0m1.277s
user 0m0.308s
sys 0m0.044s