我想用非常短的语法编写一个 DSL,用于我注意到对编程非常重要的两件事,函数和哈希。这是我的设计:
创建一个哈希:
(a:1 b:2 c:3)
Same as JavaScript's: {a:1,b:2,c:3}
创建有序哈希,省略键:
(x y 5)
Same as JavaScript's: {0:'x', 1:'y', 2:5}
创建一个匿名函数:
(a?)
Same as JavaScript's: (function(x){ return x.a; })
Example application:
((test a? b?) (a:1 b:2 c:3))
>> Outputs (test 1 2)
嵌套函数:
(a? a?')
Same as JavaScript's: (function(obj1){ return function(obj2) { return [obj1.a,obj2.a]; }; })
Example double-application:
(((a? a?') (a:1)) (a:2))
Is reduced to: ((1 a?) (a:2))
Then outputs: (1 2)
哪种语言适合实现这种 DSL?