I'm a beginner in Common Lisp and I want to use a library.
I can't find a single one simple example of loading / requiring / using a module. I've installed cl-ppcre like this :
$ sbcl --non-interactive --eval '(ql:quickload "cl-ppcre")'
To load "cl-ppcre":
Load 1 ASDF system:
cl-ppcre
; Loading "cl-ppcre"
..
But I don't know how to actually use it. I've tried the following and a dozen other thing and not one works.
$ sbcl --noinform --non-interactive --eval '(progn (require "cl-ppcre") (cl-ppcre:split "\s+" "1 2 3"))'
Unhandled SB-INT:SIMPLE-READER-PACKAGE-ERROR in thread #<SB-THREAD:THREAD "main thread" RUNNING
{1004DB8073}>:
Package CL-PPCRE does not exist.
Stream: #<dynamic-extent STRING-INPUT-STREAM (unavailable) from "(progn (...">
Backtrace for: #<SB-THREAD:THREAD "main thread" RUNNING {1004DB8073}>
0: (SB-DEBUG::DEBUGGER-DISABLED-HOOK #<SB-INT:SIMPLE-READER-PACKAGE-ERROR "Package ~A does not exist." {1003640A83}> #<unused argument> :QUIT T)
1: (SB-DEBUG::RUN-HOOK *INVOKE-DEBUGGER-HOOK* #<SB-INT:SIMPLE-READER-PACKAGE-ERROR "Package ~A does not exist." {1003640A83}>)
2: (INVOKE-DEBUGGER #<SB-INT:SIMPLE-READER-PACKAGE-ERROR "Package ~A does not exist." {1003640A83}>)
3: (ERROR #<SB-INT:SIMPLE-READER-PACKAGE-ERROR "Package ~A does not exist." {1003640A83}>)
So how can I make it work ?
EDIT 1: I didn't precised that my problem with using libraries is as much a in scripts as in the terminal. It was implicit to me. This is because of my experience in Perl, in which everything you can do with a file, you can do at the command line, including using libraries.
EDIT 2: Here is my working solution. As it turned out, there were 2 things were wrong. My problem required to :
- using multiple
--eval
Just like Svante and ignis volens said.
(load "~/.quicklisp/setup.lisp")
Which I was alrady explained here :
Confused about ``ql:quickload`` and executable scripts in SBCL
This is the terminal solution :
sbcl --non-interactive --eval '(load "~/.quicklisp/setup.lisp")' --eval '(require :cl-ppcre)' --eval '(princ (cl-ppcre:split "\\s+" "1 2 3"))'
With the caveat that a bunch of warnings are outputed on stderr, like this one, and I don't know why that is.
WARNING: redefining QL-SETUP:QMERGE in DEFUN
And this is the script solution :
#!/usr/bin/sbcl --script
(load "~/.quicklisp/setup.lisp")
(require :cl-ppcre)
(princ (cl-ppcre:split "\\s+" "1 2 3"))
(terpri)