Higher-order functions in Javascript

In Javascript, functions are just like the other variables(AKA first-class citizen), and here are several interesting tricks implemented by treating functions as first-class citizen. currying Currying is for partial evaluation, a practical example is Function.prototype.bind() in Javascript: And we can implement bind()(under this circumstance only of course) by ourselves: trampolining Javascript(ES5) does not implement tail call optimization, … Continue reading "Higher-order functions in Javascript"

Read More

javascript 解析 lisp 表达式

问题 项目中需要前端解析出 lisp 表达式中的内容后,渲染到页面上: 解决 同事离职前实现了一版,思路是使用正则表达式捕获住对应的内容,缺点也是显而易见的:不够灵活。我参考了 (How to Write a (Lisp) Interpreter (in Python)) 中的实现,完成了一版 javascript 的实现。 函数 tokenize 用于将字符串预处理成统一的形式: 函数 read_from_tokens 负责将字符串解析成对应的数据: 工具函数 atom 负责处理变量类型相关的工作: 看下效果,还不错:

Read More