TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Is Lisp Simple?

7 点作者 erlich超过 1 年前
I thought Lisp was suppose to be simple in that: it&#x27;s all just lists.<p>I thought everything would just be s-expressions, and be consistent, so it would be easy to read to figure out what is going on.<p>But it seems like there are so many special constructs and macros, that make it hard to read. And behind the scenes of these macros it gets really complicated. Whereas in other languages its readable the whole way down.<p>E.g. How am I suppose to read this? How does it de-construct to s-expressions...and does it even? What is implemented natively in the interpreter? Does that language have built-in keywords?<p>I thought everything was suppose to be like: `(left . (left . right) )`.<p><pre><code> (loop for i in &#x27;(1 2 3) when (&gt; i 1) return i) </code></pre> It seems as if there are actually a ton more special case primitives I need to know, when I could get away with a lot less syntax in other languages to be productive.<p>Like maybe there is some simplicity at the very bottom, but that doesn&#x27;t seem to matter in day-to-day programming.<p>Another example, the first think I see when I look at the language basics of how to make a function:<p>https:&#x2F;&#x2F;lispcookbook.github.io&#x2F;cl-cookbook&#x2F;functions.html:<p><pre><code> (defun &lt;name&gt; (list of arguments) &quot;docstring&quot; (function body)) </code></pre> How do I read this as an s-expression?

8 条评论

