Basic utilities for language models in Common Lisp
The lang-util library provides common operations in handling language models like finding the first duplicate in a list or indenting/commenting the lines in a string.
- A Common Lisp distribution; I tested the following distributions:
- ASDF comes packaged with the aforementioned CL distributions
- FiveAM and its dependencies
ASDF looks for system definitions in the ~/common-lisp/
folder. Create it and change to it.
mkdir -p ~/common-lisp
cd ~/common-lisp
To run the test suite you must have the FiveAM regression testing framework and its dependencies available. We use ASDF to manage systems and their dependencies. In the ~/common-lisp
folder run
git clone http://common-lisp.net/project/trivial-backtrace/trivial-backtrace.git
git clone http://common-lisp.net/projects/alexandria/alexandria.git
git clone https://github.com/didierverna/asdf-flv.git
git clone https://github.com/lispci/fiveam.git
The lang-util library also needs to be visible to ASDF. Assuming your clone of the lang-util repository resides in ~/git/lang-util/
this can be accomplished by creating a symbolic link.
ln -s ~/git/lang-util ~/common-lisp/lang-util
Eventually, you should end up with a directory structure like this:
~/
+- common-lisp/
+- alexandria/
+- asdf-flv/
+- fiveam/
+- lang-util/
+- trivial-backtrace/
You can load the library using either ASDF or Quicklisp. Below, we give instructions for each method.
Most Common Lisp distributions come with ASDF packaged. Thus, you can simply require ASDF and load the lang-util system like so:
(require :asdf)
(asdf:load-system :lang-util)
In addition to ASDF, you can load lang-util using Quicklisp. Assuming, you have Quicklisp loaded you can run
(ql:quickload :lang-util)
With FiveAM and its dependencies in place you can now run:
(require :asdf)
(asdf:test-system :lang-util)
Assuming, that you are running SBCL you can get coverage information using SBCL's sb-cover module.
(require :asdf)
(require :sb-cover)
(asdf:test-system :lang-util)
(sb-cover:report "coverage/")
Below, you find examples on how the library can be used.
The find-duplicate
function allows to find duplicate entries in a list. What makes a duplicate can be defined by giving a test predicate that takes two arguments.
(find-duplicate '(1 2 1))
1
(find-duplicate '(1 2 3) :test #'=)
nil
(find-duplicate '(a a) :test #'cl:eq)
'a
(line-pad "this is a comment" "// ")
"// this is a comment"
(line-pad (format nil "indented~%lines") " ")
(format nil " indented~% lines")
(line-pad
(format nil "#include <don't indent this>~%but indent everything else")
" "
:unless-starts-with #\#)
(format nil "#include <don't indent this>~% but indent everything else")