Shammer's Philosophy

My private adversaria

Lisp

SLIME Configuration Memo with Jessie, ClozureCL 1.11

I wrote the contents about SLIME configuration as SLIME Configuration on my Debian - Shammerism, but it is an old one. So I re-write same contents with the latest environment. My current environment is: OS is Debian Jessie, uname -a result…

How to connect PostgreSQL via Common Lisp Application?

I found the link to describe the way how to handle PostgreSQL from Common Lisp application. There is a library named clsql. I have not tried it yet but this is a memo. I will try later when I can take a time.

Directory traversal check with Lisp

I want to write code to check directory traversal. In other words, replace ".." with other values if strings includes "..". For example, the string "/aaa/../index.html" should be replaced with "/index.html". And I want to write this code a…

別パッケージのコンディションを使用する

目的 Lispのパッケージで可読性が・・・ - Shammerismで、同一パッケージのソースコードを複数ファイルに分割可能とわかった。次のステップとしてアプリ・システム全体で独自のコンディションを使用してみる。個々の処理ごとに発生する可能性のあるコンディ…

Lispのパッケージで可読性が・・・

パッケージを多用した際の問題点 load したファイルで in-package しているとどうなる? - Shammerismで書いた内容に近いだろうか。Lispで大きいアプリケーションを書いていると、メソッド呼出の際のパッケージ名があちこちに入ってコードが読みにくくなる。…

rewrite http-read-line of http://d.hatena.ne.jp/shammer/20160320/p1

In the article Lisp HTTP Client handling chunked responses - Shammerism, I wrote a HTTP client which can handle chunked response. In this article, the function whose name is http-read-line uses do loop, but I would like to rewrite as recur…

Lisp repeat-string

