User Tools

Site Tools


using_ecl_embeddable_common-lisp_on_sdf

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
using_ecl_embeddable_common-lisp_on_sdf [2021/03/11 05:42] – [References:] hc9using_ecl_embeddable_common-lisp_on_sdf [2021/03/12 18:34] (current) – [References:] hc9
Line 1: Line 1:
 +====== Using ECL (Embeddable Common-Lisp) on SDF ======
 +
 +===== What is ECL? =====
 +
 +ECL stands for //Embeddable Common-Lisp// and is a free open source ANSI Common-Lisp implementation. Its distinguishing attributes are maintaining a small-footprint, and being embeddable with existing C/C++ applications. ECL is LGPL licensed and hosted at [[http://ecls.sourceforge.net/|ecls.sourceforge.net]].
 +
 +ECL-11.1.1 is currently available to MetaARPA members on most SDF hosts.
 +
 +===== ECL vs CLISP =====
 +
 +There are currently two Common-Lisp implementations available on SDF; ECL and CLISP. Both are largely compliant with the ANSI Common-Lisp standard. Each supports various object systems, debugging, bytecode compiling, unicode, sockets, streams, etc. CLISP comes with built-in readline support; ECL doesn't, though it can be added; see the [[#asdf|ASDF]] section. In addition to being smaller and faster than CLISP, ECL can be embedded in C/C++ programs, allow embedded C/C++ code in Lisp programs, and produce stand-alone ELF executables. ECL is also very well documented.
 +
 +===== ECL Basics =====
 +
 +By default ECL starts up in interactive mode. Log into SDF host //miku// and type "'ecl'"; you should see something like below:
 +
 +<code>
 +
 +ECL (Embeddable Common-Lisp) 11.1.1
 +Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
 +Copyright (C) 1993 Giuseppe Attardi
 +Copyright (C) 2000 Juan J. Garcia-Ripoll
 +ECL is free software, and you are welcome to redistribute it
 +under certain conditions; see file 'Copyright' for details.
 +Type :h for Help.
 +Top level.
 +>
 +
 +</code>
 +
 +The default ECL prompt is ">". Enter Common-Lisp commands in the usual way:
 +
 +<code>
 +
 +> (+ 1 2 3)
 +6
 +
 +> (* 4 5)
 +20
 +
 +> (format t "hello SDF~&amp;")
 +hello SDF
 +NIL
 +>
 +
 +</code>
 +
 +In-line help is available ; type :h for options. The debugger can be entered using "(break)" ; once entered typed :h to see options. To exit the ECL interactive session type ":exit" .
 +
 +===== ECL one-liners =====
 +
 +To use ECL as a script executor (ie. CGI) the //-shell// and/or //-eval// options can be used. The //-norc// is often a good addition so as to avoid unnecessary loading of modules, etc.
 +
 +ex: hello.lsp
 +
 +<code>
 +
 +% echo '(format t "~&amp;Hello SDF~&amp;")' > hello.lsp
 +
 +% ecl -norc -script hello.lsp
 +Hello SDF
 +
 +</code>
 +
 +It's also possible to use ECL to execute simple Common-Lisp one-liners at the command line (note that //princ// is needed for screen output):
 +
 +<code>
 +
 +% ecl -norc -shell /dev/null -eval "(princ (* 1 2 3))"
 +6
 +
 +</code>
 +
 +A nicer way to accomplish the same is to create a small shell script:
 +
 +<code>
 +
 +#!/bin/sh
 +# lispit - executes a lisp expression and dumps it to stdout
 +
 +LSP_EXPR=${@}
 +
 +if [ "$#" -eq 0 ]; then
 +        echo "lispit - executes a lisp expression"
 +        echo "  usage: lispit '(lisp_expression)'"
 +        echo ""
 +        exit 1
 +fi
 +
 +ecl -norc -shell /dev/null -eval "(princ ${LSP_EXPR} )"
 +echo ""
 +exit 0
 +
 +</code>
 +
 +Example run:
 +
 +<code>
 +
 +% lispit '(mapcar (lambda (x) (expt x 2)) `(1 2 3 4 5))'
 +(1 4 9 16 25)
 +
 +</code>
 +
 +===== ASDF / enabling readline =====
 +
 +ASDF (//Another System Definition Facility//) is an extensible build facility for Common-Lisp software. ECL comes with ASDF bundled in, however on SDF, users must setup their own ASDF repository under their $HOME directory.
 +
 +The following outlines the process, using the //ecl-readline// module (adds GNU readline support to ECL) as example:
 +
 +1) Create the user-level ASDF repository:
 +
 +<code>
 +
 +% mkdir -p $HOME/LISP/ASDF
 +
 +</code>
 +
 +2) Create the ASDF config directory and config file*:
 +
 +<code>
 +
 +% cd $HOME
 +% mkdir -p .config/common-lisp/source-registry.conf.d
 +% vi .config/common-lisp/source-registry.conf.d/asdf.conf
 +
 +# ../asdf.conf
 +;;additional directory for ASDF to search (no recursion):
 +(:directory "/LISP/ASDF/")
 +
 +</code>
 +
 +*note: you can call the conf file anything you want.
 +
 +3) Download ecl-readline module and copy select files to $HOME/LISP/ASDF:
 +
 +<code>
 +
 +% cd /tmp
 +% snarf http://www.common-lisp.net/project/ecl-readline/releases/ecl-readline-0.4.1.tar.gz
 +% tar xzf ecl-readline-0.4.1.tar.gz
 +% cd ecl-readline-0.4.1/
 +% cp ecl-*.* $HOME/LISP/ASDF/
 +
 +</code>
 +
 +4) Create the ECL startup file:
 +
 +<code>
 +
 +# $HOME/.eclrc
 +(require 'asdf)
 +(asdf:operate 'asdf:load-op 'ecl-readline)
 +(ecl-readline::enable)
 +
 +</code>
 +
 +The next time you startup ECL it will compile the ecl-readline module and launch an interactive session. With ecl-readline enabled the default ECL prompt is "//CL-USER[n]>//" and you should then be able to use Emacs-style command editing and history recall. If you don't like the provided prompt you can change it by editing the //ecl-readline.lisp// file.
 +
 +===== Customizations =====
 +
 +Additional modifications can be made to the ECL startup file, such as user-defined functions and tweaks to various modules. Below is a more nuanced example which reduces the verbosity at startup, modifies ecl-readline's history file location, and adds an external SHELL function similar to that found in CLISP:
 +
 +<code>
 +
 +# $HOME/.eclrc
 +(require 'asdf)
 +(setf ASDF:*ASDF-VERBOSE* nil) ; quiets ASDF output some
 +(setf *load-verbose* nil)       ; quiets the LOAD process some
 +(asdf:operate 'asdf:load-op 'ecl-readline)
 +(ecl-readline::enable :history-file "/var/tmp/.ecl-history")
 +;;
 +;; customizations
 +
 +;; GNU clisp-like SHELL cmd
 +(defun shell (&amp;optional (shell_cmd "$SHELL"))
 +"Args: (&amp;optional shell_cmd)
 +SHELL calls the EXT:SYSTEM function. Executes SHELL_CMD if given, otherwise
 +User sub-shell is spawned. SHELL_CMD be string or symbol, 256 characters max."
 +   (ext:system shell_cmd))
 +
 +</code>
 +
 +===== References: =====
 +
 +  * //ecl(1)// and //ecl-config(1)// manpages
 +  * http://ecls.sourceforge.net/
 +  * [[http://common-lisp.net/project/asdf/|http://common-lisp.net/project/asdf]]
 +  * [[http://common-lisp.net/project/ecl-readline/|http://common-lisp.net/project/ecl-readline]]
 +  * [[http://www.cliki.net/Getting%20Started|Getting Started with Common-Lisp]]
 +
 +----
 +
 +$Id: ecl_tutorial.html,v 1.4 2011/12/12 18:10:28 Exp jgw $ [[http://sdf.org/?tutorials/ecl_tutorial|Using ECL (Embeddable Common-Lisp) on SDF]] - traditional link (using [[wp>Revision_Control_System|RCS]])