Re: Console Hello World how to
David Margolies <[email protected]> Thu, 13 Jul 2006 13:33:07 -0700
| Newsgroups | gmane.lisp.allegro |
|---|---|
| Message-ID | <[email protected]> |
Dave Mihalik asked about a no-window application created by Allegro
CL. He is using the project system. He ahs a fuction in test1.cl
(defun test1()
(let ((mystring1 "")))
(setf mystring1 "Hello World")
(print mystring1)
)
which he make the on-initialization function of the project, but
when the app starts, he gets the error:
Error: attempt to call `TEST1' which is an undefined function.
[condition type: UNDEFINED-FUNCTION]
I wrote him the following which I also am sending to this list.
The package problem would be solve by placing
(in-package :cg-user)
at the head of your test1.cl file. (Without an in-package form, the
symbols are read in whatever package happens to be current when the
file is loaded. That seems to be the cl-user package when the project
executable is made. Because it is hard to know what package will be
current when things are done automatically.
Once you do that, the project will comile and run correctly, but you
will run into another difficulty testing it: the program will exit
when it completes and it iwll complete so fast that it is unlikely you
will see anything.
Change your function to this:
(defun test1()
(let ((mystring1 "")))
(setf mystring1 "Hello World")
(print mystring1)
(sleep 100)
)
and the console will be there for a while. Also add this and correct
your LET form (which is doing nothing since you have closed it off:
(defun test1()
(console-control :show t)
(let ((mystring1 ""))
(setf mystring1 "Hello World")
(print mystring1)
(sleep 100))
)
This will ensure the console is displayed.
But the program will end after 100 seconds.
The point is that your program is either doing something or it is
waiting for the user to do something. If your program is doing
something, it ends when that something is done. If your porgram is
waiting on the user, it has to ask for input in some fashion.
If your app had windows (the main one specified by the project Main
Form), then that window would be displayed and the program would exit
when it is closed. But your program doesn't. This will ask for user
input:
(defun test1()
(console-control :show t)
(let ((mystring1 ""))
(setf mystring1 "Hello World")
(print mystring1)
(loop (if (y-or-n-p "Stop now? ") (exit 0 :no-unwind t)))
)
If you hit n, you are asked again. If you hit y, it exits.
David Margolies
Franz Inc.