joergen7 / lang-util

Basic utilities for language models in Common Lisp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status

lang-util

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.

System Requirements

  • 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

Installing FiveAM

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

Adding lang-util

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/

Loading lang-util

You can load the library using either ASDF or Quicklisp. Below, we give instructions for each method.

Loading with ASDF

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)

Loading lang-util with Quicklisp

In addition to ASDF, you can load lang-util using Quicklisp. Assuming, you have Quicklisp loaded you can run

(ql:quickload :lang-util)

Testing

Running the Test Suite

With FiveAM and its dependencies in place you can now run:

(require :asdf)
(asdf:test-system :lang-util)

Coverage Info

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/")

Examples

Below, you find examples on how the library can be used.

Finding Duplicates in Lists

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

Padding Lines in a String

(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")

License

Apache 2.0

About

Basic utilities for language models in Common Lisp

License:Apache License 2.0


Languages

Language:Common Lisp 98.6%Language:Makefile 1.4%