I don't really see the point of using functional programming languages for
real production projects, though clojure is very popular now.
好问题,但也许你尝试用FP语言做一做事情,亲身体验一下,会有不同的感觉。
my point is that in a few cases you do need to operate on functions, all
languages have such features: C has function pointers, java has anonymous
inner classes, python has lambda. it's just that they do not openly
advertise them as "functional".
FP和上述冯诺依曼机式语言有好些地方不一样。最主要之一是immutable的数据结构。
个人的体会是它使得写程序减少了变量,强迫程序员用类似数学推理的方式写程序,提
高了程序的正确性。
在写Clojure程序的时候,我的体会是应该考虑“是什么”,而不是“怎么做”,这点
和冯诺依曼机式语言明显不同。
but even clojure itself does not recommend using non-named functions
recursive, but isn't operating on functions themselves the real power of
functional programming?
真的吗?我没看到这个recommend,能给个出处好么?我通常用anonymous function和
map函数配合,譬如(map #(+ x 2) (list 1 2 3)),如果有其他推荐的方法,请教教我。
clojure is popular, and handy, but I feel a large part of that comes from
the easiness of kind of using java as a scripting language , so that u don't
need to go through the compile/build/run cycle, and the iteration is much
faster, kind of like for prototyping purposes. the only real difference of
clojure to java, I feel, is the annoying prefix notation, which is
completely useless, and the syntax could have been completely re-designed to
be like most languages to give users a more natural, intuitive feeling.
The prefix notation and endless "()" is just an archaic legacy left over
from when LISP was created.
JVM的scripting language由来已久。如果你喜欢偏java格式的语法,可以尝试
beanshell, groovy。你也有其他选择比如Jython, JRuby。
简单就是美。Prefix notation使得Lisp/Clojure用统一的格式,不受语法的限制,个
人以为这正是它美的地方。而且,如果没有了Prefix notation,还如何能使用macro,
operate code as data呢?
刚接触Lisp的同学可能会有些排斥lisp古怪的括号。当你习惯了它的时候,你会喜欢上
它的。
心得:
1. 你需要一个好的编辑器,推荐emacs。NREPL,或者slime+swank-clojure让我感觉超
越了python, R的交互环境,也许你也会这么觉得。
2. 手工配对括号是很麻烦的事情,需要自动配对工具。在emacs下推荐paredit +
rainbow-delimiter。