ferbolg wrote:What should I do to have text "Hello,world!" appeared on the console?
First of all: if you use 'princ' you should make sure that the text is really printed to the screen:
;;Printing
(princ "Hello, world!: ")
(terpri) ; terminate printing = flush the buffer
(bye) ; quit CLISP
Now you can run the plain text file like this:
C:\CLisp> clisp -q -norc hyp.lsp
Hello, world!:
C:\CLisp>
-q = do not show any welcome messages
-norc = do not read any initialisation files
You can speed up the read-time [but in CLISP this doesn't speed-up the execution-time], by byte-compiling the "hyp.lsp" file.
From within CLISP you can change the current working directory by writing:
[1]> (cd "C:\\CLisp")
#p"C:\\CLisp"
If you are in the "C:\CLisp" directory, write:
[2]> (compile-file "hyp.lsp")
The screen output should look like:
;; Compiling file hyp.lsp ...
;; Wrote file hyp.fas
0 Errors, 0 Warnings
#P"hyp.fas" ;
NIL ;
NIL
This should produce a file "hyp.fas", that you can run by writing:
C:\CLisp> clisp -q -norc hyp.fas
Hello, world!:
C:\CLisp>
If you want to run it as a stand-alone executable, you should do the following:
First define a function:
(defun hello-world ()
(princ "Hello, world!: ")
(terpri)
(bye))
From within CLISP this looks like::
[3]> (defun hello-world ()
(princ "Hello, world!: ")
(terpri)
(bye))
HELLO-WORLD
Warning: do NOT try to run the 'hello-world' function by typing (hello-world) at the CLISP prompt, because of the (bye) line CLISP will terminate instantly!
Now, after defining the 'hello-world' function at the CLISP prompt, dump a Lisp image and save it in a "myprog" executable:
[4]> (saveinitmem "myprog" :quiet t :norc t :executable t :init-function 'hello-world)
:quiet t = do not show any welcome messages
:norc t = do not read any initialisation files
:executable t = write a stand-alone executable
:init-function 'hello-world = after starting the executable, call the 'hello-world' function
The screen output should look like:
;; Wrote the memory image into myprog (8,489,838 bytes)
Bytes permanently allocated: 94,080
Bytes currently in use: 2,131,408
Bytes available until next GC: 530,852
2131408 ;
530852 ;
94080 ;
1 ;
35816 ;
32002
I haven't worked on Windows for a very long time, but according to the CLISP docs, on Windows "myprog" should be automatically extended to "myprog.exe". If it doesn't, just simply type "myprog.exe" instead of "myprog" after 'saveinitmem' above.
The executable was saved into the current CLISP working directory. In case of doubt type:
[5]> (cd)
#p"name-of-current-working-directory"
Now you should be able to run the stand-alone executable from the Windows commandline by typing:
C:\CLisp> myprog
Hello, world!:
C:\CLisp>
Plase note that the executable will contain the full Common Lisp runtime system, so this will probably be the biggest "Hello World" executable ever. Common Lisp was designed to solve "big" programming tasks, it is not particularly well suited for writing mini-executables.
For the full details of 'saveinitmem' see
http://clisp.cons.org/impnotes.html#image