lisp語言是最好的語言
This article is in response to Emmet Boudreau’s article ‘Should We be Using Lisp for Data-Science’.
本文是對 Emmet Boudreau的文章“我們應該將Lisp用于數據科學”的 回應 。
Below, unless otherwise stated, lisp refers to Common Lisp; in general, lisp refers to the lisp family of languages, just like the C-family of languages. There are functional lisps like Clojure and Scheme, and there are general purpose lisps such as Common Lisp and Racket.
以下,除非另有說明,否則lisp指的是Common Lisp; 通常,lisp指的是 lisp語言家族 ,就像 C語言家族 一樣 。 有諸如Clojure和Scheme之類的功能性lipps,還有諸如Common Lisp和Racket之類的通用lisps。
The primary hurdle to using Lisp for Data Science, I believe, is the non-infix syntax common in mathematics.
我相信,使用Lisp進行數據科學的主要障礙是數學中常見的非中綴語法。
[Edit: Added note about parentheses balancing wrt paredit, and mentioned slima for atom. A redone note about formatting lisp code. Mention of PAIP. Thanks to comments at r/lisp!]
[ 編輯:添加了有關括號與wrt paredit平衡的注釋,并提到了原子的slima。 關于格式化Lisp代碼的重做說明。 提及PAIP。 感謝r / lisp的評論 !]
但是,有什么要學習的語法嗎? (But, is there anything to learn from its syntax?)
Lisp base syntax follows prefix notation and “everything is a list” convention. In this notation, the first element of the list is the operator while the remaining elements are the operands.
Lisp基本語法遵循前綴表示法,并且“一切都是列表”約定。 在此表示法中,列表的第一個元素是運算符,而其余元素是操作數。
To some, the lack of commas in lisp can feel cleaner than their presence in non-lisps. YMMV.
在某些情況下,與沒有口吻的人相比,沒有口吻的人感覺更干凈。 YMMV。
Further, lisp symbols can actually be *anything*.
此外,lisp符號實際上可以是*任何*。

The lisp reader is also, by default, case insensitive; so you don’t need to bother about whether something is called “fooBar” or “foobar” or “FOOBar”. It’s usually just “foo-bar”. Hyphens also feel more natural than underscores. In daily language, we rarely use — at least I don’t — underscores; but hyphens just feel more natural while writing compound-words.
默認情況下,lisp閱讀器也不區分大小寫; 因此,您不必為某個東西叫做“ fooBar”還是“ foobar”還是“ FOOBar”而煩惱。 通常只是“ foo-bar”。 連字符也比下劃線更自然。 在日常語言中,我們很少使用-至少我不使用-下劃線; 但是連字在寫復合詞時會感覺更自然。
All of that is significantly subjective. Where lisp shines is when it is used in conjunction with a structured editing mode like the paredit mode.
所有這些都是主觀的。 Lisp的亮點是與結構化編輯模式(如paredit模式)結合使用。
演示地址
The alternative in other languages happens to be
其他語言的替代品恰好是
- Hold your mouse and place the cursor at the start of the code block. 按住鼠標并將光標置于代碼塊的開頭。
- Drag your mouse to the end of the code block 將鼠標拖到代碼塊的末尾
- Ctrl+X Ctrl + X
- Ctrl+V Ctrl + V
That’s about 100–300% more effortful than if you know paredit. And if you are gonna be alive for more than a decade, paredit is definitely worth the learning! Plus, did you notice that you do not need to count parentheses? The editor keeps track of it for you! Even for non-lisps, there are equivalent modes like smartparens-strict-mode you could help yourself with.
這比您知道paredit時要省力100–300%。 而且,如果您要活著超過十年,那么paredit絕對值得學習! 另外,您是否注意到您不需要計算括號? 編輯器會為您跟蹤它! 即使對于非嘴唇,也可以使用smartparens-strict-mode等等效模式來幫助自己。
But is this something unique to lisp? No, in fact, there is a related open issue for julia. So, if you did understand the power of paredit, do try smartparens-strict-mode or equivalent with other languages!
但這是Lisp獨有的東西嗎? 不,事實上, 茱莉亞 有一個 相關的公開問題 。 因此,如果您確實了解paredit的功能,請嘗試使用smartparens-strict-mode或其他語言的等效語言!
Idiomatic lisp code looks nothing unreadable the way the other article states. Here’s the same code, completed and formatted.
慣用的Lisp代碼看起來沒有其他文章所述的方式不易理解。 這是相同的代碼,已完成并格式化。

On the extensibility of lisp syntax
關于Lisp語法的可擴展性
Lisp is characterized by its extreme extensibility. You can extend the reader. You can introduce new syntax.
Lisp的特點是具有極高的可擴展性。 您可以擴展閱讀器。 您可以引入新的語法。
I’d also consider it to be objective that the prefix lisp syntax isn’t particularly well suited to sharing mathematical code.
我還認為前綴Lisp語法不是特別適合共享數學代碼是客觀的。

