lisp語言是最好的語言_Lisp可能不是數據科學的最佳語言,但是我們仍然可以從中學到什么呢?...

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符號實際上可以是*任何*。

Image for post
Syme examples of lisp symbols
Lisp符號的Syme示例

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模式)結合使用。

演示地址

Paredit mode demonstration (jump to 0:35)
演示模式演示(跳至0:35)

The alternative in other languages happens to be

其他語言的替代品恰好是

  1. Hold your mouse and place the cursor at the start of the code block.

    按住鼠標并將光標置于代碼塊的開頭。
  2. Drag your mouse to the end of the code block

    將鼠標拖到代碼塊的末尾
  3. Ctrl+X

    Ctrl + X
  4. 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代碼看起來沒有其他文章所述的方式不易理解。 這是相同的代碼,已完成并格式化。

Image for post
Better formatted lisp with paren-face-mode (with slightly different building blocks)
使用paren-face-mode格式更好的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語法不是特別適合共享數學代碼是客觀的。

Image for post
Math infix vs prefix
數學中綴與前綴

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代碼。

Image for post
infix notation in lisp using cmu-infix
使用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

您通常的開發周期包括

  1. Write/Edit code.

    編寫/編輯代碼。
  2. (Optionally) Compile.

    (可選)編譯。
  3. 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秒以內,除非您可能正在系統基礎上做某事。

演示地址

An excelllent demonstration of SLIME
SLIME的出色示范

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一樣快的速度。

Image for post
A comparison of SBCL against numpy
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,一經查實,立即刪除!

相關文章

鏈接訪問后刷新顏色回到初始_如何使鏈接可訪問(提示:顏色不夠)

鏈接訪問后刷新顏色回到初始Link accessibility is one of the most important aspects of usability. However, designers often dont understand what it takes to make links accessible. Most frequently, they only distinguish links by color, which makes it hard for …

567

567 轉載于:https://www.cnblogs.com/Forever77/p/11519678.html

leetcode 403. 青蛙過河(dp)

一只青蛙想要過河。 假定河流被等分為若干個單元格,并且在每一個單元格內都有可能放有一塊石子(也有可能沒有)。 青蛙可以跳上石子,但是不可以跳入水中。 給你石子的位置列表 stones(用單元格序號 升序 表示&#xff…

static、volatile、synchronize

原子性(排他性):不論是多核還是單核,具有原子性的量,同一時刻只能有一個線程來對它進行操作!可見性:多個線程對同一份數據操作,thread1改變了某個變量的值,要保證thread2…

tensorflow基本教程

轉載自 http://tensornews.cn/ 轉載于:https://www.cnblogs.com/Chris-01/p/11523316.html

1.10-linux三劍客之sed命令詳解及用法

內容:1.sed命令介紹2.語法格式,常用功能查詢 增加 替換 批量修改文件名第1章 sed是什么字符流編輯器 Stream Editor第2章 sed功能與版本處理出文本文件,日志,配置文件等增加,刪除,修改,查詢sed --versionsed -i 修改文件內容第3章 語法格式3.1 語法格式sed [選項] [sed指令…

python pca主成分_超越“經典” PCA:功能主成分分析(FPCA)應用于使用Python的時間序列...

python pca主成分FPCA is traditionally implemented with R but the “FDASRSF” package from J. Derek Tucker will achieve similar (and even greater) results in Python.FPCA傳統上是使用R實現的,但是J. Derek Tucker的“ FDASRSF ”軟件包將在Python中獲得相…

blender視圖縮放_如何使用主視圖類型縮放Elm視圖

blender視圖縮放A concept to help Elm Views scale as applications grow larger and more complicated.當應用程序變得更大和更復雜時,可幫助Elm Views擴展的概念。 In Elm, there are a lot of great ways to scale the Model, and update, but there is more c…

初探Golang(2)-常量和命名規范

1 命名規范 1.1 Go是一門區分大小寫的語言。 命名規則涉及變量、常量、全局函數、結構、接口、方法等的命名。 Go語言從語法層面進行了以下限定:任何需要對外暴露的名字必須以大寫字母開頭,不需要對外暴露的則應該以小寫字母開頭。 當命名&#xff08…

789

789 轉載于:https://www.cnblogs.com/Forever77/p/11524161.html

sql的split()函數

ALTER function [dbo].[StrToList_Test](Str varchar(max), fg NVARCHAR(200)) returns table table(value nvarchar(max) ) as begindeclare tempStr nvarchar(max),len INT LEN(fg); --去除前后分割符 while substring(Str,1,len)fg beginset Strsubstring(Str,len1,len(S…

大數據平臺構建_如何像產品一樣構建數據平臺

大數據平臺構建重點 (Top highlight)Over the past few years, many companies have embraced data platforms as an effective way to aggregate, handle, and utilize data at scale. Despite the data platform’s rising popularity, however, little literature exists on…

初探Golang(3)-數據類型

Go語言擁有兩大數據類型,基本數據類型和復合數據類型。 1. 數值類型 ##有符號整數 int8(-128 -> 127) int16(-32768 -> 32767) int32(-2,147,483,648 -> 2,147,483,647) int64&#x…

freecodecamp_freeCodeCamp的服務器到底發生了什么?

freecodecampUpdate at 17:00 California time: We have now fixed most of the problems. Were still working on a few known issues, but /learn is now fully operational.加利福尼亞時間17:00更新 :我們現在解決了大多數問題。 我們仍在處理一些已知問題&#…

為什么Linux下的環境變量要用大寫而不是小寫

境變量的名稱通常用大寫字母來定義。實際上用小寫字母來定義環境變量也不會報錯,只是習慣上都是用大寫字母來表示的。 首先說明一下,在Windows下是不區分大小寫的,所以在Windows下怎么寫都能獲取到值。 而Linux下不同,區分大小寫&…

python:連接Oracle數據庫后控制臺打印中文為??

打印查詢結果,中文顯示為了??? [(72H FCR, 2.0), (?????, 8.0)] E:\Python35\Lib\site-packages中新增文件: sitecustomize.py import os os.environ[NLS_LANG] SIMPLIFIED CHINESE_CHINA.UTF8 轉載于:https://w…

時間序列預測 時間因果建模_時間序列建模以預測投資基金的回報

時間序列預測 時間因果建模Time series analysis, discussed ARIMA, auto ARIMA, auto correlation (ACF), partial auto correlation (PACF), stationarity and differencing.時間序列分析,討論了ARIMA,自動ARIMA,自動相關(ACF),…

初探Golang(4)-map和流程控制語句

1.map map 是引用類型的,如果聲明沒有初始化值,默認是nil。空的切片是可以直接使用的,因為他有對應的底層數組,空的map不能直接使用。需要先make之后才能使用。 //1, 聲明map 默認值是nil var m1 map[key_data_type]value_data_type 聲明 …

網絡傳輸之TCP/IP協議族

我們現實網絡無處不在,我們被龐大的虛擬網絡包圍,但我們卻對它是怎樣把我們的信息傳遞并實現通信的,我們并沒有了解過,那么當我們在瀏覽器中出入一段地址,按下回車這背后都會發生什么? 比如說一般場景下&am…

(58)PHP開發

LAMP0、使用include和require命令來包含外部PHP文件。使用include_once命令,但是include和include_once命令相比的不足就是這兩個命令并不關心請求的文件是否實際存在,如果不存在,PHP解釋器就會直接忽略這個命令并且顯示一個錯誤消息&#xf…