Installing common lisp the rights of a user
problem On production servers (we use thin clients, fat servers) do not have any lisp machine, and I, of course, not administer them.
Come immediately to mind 2 solutions:
the
-
the
- to Persuade the administrator. the
- to Cope on their own.
The first option is suitable for the present implementers. I unfortunately do not have enough arguments why suddenly all terminal servers must have the Lisp machine.
So here we will talk about the second option. (Namely, about ECL on linux in a custom directory).
In doing so, I remembered 2 of the implement with which work from home:
the
-
the
- ANSI Common Lisp (clisp) the
- Steel Bank Common Lisp (sbcl)
None of them I could not get to work non-standard directory, if someone can suggest are welcome. Then I remembered the ECL, had once rescued me when I needed to embed a lisp engine in sesny project.
Working environment
In our office there are many identing terminal servers, and multiple network ball. Home directories are limited to a volume of 100 IIB therefore, to establish here anything I hate. But there is a human network file store, which is in my home directory specifies a symbolic link, "ns":
the
$ ls ~ -l
. . .
lrwxrwxrwx 1 necto 14 users Jul 22 12:22 ns -> /network/file/system/users/necto
. . .
Installation
How to take a distribution written in the project page. The easiest way (imho):
the
$ cd tmp && git clone git://ecls.git.sourceforge.net/gitroot/ecls/ecl && cd ecl
From ./configure --help can be gleaned that in order to install ecl in a non-standard directory, it is sufficient to specify a prefix, from which he will build. Without hesitation set up the appropriate prefix:
the
$ ./configure --prefix "~/ns/ecl/" --exec-prefix "~/ns/ecl/"
But there it was:
the
Switching to directory `build' to continue configuration.
configure: error: expected an absolute directory name for --exec_prefix: ~/ns/ecl/
Well, it's good that the link is not forced to expand.
the
./configure --prefix "/home/necto/ns/ecl/" --exec-prefix "/home/necto/ns/ecl/"
Now canonical is:
the
$ mkdir ~/ns/ecl && make && make install
I have all passed without problems, and the result is:
the
$ ~/ns/ecl/bin/ecl
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.
> (quit)
If you make a conflict-free after all:
the
/home/necto/ns/ecl/bin/ecl: error while loading shared libraries: libecl.so.11.1: cannot open shared object file: No such file or directory
you Can add /home/necto/ns/ecl/lib in LD_LIBRARY_PATH ($ export LD_LIBRARY_PATH=LD_LIBRARY_PATH:/home/necto/ns/ecl/lib )."Insert"
First I installed ecl in order to write scripts (for example to collect statistics on dumps). So here's a run of the interpreter was not easy:
$~/ns/ecl/bin/ecl -load tst.lisp
Therefore, it is necessary to patch ./.bashrc. In the same directory ~/ns/ecl add a file to-bashrc:
the
#/bin/bash
# should be included into your .bashrc
# should be in .../ecl folder
# defines two commands:
# ecl - to run the lisp interpreter in interactive mode [usage: ecl --help]
# cl $file - to execute lisp source with +cmd-args+ bind to
# list of commandline arguments
path_to_ecl=$(dirname ${BASH_SOURCE[0]})
# Use the next line, if ecl can't find libecl.so
export LD_LIBRARY_PATH="$path_to_ecl"/lib:$LD_LIBRARY_PATH
alias ecl="$path_to_ecl"'/bin/ecl'
function ecl run
{
line="(progn (defconstant +cmd-args+ '(${@})) (defconstant +/cl+ \"$path_to_ecl\/\") (load \"$path_to_ecl/my/common.lisp\" :verbose nil) (load \"$1\") (quit))"
ecl -eval "$line"
}
alias cl='ecl-run'
Here, in addition to the trivial alias added option for interpreting files with the necessary functions defined in ~/ns/ecl/my/common.lisp in which among other convenient buns have such a function:
the
;;; common.lisp aggregator of different tools
;;; being used in scripts
;; add standard lybrary path e. g. /home/necto/ns/ecl
:: use it on such way (load (lib/ "my/common.lisp"))
(defun lib/ (str)
(if (find-symbol "+/CL+")
(concatenate 'string +/cl+ str)
;; Another function useful in everyday scripting:
;; determine is a symb given as argument
(if (find-symbol "+CMD-ARGS+")
(defun symbol-mentioned-in-params (symb)
(find symb +cmd-args+)))
;; Use "verbose" or "talkative" to see debug info from
;; your script
(defun verbose-enabled-p ()
(and (find-symbol "+CMD-ARGS+")
(or (find 'talkative +cmd-args+)
(find 'verbose +cmd-args+))))
;; A output stream which you can enable by taking option "talkative"
;; to a script using it
(defconstant extra-out (if (verbose-enabled-p)
t
(make-string-output-stream)))
;; Also if user doesn't want to view all it's loads, disable it:
(setf *load-verbose* (verbose-enabled-p))
;;...
Complete code
By the way I highly recommend pregexp — a very easy and library to work with regexp'AMI. A very small library of only 1 file in ~800 lines. It is used in ecl/my/common.lisp well, very widely.
You can also see that you have defined the constant +cmd-args+ contains a list of all arguments passed to the script.
Now to integrate all this economy enough to add in .bashrc:
the
source ~/ns/ecl/to-bashrc
Usage
Now, it is sufficient to create, for example, all-funs.lisp:
the
(defun print-funcs ()
(process-every-file file (make-pathname :directory '(:relative) :name "*" :type "lisp") :input
(for-every-appropriate-line file "defun ([^ ]+) \(([^)]*)\)" (funame args)
(print-hello funame)
(print extra args-out))))
(defun print-hello (name)
(format t "~%Hello, ~a." name))
(print-funcs)
And run it:
$ cl all-funs.lisp
the
Hello, print-funcs.
Hello, print hello.
And if you specify the flag talkative:
$ cl all-funs.lisp talkative
the
Hello, print-funcs.
Hello, print hello.
name
But the most interesting, now what if a colleague wants to borrow your experience, it is enough to include /net/file/system/users/necto/ecl/to-bashrc to your .bashrc and all!
Opinion
Actually I wanted to say that embedding common lisp as a handy script interpreter, along with the same python or perl is quite simple and does not require administrative privileges.
One drawback I have not yet managed to resolve: As you all know Lisp is famous for its repl in runtime, and ECL is extremely inconvenient console, and if you accidentally made a mistake, it falls out as the exception handler (in particular exasperated the inability to erase the incorrect character). I'm here dealing with work, so interested in the opinion of the lisp community: how can I replace it with something more editable?
prerequisites:
Embeddable Common Lisp
bash
Pregexp(by the way kind of slow, and sometimes lacks the stack (on long lines) who can advise the same portable?)
PS.: Ah, found the logo of the ecl, and he can't draw, so put a generalized label.
PS.2: Interestingly, even as someone who formats the source in lisp? Because the tag of source lang="lisp" just adds grey background to the long source, no more (or is it a limitation of the preview?).
Комментарии
Отправить комментарий