Phel v0.36.0 – 运行于 PHP 之上的 Lisp,现支持数值塔(Numeric Tower)与一等公民 Var

Hacker News Top 工具

摘要

Phel v0.36.0 已发布,为这款受 Lisp 启发的、编译为 PHP 的函数式编程语言引入了数值塔和一等公民 Var。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/05/11 09:49

phel-lang/phel-lang 来源: https://github.com/phel-lang/phel-lang — 一种编译为 PHP 的函数式、受 Lisp 启发的语言。支持宏、持久化数据结构、REPL。

示例

(ns my.example)

(defn greet [name]
  (str "Hello, " name "!"))

(println (greet "Phel"))
;; => Hello, Phel!

更多示例 →

数据处理管道

(def users [{:name "Ada" :age 36}
            {:name "Bob" :age 17}
            {:name "Cam" :age 41}])

(->> users
     (filter #(>= (:age %) 18))
     (map :name)
     sort)
;; => ["Ada" "Cam"]

HTTP 响应

(ns app
  (:require phel.http :as h))

(def req (h/request-from-globals))

(h/emit-response
  (h/response-from-map
    {:status 200
     :headers {"Content-Type" "text/plain"}
     :body (str "Hello " (:uri req))}))

(defmacro unless [pred & body]
  `(if (not ,pred)
     (do ,@body)))

(unless (zero? 1)
  (println "not zero"))
;; => not zero

(unless false
  (println "ok"))
;; => ok

PHP 互操作性

(ns app)

(def now (php/new \DateTime))
(.format now "Y-m-d")
;; => "2026-04-20"

(def epoch (php/new \DateTime "1970-01-01"))
(.-days (.diff now epoch))
;; => 20564

入门指南

composer require phel-lang/phel-lang
./vendor/bin/phel init # 添加 `--minimal` 可生成单文件布局

生成 phel-config.phpsrc/phel/main.pheltests/phel/main_test.phel

./vendor/bin/phel run src/phel/main.phel # 运行
./vendor/bin/phel test                   # 测试
./vendor/bin/phel repl                   # REPL
./vendor/bin/phel build                  # 编译为 PHP

内联或标准输入求值:

./vendor/bin/phel eval '(+ 1 2)' # 输出 3
echo '(println "hi")' | ./vendor/bin/phel eval -
./vendor/bin/phel eval - < script.phel

文档

  • 快速入门 — 安装、REPL、第一个脚本(5 分钟)
  • 文档索引 — 所有指南,按用途分类
  • phel-lang.org (https://phel-lang.org) — 教程、练习、博客
  • 仓库规范 · Packagist (https://packagist.org/packages/phel-lang/phel-lang)

AI 编程助手

  • resources/agents/ — Claude Code、Cursor、Codex、Gemini、Copilot、Aider
  • ./vendor/bin/phel agent-install [platform] [--all] — 为你的助手安装技能文件

构建 PHAR

./build/phar.sh 会生成 build/out/phel.phar

贡献指南

配置和工作流:CONTRIBUTING.md

架构和代码审查要求:AGENTS.md

相似文章

面向程序员的逻辑学 v0.15,现场编程

Hillel Wayne — Computer Things

Hillel Wayne 宣布其著作《Logic for Programmers》的 0.15 候选版本,并重点介绍了一场以 Strudel 和 CLAVIER-36 为特色的现场编程聚会,用于音乐编程。

PHP 的古怪特性

Hacker News Top

一位开发者在使用了五年后反思 PHP 的古怪之处,重点介绍了其数组实现和类型系统的奇特之处。

Pyrefly v1.0 正式发布

Lobsters Hottest

Pyrefly,一款开源 Python 类型检查器和语言服务器,现已发布 v1.0,标志着其达到生产就绪状态,同时带来了显著的性能提升,并被 PyTorch 和 NumPy 等主要代码库所采用。