Ports the functionality of the very popular left-pad from npm.
trivial-left-pad is the Common Lisp version of the extremely popular node.js left-pad package. It is designed to have as similar an API to node's left-pad as possible while still remaining idiomatic Lisp. For more information on the principles behind this project, see design-philosophy.md
trivial-left-pad is not on Quicklisp. To make Quicklisp recognize trivial-left-pad, create a link to this directory in Quicklisp's local-projects. By default, the path to local-projects is:
Quicklisp is the recommended way to use ASDF systems. Any other method of installation is currently unsupported. If you need to install Quicklisp, read this link.
You should be able to load trivial-left-pad from your REPL with:
You will also be able to use it as an ASDF dependency from any project also in local-projects. To add it as an ASDF dependency, add this line to your asdf:defsystem expression:
If the depends-on line already exists, don't add another depends-on line. Instead, append it to the existing list like in this example:
:depends-on (:some-other-package :trivial-left-pad)
You will also should add it to your defpackage expression, which could be in package.lisp or could be in another file. You need to append it to your :use list like in this example:
(:use #:cl #:trivial-left-pad)
After this, you should be able to call left-pad from your Lisp program.
To test trivial-left-pad, run the following command from your REPL:
(left-pad "foobar" 10) ; " foobar" (left-pad "Hello, world!" 15 #\_) ; "__Hello, world!"
Differences with node's left-pad
While compatibility with node's left-pad is a goal, there are some differences that should be kept in mind:
- node's left-pad takes a string of length one as its character argument. This left-pad takes a string-designator because Common Lisp has a character data type. You can use strings if you want.
- This left-pad checks the types of the length and padding arguments. Any undefined behavior that you might rely on in node's left-pad will not work here.
- Using Common Lisp package naming conventions, trivial-left-pad is prefixed with "trivial-" because it is trivial.