首页 > Web开发 > 详细

s表达式和json表达式

时间:2014-04-26 16:11:39      阅读:572      评论:0      收藏:0      [点我收藏+]

s表达式 + 1 2 3
普通表达式 1+2+3
json表达式
{
+:[1, 2, 3]
}
优点,一个运算符,无限个参数

 

s表达式 * (+ 1 2) 3
普通表达式 1+(2*3)
json表达式
{
*:[{+:[1,2]} , 3]
}
优点,阅读代码的时候,无需记住运算优先级。普通表达式则要记住运算优先级


s表达式判断 if (< x 0) (-x) (x)
普通表达式 if(x<0){return -x} else{return x}
json表达式
{
if:[{ <: [x,0]}, -x, x]
}


s表达式and判断 if (and (> x 0) (< x 10)) (-x) (x)
json表达式
{
if: [ {and: [{>:[x, 0]} , {<: [x, 10]} ]}, -x, x]
}

s表达式的递归
define (factorial n)
(if (= n 1))
(1)
(* n (factorial (- n 1)))
json表达式
{
define: [{factorial:n}, {if:[{=:[n, 1]}, 1, {*:[n, {factorial:[{-:[n, 1]}] }]} ]}]
}

 


s表达式的迭代
define (factorial n) (fact-iter 1 1 n)
{
define:[{factorial:n}, {fact-iter:[1, 1, n]}]
}

define (fact-iter product counter max-count)
(if (> counter max-count))
(product)
(fact-iter (* counter product)) (+ counter 1) (max-count)))

 

s表达式和json表达式,布布扣,bubuko.com

s表达式和json表达式

原文:http://www.cnblogs.com/samwu/p/3690428.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!