0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SILVER HAIRED LISP (自作Lisp)を使ってみる

0
Posted at

SILVER HAIRED LISPを使ってみる

Java25と、SILVER HAIRED LISP のインストールが終わっているものとして解説します。

インストール方法については、後日紹介する予定です。

SILVER HAIRED LISPは、windowsとmacでテストしています。

起動コマンドは、windowsとmacで異なります。以下のようになる予定です。

windowsの場合

Windowsでは「ターミナル」というアプリから、起動コマンドを打ち込むとLispが起動します。
Windows11から「ターミナル」は、プレインストールされていた筈です。

winshl.cmd

Windowsの場合、上記のコマンドを実行すると、もう1つ窓が開きログが流れます。

macの場合

MacOSに標準で入っている Terminalや、iTermから起動します。

shllog.sh

shlmac.sh

前者はログ表示用のコマンドで、後者はLispと対話する用の画面です。
Macで自動的に、別のウインドウを開く方法がわからなかったので、2つのコマンドに分かれています。

hello, world 的なもの

cl-user >> (print "hello world")

"hello world"
"hello world"
java.lang.String
cl-user >> (quit)

インタープリタを終了する場合は、(quit) または (exit) と入力します。

ファイルを全部読み文字列にする

カレントディレクトリに、mitというディレクトリがあるものとします。

なければ、以下から落としておいてください。
https://github.com/shlisp/SilverHairedLisp/tree/main


cl-user >> (uiop:chdir "mit")

0
java.lang.Integer
cl-user >> (uiop:read-file-string "LICENSE.txt")

"\r\nuLisp\r\n\r\nLicence\r\nuLisp® ・・以下省略"
java.lang.String

注意)本Lispは独自ライセンスです。
mitというディレクトリに入っているファイルのみが、MITライセンスです。

uiopとは、SBCLのquicklispでロードするライブラリの事です。
現在は、以下の関数が実装されています。

absolute-pathname-p, chdir, delete-file-if-exists, ensure-all-directories-exist, getcwd
, getenv, read-file-string, relative-pathname-p, subpathname, write-file-string

補完機能を使う。文字列をファイルに書く

長い関数名を入力するのは、面倒なので、補完機能を使います。

(uiop: と入力して、TABを押すと、以下図のように候補が出ます。

TAB-HOKAN-NO-ZU331.png

TABキーを押していくと、下の候補が順に選択されていきます。

今回は、ファイルに書きたいので、一番最後までTABを押し、
uiop:write-file-stringの所で、ENTERを押すと、それが入力されます


cl-user >> (uiop:write-file-string "filename.txt" "contents")


これを実行すると、現在のディレクトリに、filename.txtができます。
そのファイルの内容は、contentsです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?