Common Lispをユーザーとしてインストールする

Lispで作られた

問題があります:実稼働サーバーにLispマシンがインストールされておらず(シンクライアント、シックサーバーのポリシーを使用しています)、もちろん私はそれらを管理していません。

2つのソリューションがすぐに思い浮かびます:



最初のオプションは、実際の実装に適しています。 残念ながら、突然すべてのターミナルサーバーがLispマシンを取得する必要がある理由については、十分な議論がありません。

したがって、ここでは2番目のオプションについて説明します。 (つまり、カスタムディレクトリのLinux上のECLについて)。





このパスに従って、私は最初に自宅で作業する2つの実装を思い出しました。



誰にも言えないなら、お願いします。 それから、統合プロジェクトにLispエンジンを組み込む必要があったときに、一度助けてくれたECLについて思い出しました。



作業環境



私たちのオフィスには、多数の同一のターミナルサーバーといくつかのネットワークボールがあります。 ホームディレクトリは100 MiBに制限されているため、ここには何もインストールしません。 しかし、私のホームディレクトリには、シンボリックリンク「ns」が指すヒューマンネットワークファイルストレージがあります。

$ ls ~ -l . . . lrwxrwxrwx 1 necto users 14 Jul 22 12:22 ns -> /network/file/system/users/necto . . .
      
      







設置



配布キットの入手方法は、プロジェクトページに記載されています 。 最も簡単な方法(imho):

 $ cd tmp && git clone git://ecls.git.sourceforge.net/gitroot/ecls/ecl && cd ecl
      
      





./ configure --helpから、非標準のディレクトリにeclをインストールするために、開始するいくつかのプレフィックスを指定するだけで十分であることがわかります。 ためらうことなく、必要なプレフィックスを設定します。

 $ ./configure --prefix "~/ns/ecl/" --exec-prefix "~/ns/ecl/"
      
      





しかし、そこにあった:

 Switching to directory `build' to continue configuration. configure: error: expected an absolute directory name for --exec_prefix: ~/ns/ecl/
      
      





まあ、シンボリックリンクが強制的に展開しなかったのは良いことです。

 ./configure --prefix "/home/necto/ns/ecl/" --exec-prefix "/home/necto/ns/ecl/"
      
      





正規になりました:

 $ mkdir ~/ns/ecl && make && make install
      
      





すべてが順調に進み、その結果:

  $ ~/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)
      
      





競合のないmakeの後でも:

  /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
      
      



/ home / necto / ns / ecl / libをLD_LIBRARY_PATHに追加できます($ export LD_LIBRARY_PATH = LD_LIBRARY_PATH:/ home / necto / ns / ecl / lib)。



「建物」



まず、スクリプトを作成するために(たとえば、ダンプに関する統計を収集するために)eclをインストールしました。 したがって、このインタープリターの起動は決して便利ではありません: $~/ns/ecl/bin/ecl -load tst.lisp





したがって、. / . bashrcにパッチを適用する必要があります。 同じ〜/ ns / eclディレクトリに、 to-bashrcファイルを追加します。

 #/bin/bash # should be included into your .bashrc # should be in .../ecl folder # defines two commands: # ecl - to run 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'
      
      





ここでは、簡単なエイリアスに加えて、ファイルを解釈するオプションが追加され、必要な機能が〜/ ns / ecl / my / common.lispで定義されています。

 ;;; common.lisp - aggregator of different tools ;;; being used in scripts ;; add standart lybrary path eg /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) 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)) ;;...
      
      





完全なコード

ちなみに、regexpを操作するための非常に軽量なライブラリであるpregexpを強くお勧めします。 〜800行に1ファイルしかない非常に小さなライブラリ。 ecl / my / common.lispで非常によく使用されます。



また、スクリプトに渡されるすべての引数のリストを含む定数+ cmd-args +が定義されることもわかります。

この経済をすべて統合するには、.bashrcを追加するだけで十分です。

  source ~/ns/ecl/to-bashrc
      
      







使用する



次に、たとえばall-funs.lispを作成します。

 (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 args extra-out)))) (defun print-hello (name) (format t "~%Hello, ~a." name)) (print-funcs)
      
      





そしてそれを実行します:

$ cl all-funs.lisp





 Hello, print-funcs. Hello, print-hello.
      
      





そして、talkativeフラグを指定した場合:

$ cl all-funs.lisp talkative





 Hello, print-funcs. Hello, print-hello. name
      
      







しかし、最も興味深いのは、同僚があなたの実績を使用したい場合、彼が.bashrc/ net / file / system / users / necto / ecl / to-bashrcを含めるだけで十分だということです!



おわりに





実際に、同じpythonやperlとともに、一般的なLispを便利なスクリプトインタープリターとして埋め込むのは非常に簡単であり、管理者権限を必要としないと言いたかったのです。



1つマイナスはまだ除去できていません:ご存知のように、lispはランタイムでのreplで有名であり、ECLには非常に不便なコンソールがあり、誤ってミスをすると、例外ハンドラーとして機能しなくなります(具体的には、誤った文字を消去できなくなります)。 私はここで苦労しているので、私は一般の人々の意見に興味があります。それをより編集可能なものに置き換えるにはどうすればよいですか?



必要なコンポーネント:


埋め込み可能なCommon Lisp

バッシュ

Pregexp (ちなみに、それは少し遅いですが、スタックがない場合もあります(長い行で)、だれが同じポータブルかをアドバイスしますか?)

P. s .:ああ、eclのロゴは見つかりませんでしたが、描く方法がわからないので、一般的なラベルを付けました。

P. s.2:誰かがLispフォーマットをどのようにフォーマットするのだろうか? source lang = "lisp"タグの場合、長いソースに対して灰色の背景のみが追加され、それ以上はありません(または、これはプレビューの制限ですか?)。



All Articles