lisp 起動してから slime から操作して元にもどすメモ
swank server を利用すると、はじめからslime を使用していなくても、途中から利用できるようになる。これを利用すると起動中の ものを書き換えるホットデプロイができるらしい。これの操作メモ
swank server をマニュアル起動
それから swnk をquickload して、(swank:create-server :port 4005 :style :spawn :dont-close t)を評価する。
Welcome to Clozure Common Lisp Version 1.10 (DarwinX8664)!
CCL is developed and maintained by Clozure Associates. For more information
about CCL visit http://ccl.clozure.com. To enquire about Clozure's Common Lisp
consulting services e-mail info@clozure.com or visit http://www.clozure.com.? (ql:quickload :swank)
To load "swank":
Load 1 ASDF system:
swank
; Loading "swank"
....
(:SWANK)? (swank:create-server :port 4005 :style :spawn :dont-close t)
;; Swank started at port: 4005.
4005
?
slime-connect と slime-disconnect
Emacs から M-x slime-connect を実行する。hostと、ポート番号をきかれるのでそのままエンターを連続入力する。これでいつもの *slime-repl ccl*バッファがひらく。
さて、元のターミナルはどうなっているのだろう。プロンプトが表示されていない。
入力が、swankによってのっとられたということだろう。
; Warning: Test failed: (&KEY #'#'+) => "(&key (function (function +)))"
; Expected: "(&key (function #'+))"
; While executing: (:INTERNAL TEST TEST-PRINT-ARGLIST), in process worker(8).
Emacs 上で、普通に slimeのセッションがはじまる。
これで、Emacsから M-x slime-disconnect すれば接続を切断できる。ターミナルでの入力にもどるはず。
;; swank:close-connection: Unexpected end of file on #
とりあえずプロンプトが表示されなかったのが、適当に入力してエンターを入力すると元にもどったことがわかる。ただしEnter を入力してもプロンプトは出してくれないのでここでは ?+Enter を入力した。
?
The following toplevel commands are available:
:? help
:PWD Print the pathame of the current directory
(:CD DIR) Change to directory DIR (e.g., #p"ccl:" or "/some/dir")
(:PROC &OPTIONAL P) Show information about specified process/all processes
(:KILL P) Kill process whose name or ID matches
(:Y &OPTIONAL P) Yield control of terminal-input to process
whose name or ID matches, or to any process if
is null
Any other form is evaluated and its results are printed out.
? :q
Unknown command :Q
? :?
The following toplevel commands are available:
:? help
:PWD Print the pathame of the current directory
(:CD DIR) Change to directory DIR (e.g., #p"ccl:" or "/some/dir")
(:PROC &OPTIONAL P) Show information about specified process/all processes
(:KILL P) Kill process whose name or ID matches
(:Y &OPTIONAL P) Yield control of terminal-input to process
whose name or ID matches, or to any process if
is null
Any other form is evaluated and its results are printed out.
? (+ 1 1)
2
もちろん、この Emacsでの操作は反映されている。
確認するには、Emacs で M-x slime-connect して、slimeで変数を設定してから M-x slime-disconnect し。ターミナルで変数が設定されているかを確認すればよい。
slimeで
CL-USER> (defvar *DoYouRemember* t)
*DOYOUREMEMBER*
ターミナルで
? *DoYouRemember*
T
ホットデプロイ
http://aikotobaha.blogspot.jp/2013/03/common-lisp.html にそって、実施する。
ポート番号は4005にするとあとでEmacs のslime接続とかぶるから避ける。
ccl64
Welcome to Clozure Common Lisp Version 1.10 (DarwinX8664)!
CCL is developed and maintained by Clozure Associates. For more information
about CCL visit http://ccl.clozure.com. To enquire about Clozure's Common Lisp
consulting services e-mail info@clozure.com or visit http://www.clozure.com.? (ql:quickload :swank)
To load "swank":
Load 1 ASDF system:
swank
; Loading "swank"
....
(:SWANK)
? (swank:create-server :port 5555 :style :spawn :dont-close t)
;; Swank started at port: 5555.
5555
? (defparameter *num* 1)
*NUM*
? (defun foo () (format t "~a~%" *num*))
FOO
? (loop
(foo)
(sleep 1))
これで *num* が一秒毎に出力できる。
1
1
1
Emacs から M-x slimeで 別ターミナルから clozure clを実行。
そこで swank-client で接続する。
(ql:quickload :swank-client) (swank-client:with-slime-connection (conn "localhost" 5555) (swank-client:slime-eval '(setf *num* 2) conn))
確かに書きかわっている。
1
1
1
;; swank:close-connection: Unexpected end of file on #
2
2
2
これをリモートでするには、sshトンネルで通信を暗号化した方がいいのだろう。