Phel の Pharファイルが公開されたので、試してみるのが非常に簡単になりました。

0.18.0 – Going PHARther

Phelを試すのが更に簡単になりました。PHP(8.2以上)の実行環境があれば、phel.phar ファイルをダウンロードするだけで、phel-langを実行できます。dockerやcomposerが無くても良くなるので、とりあえず触ってみるのは簡単です。

準備

phel.pharをダウンロードして、実行権限を付けるだけです。(Windowsなら実行権限も不要かもしれません)

$ curl -OL https://github.com/phel-lang/phel-lang/releases/download/v0.18.0/phel.phar
$ chmod +x phel.phar

これで準備は完了です。phel-lang 0.18.0 で追加された doctor コマンドで動作環境に問題がないかを確認してみます。

$ ./phel.phar doctor
Checking requirements:
 - PHP >= 8.2: OK
 - json extension: OK
 - mbstring extension: OK
 - readline extension: OK
Your system meets all requirements.

OKでした。

REPLの実行

REPLを起動して 1 + 2 + 3 の結果を表示してみました。

$ ./phel.phar repl
Welcome to the Phel Repl
Type "exit" or press Ctrl-D to exit.
phel:1> (println (+ 1 2 3))
6
nil

phelのスクリプトファイルの実行

では、次にphelのコードが書かれたファイルを実行してみます。

src/hello.phel

(ns hello
  (:require phel\str))

(println "Hello, phel")

(as-> "The Phel Language" it 
  (str/upper-case it)
  (str/pad-left it 30 " ")
  (println it))

run に続けてhello.phelのパスを指定することで実行できます。

$ ./phel.phar run src/hello.phel 
Hello, phel
             THE PHEL LANGUAGE
hello.phelを実行することができました。 次は、別のファイルの関数を使う例を実行してみます。

src/module.phel

(ns module)

(defn get-title []
  "from module.")

src/call.phel

(ns call
  (:require module))

(println "call file")
(println (module/get-title))
上の2つのファイルを用意して、call.phelを実行します。
$ ./phel.phar run src/call.phel  
call file
from module.
call.phelを実行して、module.phelの関数を利用できたことがわかります。

まとめ

非常に簡単にphelを試すことができることがわかります。PhelはClojureに似た構文を持つ言語です。 Phel Language 生成AIにプログラムを書かせるのが仕事になってきつつある人も少なくないかもしれませんが、趣味プログラミングとしてPhelを試してみてはどうでしょうか?

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です


reCaptcha の認証期間が終了しました。ページを再読み込みしてください。

This site uses Akismet to reduce spam. Learn how your comment data is processed.