In almost all written mathematics, the prefix syntax in code and paper/text-book takes away the overhead of checking whether you typed the expression correctly. I, as a lisper, don’t find the former syntax to be “harder” than the latter; if anything, it states exactly what is to be done — namely, we have to add 5, x, and another expression. However, that isn’t how I find mathematics written in books!
在幾乎所有的書面數學中,代碼和紙質/教科書中的前綴語法消除了檢查是否正確鍵入表達式的開銷。 我作為一個傻子,沒有發現前一種語法比后者更“硬”。 如果有的話,它確切說明了要執行的操作-即,我們必須添加5,x和另一個表達式。 但是,這不是我發現書本中寫的數學的方法!
But lisp is extensible. There is a library called cmu-infix that introduces the required mathematical syntax; so the following is perfectly valid lisp code once you use it.
但是Lisp是可擴展的。 有一個名為cmu-infix的庫,它引入了所需的數學語法。 因此,以下是使用后完全正確的Lisp代碼。

And that is hardly different from the math syntax above!
這與上面的數學語法幾乎沒有什么不同!
However, in 2020, in my opinion, cmu-infix needs more polishing, particularly to deal with array slicing. And, it’d be great to have superscripts to mean power too, just very like usual mathematics!
但是,我認為,到2020年,cmu-infix需要更多地拋光,尤其是要處理陣列切片時。 而且,也很像上一門數學一樣,有上標也能表示冪!
Quicklisp和Ultralisp (Quicklisp, and Ultralisp)
Where I found myself significanly disagreeing with the author was on quicklisp. Quicklisp is one of the best package management I’ve known, thanks to its guarantee that “all packages build together”. So, as long as you haven’t moded your lisp system, loading a library is as simple as (ql:quickload “library”). This is actually a dist system, akin to what one’d find with the linux package system apt. There are almost monthly updates to quicklisp, and if something does break due to the upgrade, you simply go back to a known working dist.
我發現自己明顯不同意作者的觀點是在quicklisp上。 Quicklisp是我所知最好的軟件包管理之一,這要歸功于它保證“所有軟件包都可以一起構建”。 因此,只要您沒有設置Lisp系統的模式,加載庫就和(ql:quickload“ library”)一樣簡單。 這實際上是一個dist系統,類似于linux軟件包apt中的系統。 quicklisp幾乎每月都有更新,并且如果由于升級而導致某些問題確實中斷了,您只需回到已知的工作區即可。
Quicklisp works with ABCL, Allegro CL, Clasp, Clozure CL, CLISP, CMUCL, ECL, LispWorks, MKCL, SBCL, and Scieneer CL, on Linux, Mac OS X, and Windows.
Quicklisp可與ABCL , 快板CL , 扣 , Clozure CL , CLISP , CMUCL , ECL , LispWorks , MKCL , SBCL和Scieneer CL ,在Linux,Mac OS X和Windows。
So, I don’t really get the author’s point about using a quicklisp compatible compiler. It’s just ubiquitous!
因此,我并沒有真正理解作者使用與quicklisp兼容的編譯器的觀點。 隨處可見!
The monthly update cycle can, indeed, be painful for projects in active development; for which, there happens to be ultralisp, that updates every 5 min!
實際上,每月更新周期對于正在積極開發的項目可能確實很痛苦; 為此,每5分鐘更新一次Ultralisp !
Of course, there are facilities like qlot to help manage dependencies, if quicklisp dists ever happen to be insufficient for you.
當然,如果quicklisp dists碰巧不足以幫助您解決問題,則可以使用qlot之類的工具來幫助管理依賴項。
還有什么? (What else?)
While macros are one thing, I don’t tend to find them of as much use as SLIME.
雖然宏是一回事,但我并不傾向于發現它們的用途與SLIME一樣多。
Your usual development cycle consists of
您通常的開發周期包括
- Write/Edit code. 編寫/編輯代碼。
- (Optionally) Compile. (可選)編譯。
- Run and debug. 運行和調試。
I’ve found myself waiting for 10 sec on the smallest of changes while working on a largish python system. SLIME is a god-send in that it takes this waiting period to under 1 sec, unless perhaps you are doing something in the base of your system.
我發現自己在使用大型python系統時,等待最小變化的時間為10秒。 SLIME是一個天賜良機,因為它將等待時間縮短到1秒以內,除非您可能正在系統基礎上做某事。
演示地址
Are there alternatives in other languages? Sorta yes. In python, if you fire up a REPL inside emacs, it is connected to python buffers; however, the lack of a lisp like package system limits this to single file workflows. For julia, there is julia-snail.
是否有其他語言的替代品? 排序是的。 在python中,如果您在emacs中啟動REPL,它將連接到python緩沖區; 但是,缺少像Lisp這樣的軟件包系統,將其局限于單個文件工作流程。 對于茱莉亞,有茱莉亞蝸牛 。
What about jupyter notebooks? Consider SLIME to be the next step in the jupyter-notebooks evolution :p. Okay, one place where jupyter notebooks (can) shine is when you need to display images and graphs to management folks. Though, emacs-ers do have the awesome org-mode for the same, that does allow inline latex and images, and multiple language blocks in a single file. YMMV.
那么Jupyter筆記本呢? 認為SLIME是jupyter-notebooks進化的下一步:p。 好吧,當您需要向管理人員顯示圖像和圖形時,jupyter筆記本(可以)發光的一個地方。 盡管emacs-ers確實具有出色的org-org模式,但確實允許內聯乳膠和圖像以及單個文件中的多種語言塊。 YMMV。
看到? 您學到了很多東西,卻沒有真正學過一口氣。 (See? You learnt so many things without actually learning a lisp?)
Well, I’d say you are already about one-third way on your path to learning lisp. May be help yourself learning the full thing!
好吧,我想說您已經走近了學習口齒不清的道路上的三分之一。 可能會幫助您學習完整的東西!
那圖書館呢? (What about libraries?)
In theory, it is entirely possible to write SBCL that is almost as performant as C. For instance, one of my past-times has been working on a library called numericals that gets at least as fast as numpy using SBCL.
從理論上講,完全有可能編寫出與C 幾乎一樣性能的SBCL。例如,我過去的一個時光一直在研究一個稱為“ 數值”的庫,使用SBCL至少可以得到與numpy一樣快的速度。