I wrote this article to concatenate some character without dotimes, using with-output-to-string instead. But, I noticed more easy way to recursive function. Here is a last version. (defun str (x) (typecase x (cons (concatenate 'string (str…

How to add same character repeatedly without dotimes?

Sometimes I want to add some character repeatedly like generating something depended on how many there are. For example, organizing a file name with sequence numbers which might be different length, the length of sequence number 0 is 1, bu…

my is-dot-cons is a bad function...

I wrote is-dot-cons to check if it is a dot cons written at Is normal cons? Is dot cons? - Shammerism, but it has a bug. This function is not considered the following cons. ("100" . '(10 20 30))This is a dot cons, but cdr is not atom, so m…

Is normal cons? Is dot cons?

There is a case to want to know that the cons is normal cons or dotted cons. In detail, the cons is like ("A" "B") or ("A" . "B"). These cons have a difference how to handle right element. If the cons is like ("A" "B"), the function cadr c…

Using find-if instead of remove-if-not

This is a continuous article of remove-if と remove-if-not を理解する - Shammerism and find と remove-if-not - Shammerism. Lisp functions end-with -not would be deprecated in the future, so I have to get used to use functions which are not…

Lisp HTTP Client handling chunked responses

I wrote an HTTP client with ClozureCL, and this can handle chunked response. (defparameter *remote-host* "d.hatena.ne.jp") (defparameter *remote-port* 80) (defparameter *client-stream* nil) (defmacro connect-operation (&rest body) `(with-o…

eval-whenを試す

スクリプトとして実行された場合のみ実行したいという処理をどうすればいいか。どうやらeval-whenを使用すればこれができそうに思った。過去にちょっとだけ見たことがあるようだ。パッケージ名の取得でコケた・・・ - Shammerismでちょっとだけ言及している…

Install Clozure CL 1.11 to Debian wheezy running as Xen VM

I tried to install Clozure CL 1.11 into my Debian wheezy running as Xen VM. At first, I tried the way as well as Install Clozure CL 1.10 to Debian wheezy - Shammerism, but it finished with Error. root@tora2017:/usr/local/src/ccl/lisp-kerne…

文字列を16進数の配列に変換する

Socket 通信をバイトでやりとりするときに、文字列をそのまま16進数の文字列に変換したいことがあるのでそれを書いてみた。想定では、0から9、aからfのいずれかの1文字、2文字で一つの16進数を表現すること、先頭から読み込むと先頭が1バイトの時に正確な値…

Socket server sample with string-output-stream returns response from text files

string-output-streamをサーバーで使ってみる - Shammerismを改良し、応答をファイルから読み出したデータで返すことにする。あらかじめ、x.txtという名前のファイルを用意しておく。 $ echo 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxy…

string-output-streamをサーバーで使ってみる

format や prin1 で文字列を受け取る - Shammerismで、make-string-output-streamを使ったときの結果を書いたが、これを TCP の Server の中で使ってみたい。 受信した文字を標準出力に書き出すだけのサーバーは以下のようになるが、 (with-open-socket (ser…

Using typecase in Common Lisp

I wrote some functions that need to check the type of valuable with using cond with numberp, stringp, characterp etc, here is a sample. (cond ((numberp x) ; do something here ...) ((stringp x) ; do something here ...) (t ...)) But, there i…

read-line-with-message on Lisp

There are a lot of cases that waiting user input from STDIN after show some messages. Terminal output likes below on that case. What your name?: Waiting user input can be done with read or read-line on Lisp, but we have to use other functi…

Lisp selective box ver 20151124?

どのように呼べばいいかわからないのでこういうタイトルにしてみた。何らかの入力を伴うプログラムで、無効な値が入力された際には有効な値が入力されるまで繰り返し入力を促したい、という場合がある。全て網羅するのは大変なので、手始めに項番と項目のペ…

Both 0 and 1 are not integer on Lisp?

I found a wonder point on Lisp. Comparing a valuable type returned unexpected result. This unexpected thing happened when comparing the type of 1 and 2. I expected the type of them is equal. But this is not correct. ? (equal (type-of 1) (t…

Is this lisp function invoked on an interpreter or run as compiled program?

I have thought that there are any lisp standard function to judge whether this is running as an compiled program or running as an script on interpreter, this is in this article. Although I have never looked for a such kind of function earn…

Create a sequence list with Lisp

This is like a seq of shell command which is used like below. $ for i in `seq 1 10`;do echo $i;done 1 2 3 4 5 6 7 8 9 10 $Here is a lisp code. (defun seq (start end) (declare (integer start) (integer end)) (loop for i from start to end col…

Install Clozure CL 1.10 to Debian wheezy

I installed Clozure CL 1.9 to Debian wheezy before, detail is Install ClozureCL to Debian - Shammerism, but Clozure CL 1.10 already released. And then, I tried it but it couldn't be launched with following error. root@my-wheezy:/usr/local/…

How to break from loop in Common Lisp?

Description I found the link in Stack Overflow discussed about this. The link is Return from a nested loop in Common Lisp - Stack Overflow. This is an continuous article of 【LISP繰り返し Hack 】do を展開してみる・その2 - Shammerism. This…

ashでバイナリサーチをする?

Land of Lisp を ClozureCL で - Shammerismで言及したLand of Lispだが、最初のプログラムは数当てゲームだった。1から100の中の任意の数をユーザーが決定し、コンピュータの示した数の方が大きい場合は「より小さく」という主旨のコマンドを、コンピュータ…

Land of Lisp を ClozureCL で

Lispについての本は少ない。見つけても結構古い。20世紀の本もチラホラあるくらいだ。使っていない人からしたら化石と思われていそうなそんな言語だが、オライリーからLand of Lispなる本が出た。 Lispを使う人間としては当然"買い"な本だが、残念なことに(?…

LISP IO Samples 20150820

LISP IO Samples 20120825 - Shammerismに一部追加。 File 読み込み (with-open-file (input-stream "$READ_FILE_NAME" :direction :input) (loop (let ((line (read-line input-stream nil 'eof))) (if (eql line 'eof) (return)) (format t "~A~%" line)))…

Lispでシフト演算をする

そのままズバリな名前の関数ではなかったのでメモ。ashという関数を使用する。 ? (ash 32 5) 1024 ? (ash 23 2) 92 ? (ash 32 1) 64 ? (ash 64 -1) 32 ? (ash 32 -5) 1 ? (ash 32 -6) 0 ? (ash 32 -7) 0 ? ashは引数を二つ取る。一つはもとになる数(この数に…

~%をファイルに書き出すには

普通にformatを使ってファイルに~%を書き出そうとすると、~%でなく改行と認識されてしまい期待通りにならない。 ? (with-open-file (file "aaa.l" :direction :output) (format file "~%")) NIL ? これで書き出されたaaa.lは以下のように改行だけ(何も表示さ…