arethuza超过 1 年前
The loop macro is an interesting example as its pretty much a mini language within Lisp just for looping purposes that <i>doesn&#x27;t</i> use the normal s-expression based syntax - which is either a bad thing or a great example of how powerful Lisp can be... Personally, when I used to write Common Lisp for a living (a long long time ago) I was very fond of loop.<p>As for &quot;it&#x27;s all just lists&quot; - Common Lisp directly supports a variety of different mechanisms for structuring data, including the rather wonderful CLOS.
评论 #37212426 未加载
PaulHoule超过 1 年前
It&#x27;s simpler than most languages that have a generative grammar.<p>If you really want to understand it I&#x27;d suggest reading this<p><a href="https:&#x2F;&#x2F;groups.csail.mit.edu&#x2F;mac&#x2F;ftpdir&#x2F;scheme-7.4&#x2F;doc-html&#x2F;scheme_toc.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;groups.csail.mit.edu&#x2F;mac&#x2F;ftpdir&#x2F;scheme-7.4&#x2F;doc-html&#x2F;...</a><p>and reading it again, thinking about it, writing some code, reading it again and such. It is astonishing short for a specification for a real programming language and will become clear to you if you live with it. I count 30 &quot;special forms&quot; in there<p><a href="https:&#x2F;&#x2F;groups.csail.mit.edu&#x2F;mac&#x2F;ftpdir&#x2F;scheme-7.4&#x2F;doc-html&#x2F;scheme_3.html#SEC29" rel="nofollow noreferrer">https:&#x2F;&#x2F;groups.csail.mit.edu&#x2F;mac&#x2F;ftpdir&#x2F;scheme-7.4&#x2F;doc-html&#x2F;...</a><p>and 24 in the Common Lisp spec<p><a href="https:&#x2F;&#x2F;www.cs.cmu.edu&#x2F;Groups&#x2F;AI&#x2F;html&#x2F;cltl&#x2F;clm&#x2F;node59.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;www.cs.cmu.edu&#x2F;Groups&#x2F;AI&#x2F;html&#x2F;cltl&#x2F;clm&#x2F;node59.html</a><p>although this claims the minimum is 9<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;3482389&#x2F;how-many-primitives-does-it-take-to-build-a-lisp-machine-ten-seven-or-five" rel="nofollow noreferrer">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;3482389&#x2F;how-many-primiti...</a><p>See also<p><a href="http:&#x2F;&#x2F;www.paulgraham.com&#x2F;rootsoflisp.html" rel="nofollow noreferrer">http:&#x2F;&#x2F;www.paulgraham.com&#x2F;rootsoflisp.html</a>
kagevf超过 1 年前
&gt; it&#x27;s all just lists. Yes, Lisp code is made up of lists.<p>&gt; But it seems like there are so many special constructs and macros, that make it hard to read.<p>&gt; (loop for i in &#x27;(1 2 3)<p>Common Lisp is a &quot;programmable programming language&quot; meaning that it&#x27;s possible to make macros like the loop macro that aren&#x27;t even what many consider &quot;Lispy&quot; - lots of people who otherwise like Common Lisp dislike the loop macro. But, it&#x27;s a good example of a DSL and how far you can go with making one. Of course, there are other ways to do iteration besides loop, both standard built-in forms such as do or dolist, and even 3rd party libraries like series or iterate.<p>Also, when macros are expanded they resolve to lists - even the loop macro.<p>OTOH, something like MIT Scheme which was used in SICP is a much simpler Lisp compared to CL.
thesuperbigfrog超过 1 年前
If you are using Common Lisp, the HyperSpec is an awesome resource:<p><a href="http:&#x2F;&#x2F;www.lispworks.com&#x2F;documentation&#x2F;HyperSpec&#x2F;Front&#x2F;index.htm" rel="nofollow noreferrer">http:&#x2F;&#x2F;www.lispworks.com&#x2F;documentation&#x2F;HyperSpec&#x2F;Front&#x2F;index...</a>
评论 #37210914 未加载
kagevf超过 1 年前
&gt; (defun &lt;name&gt; (list of arguments) &gt; &quot;docstring&quot; &gt; (function body))<p>&gt; How do I read this as an s-expression?<p>It&#x27;s still a list.<p>You can re-write it as:<p><pre><code> (let ((my-list &#x27;(defun &lt;name&gt; (list of arguments) &quot;docstring&quot; (function body)))) (print (first my-list)) (print (second my-list)) (print (third my-list)) (print (fourth my-list))) </code></pre> It will print:<p><pre><code> DEFUN &lt;NAME&gt; (LIST OF ARGUMENTS) &quot;docstring&quot; </code></pre> If &quot;docstring&quot; appears twice when you run the above, that&#x27;s because it&#x27;s the value produced by the final form in the block, so it shows up as the return value of the block.
coldtea超过 1 年前
&gt; I thought everything was suppose to be like: `(left . (left . right) )`.<p>Could be, but you don&#x27;t need the &quot;.&quot; (or the list as so-called &quot;cons pairs&quot;). (a b c ...) is enough.<p>&gt; It seems as if there are actually a ton more special case primitives I need to know<p>You need to know a handful of special forms like and, cond, let etc (corresponding roughly to keywords in other languages). Everything uses those with the same syntax (nested lists), with an exception:<p>Normally (a b c) means call function a with arguments b c. If you want to treat it as a list you can use the quote &quot;function&quot;:<p><pre><code> (quote a b c) </code></pre> For convenience this can also be written as:<p><pre><code> &#x27;(a b c) </code></pre> &gt; (loop for i in &#x27;(1 2 3) when (&gt; i 1) return i)<p>Loop is a macro, a user-defined syntax that can evaluate its arguments in a special way. It&#x27;s not part of the core language, even if it comes with it. Rather it is implemented in Lisp itself.<p>You can just not use it, it&#x27;s neither core Lisp, nor essential. If you do want to use it, or have to read the code of someone that does use, it&#x27;s pretty easy to understand. It was created so people can have their familiar for loop in Lisp too.<p>&gt; How do I read this as an s-expression?<p>What do you mean? This is already an s-expression. Or it would be, if you actually write an instance of this, this is just an example with placeholders. An instance would be something like:<p><pre><code> (defun double (a) &quot;Doubles a number&quot; (+ a a)) </code></pre> corresponding to the:<p>defun = special form (similar to &quot;def&quot; or &quot;function&quot; in other languages)<p>double = name of function we define<p>(a) = parameter list of a single parameter: a<p>&quot;Doubles a number&quot; = docstring, similar to the &quot;&quot;&quot;docstrings&quot; in Python, descriptive metadata string about the function<p>(+ a a) = add a to a in prefix (operator first) math notation
评论 #37212033 未加载
graboid超过 1 年前
&gt; It seems as if there are actually a ton more special case primitives I need to know, when I could get away with a lot less syntax in other languages to be productive.<p>I think most special forms do not complicate syntax, as they look like your standard s-expressions, they just have differing semantics from regular functions.<p>If you look at Common Lisp, I feel like you got a point. It is a huge and complicated language, and while it embodies many of the nice Lisp characteristics, I feel like minimalism certainly is not one of them. But there are other Lisps&#x2F;Schemes that are much smaller, with a lot less special forms.
评论 #37211958 未加载
kazinator超过 1 年前
&gt; <i>I thought Lisp was suppose to be simple in that: it&#x27;s all just lists.</i><p>&quot;Lisp is simple&quot; is mainly an ignorant meme that is used to belittle the interests of people who work in, or on, some kind of Lisp. There are simple aspects, but the aspects are numerous and the combination is complex.<p>Lisp has kept bright minds busy for sixty years and continues to do so.<p>Making a production Lisp from scratch is a pretty big undertaking.