While, not tested for performance by me, there are much more complete libraries like clml for machine learning.
雖然沒有經過我的性能測試,但還有更多完整的庫(例如clml)可用于機器學習。
Depending on your use case, you might also find py4cl2 suitable for you. py4cl brings python libraries to common lisp, with quite a few limitations; check if those limitations apply to you!
根據您的用例,您可能還會發現適合您的py4cl2 。 py4cl將python庫帶到了常見的lisp中,但有很多限制; 檢查這些限制是否適用于您!
In practice, in fact, lisp was never a go to language for machine learning! Lisp has been the language of the pre-ML AI — Norvig’s Paradigm of Artificial Intelligence is a great read for anyone interested in what AI was before the dawn of Machine Learning.
實際上,實際上,lisp絕不是機器學習的語言! Lisp一直是ML之前的AI的語言-對于在機器學習曙光之前對AI感興趣的人來說, Norvig的《人工智能范式》是一本好書。
That said, the take home message is: structured editing, quicklisp-like package system, and SLIME. If lisp does interest you, take a look at some of its defacto libraries — the Getting Started sections of cl-who, cl-ppcre, fiveam, iterate and alexandria in very particular.
也就是說,帶回家的消息是:結構化編輯,類似quicklisp的打包系統和SLIME。 如果lisp引起您的興趣,請查看 其一些事實上的庫 -cl-who,cl-ppcre,fiveam,iterate和alexandria的入門部分。
The bonus of working with lisp is that, if your needs are met by the ANSI standard, or perhaps some well solidified defacto libraries, then you can avoid yourself the pain of upgrading your projects due to “language upgrades”. ANSI standardization was complete in 1994; and quite a few projects from the pre-2000s can still run in ANSI-conforming implementations in 2020.
使用lisp的好處是,如果ANSI標準或某些可靠的事實庫滿足了您的需求,那么您可以避免由于“語言升級”而導致的項目升級麻煩。 ANSI標準化工作于1994年完成; 而且2000年以前的許多項目仍可以在2020年以符合ANSI的實施方式運行。
If Common Lisp does interest you, The Common Lisp Cookbook and Practical Common Lisp, coupled perhaps with Baggers’ videos are some of the several excellent resources to get started. If you ever need help with anything, the community is welcoming at r/CLSchools! Of course, there’s the more general purpose r/lisp, and the more familiar stackoverflow.
如果您對Common Lisp感興趣,可以參考Common Lisp食譜和實用Common Lisp以及Baggers的視頻,這是一些不錯的入門資源。 如果您需要任何幫助,歡迎訪問r / CLSchools ! 當然,有更通用的r / lisp和更熟悉的stackoverflow 。
And, if you find emacs to be curve, there is SLIMA for Atom as well.
而且,如果您發現emacs可以彎曲,那么Atom也可以使用SLIMA 。
Hope you have a good day!
希望你有美好的一天!
翻譯自: https://medium.com/@shubhamkarayare/lisp-may-not-be-the-best-language-for-data-science-but-what-can-we-still-learn-from-it-528024114e02
lisp語言是最好的語言
本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。 如若轉載,請注明出處:http://www.pswp.cn/news/391261.shtml 繁體地址,請注明出處:http://hk.pswp.cn/news/391261.shtml 英文地址,請注明出處:http://en.pswp.cn/news/391261.shtml
如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!