Show HN: eli - 嵌入式 Lisp 解释器
Navigation Menu
Toggle navigation Sign in
- Product
- GitHub Copilot Write better code with AI
- Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less Explore
- All features
- Documentation
- GitHub Skills
- Blog
- Solutions By company size
- Resources Topics
- Open Source
- Enterprise
- Pricing
Search or jump to...
Search code, repositories, users, issues, pull requests...
Search Clear Search syntax tips
Provide feedback
We read every piece of feedback, and take your input very seriously. Include my email address so I can be contacted Cancel Submit feedback
Saved searches
Use saved searches to filter your results more quickly
Name Query To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up Reseting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} codr7 / **eli ** Public
- Notifications You must be signed in to change notification settings
- Fork 0
- Star 13
Embedded Lisp Interpreter
License
MIT license 13 stars 0 forks Branches Tags Activity Star Notifications You must be signed in to change notification settings
Additional navigation options
codr7/eli
main BranchesTags Go to file Code
Folders and files
Name| Name| Last commit message| Last commit date
---|---|---|---
Latest commit
History
109 Commits
benchmarks| benchmarks
tests| tests
LICENSE.txt| LICENSE.txt
README.md| README.md
TODO.org| TODO.org
View all files
Repository files navigation
eli
Introduction
eli
代表了 15 年来在各种语言中设计和实现嵌入式 Lisp 解释器的结晶。
这一切都始于渴望一个用于个人项目的嵌入式 Lisp,但演变成了我乐于投入的最深的兔子洞之一。
Implementations
以下项目在不同的语言中实现了 eli
,有些比其他的更完整。 目前,大部分工作都在 eli-java 中进行。
我还致力于将一些 eli
魔法添加到 Common Lisp 中。
Performance
我早先决定将 Python 作为合理的性能目标,因为它主要是解释型的并且非常出名。
$ python3 benchmarks/run.py
fact 1.689405483
fib 0.634149815
Java
$ java -jar eli.jar benchmarks/run.eli
fact 1.682860949
fib 1.568288647
Language
Types
Any
Bit (Any)
Callable
Comparable
Countable
Char (Any)
Expr (Any)
Float (Any Numeric)
Int (Any Numeric)
Iter (Any Iterable)
Iterable
Lib (Any)
List (Any Callable Comparable Countable Iterable Sequential)
Macro (Any Callable)
Map (Any Callable Comparable Countable Iterable Sequential)
Meta (Any)
Method (Any Callable)
Nil
Numeric (Any Comparable)
Pair (Any Comparable Countable Iterable Sequential)
Sequential
String (Any Callable Comparable Countable Iterable Sequential)
Sym (Any Comparable)
Time (Any)
Timestamp (Any)
Truthiness
所有值都有 Bit
表示,大多数评估为 T
; 这些值被称为 truthy。 除了 F
之外,值得注意的例外是空字符串、列表; 0
和 _
。
Branches
(if T 1)
1
(if F 1)
_
else
可用于提供备用分支。
(if F 1 (else 2))
2
else-if
可用于减少嵌套。
(if F 1 (else-if F 2 3))
3
Quoting
'(+ 1 2)
'(+ 1 2)
引用的列表会变成引用的项目列表。
'[foo bar baz]
['foo 'bar 'baz]
,
取消引用后面的形式。
(let [foo '(+ 1 2)]
,foo)
3
Bindings
(var foo 42)
foo
42
let
可用于创建作用域绑定,
(let [foo 'bar]
foo)
'bar
以及覆盖现有的 var
绑定。
(var foo 1)
foo
1
(^baz [] foo)
(let [foo 2] (baz))
2
foo
1
let
和 var
都支持对结构。
(let [i:j 1:2]
i:j)
1:2
set
更新现有绑定的值。
(let [foo 1 bar 2]
(set foo 2 bar 3)
foo:bar)
3:4
Iterators
Imperative
(let [foo 0]
(iter/for [i [1 2 3]
(inc foo i))
foo)
6
可以并行迭代多个序列。
(let [foo 0 bar 0]
(iter/for [i [1 2 3]
j [4 5]]
(inc foo i)
(inc bar j))
foo:bar)
6:9
只要指定的条件为 truthy,while
就会重复其主体。
(let [foo 0]
(iter/while (< foo 10)
(inc foo))
foo)
break
评估其参数并跳转到循环的末尾。
(let [foo 0]
(iter/while T
(if (= (inc foo) 10)
(break (* foo 2)))))
20
next
评估其参数并跳转到下一次迭代的开始。
(let [foo 0]
(iter/while T
(if (< (inc foo) 10)
(next))
(break (* foo 2))))
20
Functional
[(iter/comb [1 2 3])*]
[[1] [2] [1 2] [3] [1 3] [2 3] [1 2 3]]
cross
返回一个迭代器,用于两个可迭代对象的叉积。
[(iter/cross + [1 2] [3 4])*]
[4 5 5 6]
fold
使用指定的二元运算和种子值将可迭代对象折叠为单个值。
(^my-sum [in*]
(iter/fold + in 0))
(my-sum 1 2 3)
6
map
返回一个迭代器,用于映射到一组可迭代对象的方法。
[(iter/map + [1 3] [5 7 11])*]
[6 10]
where
返回一个迭代器,用于从一组可迭代对象中匹配谓词的项目。
[(iter/where > [1 5 2 6] [1 2 3 4])*]
[5:2 6:4]
unzip
将一对可迭代对象拆分为一对列表。
(iter/unzip [1:2 3:4])
[1 3]:[2 4]
Methods
(^foo [x]
x)
(foo 42)
42
Arguments
(^foo [x y?]
(say x " " y))
(foo 1 2)
(foo 3)
1 2
3 _
在最后一个参数后添加 *
后缀,使该方法能够接受可变数量的参数。
(^foo [x*]
(+ x*))
(foo 35 7)
Result
(^foo [x]
x)
(foo 42)
42
return
评估其参数并跳转到当前方法的末尾。
(^foo [] 1 (return 2 3) 4)
(foo)
3
返回对的方法支持调用站点解构。
(^foo []
1:2:3)
(foo:_)
1
(_:_:foo)
3
(_:foo)
2:3
Overloading
方法支持重载。 调用时; 选择最具体的、最新的、匹配的定义。
(^foo [x]
(say "x 1"))
(^foo [x y]
(say "x y"))
(foo 1)
(^foo [x]
(say "x 2"))
(foo 1)
(foo 1 2)
x 1
x 2
x y
Lambdas
(^[] 42)
(^repl@1:1 [])
IO
(say "35+7=" (+ 35 7))
35+7=42
Type Checking
(+ 35 7)@Numeric
42
如果类型不兼容,则会发出错误信号。
42@String
Error in REPL@1:3: Type check failed, expected String: 42
支持绑定。
(let [foo@Int 42]
foo]
42
以及方法参数。
(^foo [x@Int]
x)
(foo 42)
42
Libraries
(lib foo
(var bar 42))
foo/bar
42
import
将外部绑定提取到当前命名空间中。
(import f/bar)
bar
42
目标 ID 可以被覆盖。
(import foo:f)
f/bar
42
Loading
42
include
在编译时发出外部文件的内容。
(include "test.eli")
42
load
在运行时评估外部文件的内容。
(load "test.eli")
42
Testing
(check 1 2)
Error in REPL@1:1: Check failed; expected 1, actual: 2
Work
如果您发现自己参与了一个软件项目,该项目具有有趣的非 GenAI 挑战,并且需要一位具有 40 年不同技术/角色/公司/国家/地区丰富经验的创意开发人员/技术/团队负责人,请随时联系。
About
Embedded Lisp Interpreter
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published
Languages
Footer
Footer navigation
You can’t perform that action at this time.