两分钟掌握Elisp

Elisp久负"难学"的名声,
分析一下, 可能未必难在语言本身, 而是难在决策上, 在’分秒必争’的环境里去学习一种"无用之学". (颇为耐人寻味, lisp原以"实用主义"起家

且不论lisp这门古老FP语言怎样, elisp更像是shell script一般脚本语言, 堆砌命令, 区别是比bash还碎片.

本帖试图在两分钟内梳理框架结构, 节省几个小时的时间投入, 探讨crash elisp(秒一门语言)的大致思路:

承接 两分钟掌握50大章的Emacs Manual文档 - Emacs-general - Emacs China,

Elisp结构图分为 3. applications 2.text process methods 1.objects and concepts三个部分.

三.applications, 系统接口

  1. process and IPC (38章)
;;manipulate process
make(start)-process, call-process, call-proces-region
async-shell-command, shell-command,
delete-process
list-processes, get-process, list-system-processes
;;IPC
process-send-string,  signal-process (input
process-buffer, process-filter, accept-process-output (output
  1. thread(37章)
;;manipulate thread
make-thread, thread-join, thread-yield
;;lock
with-mutex, mutex-lock, mutex-unlock 
;;events
make-condition-variable
  1. I/O and File system (19, 20, 16, 25, 27
read, message, print
with-temp-buffer, insert 

  1. System service (40)
 (format-time-string "%a %b-%d %H:%M %p" (current-time))

一.Concepts and Objects

Cursor(point, mark), file, buffer, window, frame, mode, display

save-excursion, 
add-hook

二.语言构件 (略

#+BEGIN_SRC elisp
(defun fib-iter (a b count)
  (if (= count 0)
      a
      (fib-iter b (+ a b) (- count 1))
  )
)
(defun fib(n)
  (fib-iter 0 1 n))

(fib 3)
#+END_SRC
#+RESULTS:
: 2

#+BEGIN_SRC elisp

(defun factorial (n)
  (fact-iter 1 1 n))

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

(factorial 3)
#+END_SRC
#+RESULTS:
: 6

参考资料:

4 个赞

这不就是Elisp Reference目录?还是阉割版的

其实,大部分(自认)学不好Elisp,都是被lisp一堆括号有本能的偏见,恐惧。

另外,说lisp比sh更琐碎的,我怀疑你有没有写过100行以上的两个语言

2 个赞

这也太标题党了吧。

你多说了一行

我觉得没有哦

对于一个学过一门有一定支持函数式编程范式的语言的人来说,两分钟掌握Elisp的core part并不是什么难事。然而你这洋洋洒洒列的一大堆东西(进程管理,进程间通信,Emacs的buffer交互)首先它们的内涵是语言无关的,其次他们的表征(API,最佳实践)各种语言上是有差异的,根本不可能两分钟掌握。更何况一个没有先学过一门PL的人,两分钟连Elisp的core part都没法掌握。

不能妖魔化lisp,但lisp也不是随便看一眼就能学会的,那种是云程序员。

我寻思你都要两分钟掌握了,这种东西就别从略了

追根溯源lisp就不是实用主义起家的,原来是要做一个简单的符号推演语言,比COBOL啊C啊Fortran这些花里胡哨多了。最早开始搞lisp实用主义的大概是RMS他老人家吧。你这卖广告广告词都弄歪来。

什么叫”比Bash更碎片“?不要整这些春秋笔法

还有比shell更琐碎的? shell里充满各种黑魔法和写法不一致的地方…

1 个赞

实用主义的解释 Structure and Interpretation of Computer Programs

Despite its inception as a mathematical formalism, Lisp is a practical programming language.

Lisp was not the product of a concerted design effort. Instead, it evolved informally in an experimental manner in response to users’ needs and to pragmatic implementation considerations. Lisp’s informal evolution has continued through the years, and the community of Lisp users has traditionally resisted attempts to promulgate any ``official’’ definition of the language. This evolution, together with the flexibility and elegance of the initial conception, has enabled Lisp, which is the second oldest language in widespread use today (only Fortran is older), to continually adapt to encompass the most modern ideas about program design. Thus, Lisp is by now a family of dialects, which, while sharing most of the original features, may differ from one another in significant ways. The dialect of Lisp used in this book is called Scheme.2

在SICP这本书要讲的东西里,相对晦涩的数学符号,lisp可以算很pratical了,要是真那么pratical,就不会有py魔改版SICP了。

第二段意思是lisp有个很能折腾(分裂)的社区,和pratical与否有什么关系

这是practical. 从实用出发.

你该看看McCarthy发lisp的那篇论文

看来不用我来批这句话,已经有人出来批了。

区别是比bash还碎片.