19 ms·
Why Lisp Syntax Works
- tsm 3y agoI write Lisp professionally and love s-expressions, but the comparison with ALTER TABLE's grammar is pretty unfair. Postgres can detect many invalid ALTER TABLE formulations by checking the grammar, whereas in Lisp it's much easier to have grammatically-correct but semantically-wrong formulations. A major saving grace here (which was not covered in the section on macros) is that you can write clever macros that do appropriate checking at macroexpansion time, not runtime. This lets you use Lisp to write checkers for your Lisp code, which gives you a Turing-complete language you already know to do the checking instead of the (formally and practically) more limited checking of a grammar.
- gostsamo 3y agoCan you share where do you use lisp? I'm curious what are its niches nowadays.
- agumonkey 3y agoclojurians seems to still be active and somehow numerous, datascience subgroups held regular online meetups not long ago. some would say clojure is not true-lisp but well.
- kgwxd 3y agoI’ve seen people saying that but never with an argument as to why. What do they mean?
- nordsieck 3y ago> I’ve seen people saying that but never with an argument as to why. What do they mean? I don't know but if I had to guess, it's because lisp is list processing language, and Clojure doesn't really support lists (I mean, it's possible to make some, but there are none out of the box); instead it has a variety of trees that mimic the runtime performance of lists, arrays, hashes, etc.
- deleted 3y ago[deleted]
- kgwxd 3y agoI’m not sure I understand how there are no lists out of the box in Clojure. What makes the data structures not valid lists? Basic lisp lists are nestable, doesn’t that make them trees? The underlying structure is to support immutability by default but that’s under the hood stuff. Conceptually and, I think more importantly, syntactically they’re list.
- nordsieck 3y agoI'm probably the wrong person to have this conversation with - I agree with you for the most part, and I think Clojure is a lisp. My guess was the only thing that I could really think of. That and the syntax support and integration of non-list datatypes into the core language (e.g. function syntax).
- cfiggers 3y agoAFAIU, "list" has a specific technical meaning when used by someone complaining about Clojure not having them. It has to do with the implementation details, not just the semantics of how they're used. Clojure has "sequences" or "seqs", which are semantically the closest to what lispers mean by a "list"—but also "vectors," denoted by square brackets, "maps," denoted by curly brackets, and "sets", denoted by curly brackets prefixed with a hash sign. Having these as core data structures violates the Lisp principle of "everything is just a list," and they introduce something other than round parens into the syntax, which looks really weird to those practiced with traditional/conventional Lisps. For those well-practiced in "true" Lisps, Clojure reads like a very strange hybrid (one might say "corruption") of Lisp and JSON.
- robto 3y agoWhen lispers talk about lists, they are usually speaking about a very specific type of data structure - a linked list of cons cells[0]. Clojure's lists are not actual chains of cons, they are immutable hash array map tries. This means that Common Lisp code can't interoperate with Clojure code. The precise/pedantic lisper may insist that since Lisp stands for List Processing and Lists are chains of cons cells and since Clojure doesn't have cons cells for the built-in lists, then Clojure is not a Lisp. If, however, you view lisp (lower case) as a family of homo-iconic languages that use s-expressions, then Clojure happily fits under that umbrella. The trick is to pay close attention to whether the person is talking about a Lisp (ANSI Common Lisp implementation) or a lisp (the family). Sometimes people say "lisp" when they are talking about "Lisp", which can cause some confusion. [0]https://en.wikipedia.org/wiki/Cons https://en.wikipedia.org/wiki/Cons
- giancarlostoro 3y agoMy understanding is that Clojure is meant to be Scheme like, but it is not fully compliant to a Scheme spec, my only guess is due to JVM specific nuances, but I could be wrong. It has been some time since I last dived into Clojure specifics. I will say though, that side from Racket, I think Clojure is top notch, although it seems a lot of my favorite projects from a few years ago have been abandoned. One of my favorite things with Clojure is using the REPL to build a GUI using JVM libraries.
- thesuperbigfrog 3y ago>> My understanding is that Clojure is meant to be Scheme like, but it is not fully compliant to a Scheme spec, my only guess is due to JVM specific nuances, but I could be wrong. Clojure's syntax and semantics are quite different from Scheme and Common Lisp: https://clojure.org/reference/lisps https://clojure.org/reference/lisps https://www.more-magic.net/posts/thoughts-on-clojure.html https://www.more-magic.net/posts/thoughts-on-clojure.html Most differences are due to design choices, not merely JVM nuances. A few differences are due to JVM limitations at the time that Clojure was designed. I don't think any attempt was made to comply with a Scheme spec.
- giancarlostoro 3y agoGood to know, thank you! I have only done a small amount of Clojure and Racket.
- agumonkey 3y agoIt's a slight cultural shift, rich hickey probably tried to modernize/homogenize things sensibly, adding a few literals for vectors, maps and sets (a very interesting idea ergonomics wise, i'm 80% for it personally, having easy data notation is such a bliss), and some underlying changes (immutable DS first) which makes clojure feel different than lisps/CL/scheme.
- rawoke083600 3y agoI'm sure it matters for purist (valid concern), language designers and "lisp-power-users (sic ?)" I do feel however like that statement is kind a like a "tomato is a fruit" statement. Technically true but for the vast (again not all) amount of tomato users does it really matter ?
- mikelevins 3y agoThere are some other explanations given in sibling comments. They may be right, but there's another point that may also explain some of this sentiment. In Common Lisp and its antecedents, a "list" is a chain of cons cells, as mentioned by some of the sibling comments, but that's not all. Another important point is that in Common Lisp and its antecedents, source code is not made of text strings; it's made of Lisp data structures--atoms and chains of cons cells. A text file containing "Common Lisp source code" does not actually contain Common Lisp source code. It contains a text serialization of Common Lisp source code (one of many possible text serializations, actually). It isn't actually Common Lisp source code until the reader gets done with it. This might sound like a trivial pedantic point, but it isn't. Because Common Lisp source code is made up of standard Common Lisp data types, its standard library provides everything you need to walk arbitrary source code, deconstruct it, transform it, construct it, and compile it. Those features are all built into the language in a way that they are not in most languages. For those of us who are accustomed to using those features regularly, working with a language that lacks them is such an impoverished experience that I can understand folks objecting that "that's not a proper Lisp." I don't tend to make that objection myself, but I do understand it. If your Lisp does not represent its source code in this way, or if it doesn't even have the data structures that source code is made of in Common Lisp and its antecedents, then there is a nontrivial sense in which it's not a Lisp--or at least not the kind of Lisp that those older ones are.
- eduction 3y ago>In Common Lisp and its antecedents, a "list" is a chain of cons cells, as mentioned by some of the sibling comments, but that's not all. Another important point is that in Common Lisp and its antecedents, source code is not made of text strings; it's made of Lisp data structures--atoms and chains of cons cells. Source code in Clojure is also not made of text strings, it also reads text as the serialization of data structures, which are then interpreted as source. The difference is, Clojure uses data structures other than cons cells for source. What do you see as particularly important about cons cells? What advantages do they give what some might call a "real LISP" over Clojure, which, I'd argue, smartly abstracts around more modern data structures like vectors, maps, sequences, collections as opposed to being "married" to cons cells as Rich Hickey once put it?
- kaliszad 3y agoClojure and ClojureScript communities are thriving. Our product, orgpad.com is written completely in those two. I have written about some of the technologies we use before.
- deleted 3y ago[deleted]
- smcn 3y agoWe use it for stock market analysis over at https://feetr.io https://feetr.io. Honestly, I couldn't imagine a better language as it makes large tasks almost effortless. Plus the fact that I can connect to the running image and query data feels like magic and makes farming content for social media almost facile as I can pipe some of the data through cl-table and just post a screenshot.
- zetalyrae 3y agoWhat's the scale of the codebase, in kilolines of code? Do you find the dynamic typing to be a problem at scale?
- smcn 3y ago`cloc` has it at 24k lines of code so it's by no means a huge project but it's big enough where I feel like we would have encountered a large variety of issues. As of yet there hasn't been anything major. We have felt the lack of libraries at times but that just means we need to write more lisp, which is a good thing as lisp is fun. Honestly, I don't know that I'd classify our use of CL as dynamic. We're happy customers of `deftype` and `declaim`. While it's true that not every function makes use of them, most of them do. So in that regard, I can't comment but that's the beauty of lisp: it's the language that you need it to be.
- belmarca 3y agoAre you guys hiring?
- 3y ago
- nerdponx 3y agoI think of specialized language syntax on a spectrum similar to "Dynamic types <-> Static types". Very general syntax like S-expressions provides you maximum flexibility, but the minimum amount of guidance on semantics and protection against mistakes, along with the opportunity for nicer, more-detailed error messages.
- reikonomusha 3y agoI don't agree. One can write a serious, syntactically bullet-proof grammar for a language built out of S-expressions, with nice error messages and all. We can imagine a parallel universe in which TFA's Postgres example were written using S-expressions: <alter> := (ALTER-TABLE (:IF-EXISTS? :ONLY?) <symbol> :*? <action>+) | ... <action> := ... Despite using S-expressions, this is parseable with as much rigor as more free-form character syntax. I think Coalton [1] is a good example of this. The language is embedded as S-expressions in Common Lisp, but you get Rust-like error messages, showing exact source lines (with line numbers) and embedded underlines showing the location of the offending code. With that said, what is true is that if you're using Common-Lisp-style macros and you're manipulating S-expressions programmatically, lexical information may get thrown out. This is not unlike doing a bunch of string manipulation in an ORM to generate SQL, which will have similarly poor error messages. [1] https://github.com/coalton-lang/coalton https://github.com/coalton-lang/coalton
- datagram 3y agoI don't think the article is necessarily claiming that specific syntaxes like SQL are bad. I think they just wanted to highlight how different the languages are.
- 7thaccount 3y agoWhat kind of work do you do? I occasionally daydream about working in something like APL/q, Forth, or Lisp.
- tsm 3y agoI write Clojure for https://www.metabase.com/ https://www.metabase.com/ Lots of interesting problems involving working with different database engines, processing data, compiler design, etc.
- 7thaccount 3y agoThat sounds super cool!
- Naomarik 3y agoI'd recommend this for more reading on the subject: https://www.defmacro.org/ramblings/lisp.html https://www.defmacro.org/ramblings/lisp.html Personally I switched to clojure 8 years ago after this article along with PG's essays pushed me over the edge.
- wodenokoto 3y agoAs a backseat lisper, I wondered, when cakelisp hit the front page, if what makes one lisp different from another really only is “the standard library”, because the syntax is so barebones, there really isn’t anything to play around with. And then cakelisp turned out to not really be a lisp according to the author.
- stefncb 3y agoSemantics. CL is extremely dynamic and has separate symbol namespaces, Scheme has more rigid types, Clojure has a lot of stuff built around immutability and replaced the general use of lists with arrays, Fennel has lua types and semantics, Janet is very small and portable, and adds a lot of small nice things. Each of these feels completely different to program in, and it's mostly not about the standard library.
- senko 3y ago> Lisp’s unusual syntax is connected to its expressive power. [...] It’s because of uniformity. Okay... > Lisp (and XML) have a uniform syntax. .. ookay. The rest of the arguments, and the conclusion, can then be equally applied to XML, specifically the: > I maintain that Common Lisp is the gold standard of DX for macros Does (s)he also maintain that XML is the gold standard of DX for macros? I guess that'd mean XSLT? ... Or the article is just trying to be too clever for its own good.
- denton-scratch 3y ago> I guess that'd mean XSLT? XSLT is amazing. And XSLT scripts are really hard to read - just like Lisp is (at least, it is to me).
- masklinn 3y agoThe idea behind XSLT (match/patch) is amazing. Xslt itself is complete trash. - developing an entirely new language in XML was a meh idea, but it was severely lacking making using it difficult unless you were allowed to extend it via custom functions and elements - the template-as-transform and template-as-function confusion was completely unnecessary and made it much harder to learn and grok than necessary - but the worst mistake by far was the impliciteness and confusion of `.`, the thing is verbose as all hell, the implicit passing and transformation of the context was completely unwarranted, not unlike Perl’s magical side-effect unless you’re deep in the sauce it makes the entire thing a lot worse, and with even less payout given the general verbosity of XSLT and XML (in perl all the magic provides amazingly terse CLI commands, it’s just a shame people then used that in perl files)
- rjsw 3y agoXSLT is a lot harder to use than Lisp. Trying to debug some XSLT right now, every implementation processes the script differently, have reached the point of just declaring that it is broken and using something else. I should be writing Common Lisp, I get paid for that.
- 3y ago
- magic_hamster 3y agoIn my long journey to make computers do what I want spanning several decades, systems, languages and trends, I've come across a certain class of geeks. This group would swear by Lisp. And by that I mean, they would treat Lisp as the gold standard. Sometimes, the only standard that matters. They would go to unimaginable lengths to explain why Lisp is really the purest form of computer science expression; how it sharpens your mind and elevates your skill; how it is akin to poetry, only better, because it's poetry in code. And after all this was done, and repeated several times over, I would gently nod at this exalted madman who had been blessed by the touch of the Lisp God. And then we'd both go back to whatever language we were actually using at the time.
- KRAKRISMOTT 3y agoBut other than a Skyscanner predecessor (VIA), a computer algebra engine, and Grammarly, are there any other modern high profile lisp powered products?
- jb1991 3y agoI’ve heard that CircleCI uses clojure extensively, not sure if that counts as a true lisp. There’s also Metabase, also written in it.
- benrutter 3y agoThe big one that I always remember is Crash Bandicoot - Naughty Dog I think had their own version of Scheme and then switched to Racket at some point. Nubank are also a semi-high profile company who use a lot of Clojure. Of course, if you ditch the "modern" requirements, I'm sure there is more web infrastructure and scripts supported by Common Lisp than people would want to admit. . .
- crabmusket 3y agoTo clarify, Naughty Dog has still been using LISP-based scripting and asset definitions in their recent games[1]. (Though I count The Last Of Us as recent so I guess that shows how often I play games.) [1] https://www.youtube.com/watch?v=gpINOFQ32o0 https://www.youtube.com/watch?v=gpINOFQ32o0
- deleted 3y ago[deleted]
- timwis 3y agoIf I understand correctly, I believe elixir carries similar benefits: https://elixir-lang.org/getting-started/optional-syntax.html https://elixir-lang.org/getting-started/optional-syntax.html
- medo-bear 3y agoyou dont
- timwis 3y agoHey, not sure if this was your intention, but your comment came across as quite rude, and makes me feel discouraged from commenting on something in the future that I'm not 100% confident about. And of course that's no way to learn. A more encouraging response would be one that doesn't focus on whether or not I understand correctly (I'd already acknowledged that I may not), but on what the differences are, thereby spreading your knowledge rather than using it to make people feel excluded.
- medo-bear 3y agoHi, I'm sorry for coming across as rude, but your post had no content other than a statement that you think Elixir has similar syntax benefits as Lisp. Maybe if you wrote, "I think this is similar to Elixir because so and so", someone would be able to give you a more informative reply as to why you are wrong
- edanm 3y agoI disagree. The comment pointed out another language with similar benefits to the article, and linked to another article which specifically talked about syntax rules of Elixir. It was useful for me, personally.
- medo-bear 3y agosome consider posting a link to some content you want to use as an argument, bad form. usually what is expected is to make your claim and use that article as reference to support it. this also helps lay bare your understanding of the content you are linking to. with that said, what precisely do you think are the similar benefits of elixir syntax rules to those of common lisp?
- revskill 3y agoI rather want to master lisp as the last proframming language, because i want to experience the pain first in other languages to understand why, what and how lisp could help.
- bluetomcat 3y agoIt's called prefix notation and it's the most primitive form of representing ordered computation. It was the easiest thing to implement in the glorified calculators of the 1950s. It's not the "Lisp syntax" that works, it's the lack of syntax that enables this uniformity and flexibility but irks the eye.
- Paul-Craft 3y agore: "lack of syntax" I agree (though it doesn't necessarily irk the eye after some getting used to). Rather than saying it has a "uniform" syntax as the article author does, I am fond of saying lisp has "no syntax," because it's essentially true.
- zrkrlc 3y agoMinor nitpick, but weren't the best of these calculators (i.e. the HP ones with RPN) postfix instead of prefix?
- thesuperbigfrog 3y ago>> weren't the best of these calculators (i.e. the HP ones with RPN) postfix instead of prefix? Yes. RPN is more like Forth than Lisp.
- mlatu 3y agosure, disregard that one word and suddenly it all falls apart. what is homoiconicity anyways? doesnt matter you say? it is the feature of the code being represented the same way as the datastructures it manipulates. i know, what a completely unneccessary and unimportant point. now let's all forget this and turn our attention back to the compiler, it wants you to fix those bugs now... back to work.
- klysm 3y agoBut my macros!
- mlatu 3y agowhataboutthem?
- zetalyrae 3y ago>it is the feature of the code being represented the same way as the datastructures it manipulates. Every language can do this. You just don't get QUOTE. But any compiler can implement QUOTE.
- mlatu 3y agoXD yeah. you can implement lisp in any language.
- taeric 3y agoMaybe? Many languages can possibly expose an AST abstraction that you can use to achieve the same results, but you will have to resort to a new syntax to make that work. Compare with https://taeric.github.io/CodeAsData.html https://taeric.github.io/CodeAsData.html, where you can take the normal syntax of a function, but use it to get something else. That is to say, the "quote" form in lisp is far more than just a string template, which is what it often turns into in other languages. That, or you build up a bunch of structs that you don't normally see.
- yogsototh 3y agoPersonally I find that LISP syntax remove a layer of complexity by directly exposing the AST to my brain instead of adding a layer of internal parsing. 1 + x * 2 - 3 % x is longer to decipher than (% (- (+ (* x 2) 1) 3) x) which is itself harder than (-> x (* 2) (+ 1) (- 3) (% x)) But it takes a while to be used to it. And yes, it really helps writing macros, but I wouldn't say this as always be a good thing. Macros are far from being the alpha and omega of programming, as they add an implicit layer of transformation to your code making it easier to write but very often harder to read and reason about.
- sbergot 3y agoYou left out the more common options: (1 + x * 2 - 3) % x and (1 + (x * 2) - 3) % x both are clearer than the S-expression in my opinion
- Paul-Craft 3y agoI agree, and this is why for math expressions that aren't just composition of functions that aren't basic operators, I like to use a macro that lets me type them in as infix. It's the one case where lispy syntax just doesn't work well, IMO.
- zelphirkalt 3y agoI don't find them to be clearer, with the background of knowing many language, because now I have to worry about precedence and I better double check, to not get it wrong or read it wrong.
- digdugdirk 3y agoAs someone who isn't a trained programmer (and has no background or understanding of lisp) that looks like you took something sensible and turned it into gibberish. Is there a recommended "intro to understanding lisp" resource out there for someone like myself to dive in to?
- _aaed 3y ago
- vidarh 3y agoI find s-expressions useful, of sorts, but I also find them horrible to read and write. For my long-languishing Ruby compiler project I added syntax to let me embed small chunks of "pretty much AST" directly in the code to "escape" to lower level code when implementing the lower levels of the standard library (like Object, Class etc.). For that kind of limited use, I find s-expressions great because it's trivial to add simple s-expression parsers to things where you suddenly need to support complex nested structures with minimal syntactic noise, but I'd claw my eyes out if I had to read s-expressions all day every day. (And since I prefer Ruby: just prepending a "%" the example s-expressions in the article makes them valid Ruby literal strings, so now I'm kinda tickled at the thought of taking a little s-expression parser and building a tiny Ruby Lisp implementation that lets you just intersperse lisp code in your Ruby. Surely someone must have already done so for fun)
- vidarh 3y agoCouldn't resist, so a lightly golfed s-expression parser and test of using %() here: https://m.galaxybound.com/@vidar/110493036393779755 https://m.galaxybound.com/@vidar/110493036393779755
- beeforpork 3y agoWell, I like Lisp, too. But the macros are not really good, but they are basically buggy ('non-hygienic'), and it took a few years to realise and repair that. Look at Scheme or Racket instead.
- bitwize 3y agoCLers will be along to tell you that macro bugs rarely happen in CL because of separate function and variable namespaces, and if they do you can always use gensyms. CL is the "worse is better" of "the right thing".
- pfdietz 3y agoAs a CLer, I have never understood the draw of hygienic macros. They solve what looks like a non-problem, straining mightily to achieve little of actual value.
- Paul-Craft 3y agoIt turns out that it isn't terribly hard to implement hygienic macros on top of "non-hygienic" macros. I recently saw a paper that had an implementation. The code itself was fairly short.
- beeforpork 3y agoThat sounds like an interesting read. Can you post a pointer?
- Paul-Craft 3y agoI wasn't sure I could find it again, but here it is! Embedding Hygiene-Compatible Macros in an Unhygienic Macro System: https://www.jucs.org/jucs_16_2/embedding_hygiene_compatible_macros.html https://www.jucs.org/jucs_16_2/embedding_hygiene_compatible_... Abstract: It is known that the essential ingredients of a Lisp-style unhygienic macro system can be expressed in terms of advanced hygienic macro systems. We show that the reverse is also true: We present a model of a core unhygienic macro system, on top of which a hygiene-compatible macro system can be built, without changing the internals of the core macro system and without using a code walker. To achieve this, the internal representation of source code as Lisp s-expressions does not need to be changed. The major discovery is the fact that symbol macros can be used in conjunction with local macro environments to bootstrap a hygiene-compatible macro system. We also discuss a proof-of-concept implementation in Common Lisp and give historical notes. The code is in Figure 1, on page 10 of the PDF (p. 280 in the actual journal)
- ldb 3y agoThere are some nice Lisp related comics on xkcd, e.g. https://xkcd.com/224/ https://xkcd.com/224/ and https://xkcd.com/297/ https://xkcd.com/297/.
- chrismorgan 3y agoMost of the SQL grammar shown is, in practical terms, semantics more than syntax. Sure, there’s syntax woven into it, so that the points being made are quite valid, but I mean that to cover the scope of that grammar would take just as much space in Lisp, just in the form of things like function and parameter definitions (probably just as complex) instead of syntax. So it’s not just 118 lines of stuff Lisp wouldn’t need at all, which is a way I can see some people misinterpreting that section. SQL puts a lot of its complexity into syntax-space, a similar Lisp system puts it into library-space, but the complexity is still there (just probably easier to work with programmatically).
- fuzztester 3y agoAside but related: Borretti's Austral systems programming language looks interesting. Early stage. I just read the one example so far, but the syntax looks nice and clean to me. https://github.com/austral/austral https://github.com/austral/austral
- paldepind2 3y agoThis is a good article and I think it hits the nail on the head. There is one point I don't agree with though: > Syntactic uniformity also means there is a lot less room for syntax bikeshedding. Really the only thing you can bikeshed is the naming convention for identifiers, and how S-expressions should be indented. This might be true in theory, but in practice I find to be effectively false. Lisp makes is very easy to add your own macros that implement DSLs with custom "syntax". Common Lisp for instance has bunch of these build in, for instance for iterating over lists. While this is technically not syntax in the traditional sense that the parser is aware of it, it has the same characteristics for a user. You need to learn the "syntax" that the macros implement and _that_ syntax you can certainly bikeshed about.
- WorldMaker 3y agoYou can see that in even ancient Lisp discussions. The article shows a macro that transforms to a Common Lisp-style LOOP, but LOOP is often criticized as having too much of a DSL syntax and there's plenty of old debates on if it is better to use things like REDUCE or other predecessors of LOOP instead of learning the complexities of LOOP. (On the other hand, LOOP is very powerful, and its mini-query language can relatively succinctly describe a lot of usefully optimized loops.)
- Jtsummers 3y agoThe LOOP facility is also often more efficient than stringing together map, reduce, and other functions. Unless you use something like SERIES (or a similar package) which can perform stream fusion for efficiency, but that's not the norm (I highly recommend exploring it though if you want to use the map/reduce style and want efficient results).
- ducktective 3y agoThe code mentorship platform Exercism has recently launched "The Summer of Sexps!" This month for #12in23 we're exploring languages that are Lisp dialects. We're digging into Clojure, Common Lisp, Emacs Lisp, Racket and Scheme, with interviews and live streaming, exclusive swag and lots of fun exercises for you to complete! https://exercism.org/challenges/12in23 https://exercism.org/challenges/12in23 https://youtu.be/5Kg7gC1YcWs https://youtu.be/5Kg7gC1YcWs
- rawoke083600 3y agoI've mentioned it before, but maybe If I can help one "almost-lisper": IF the "Syntax / Parenthesis" is the "only" thing that puts you off LISP (I'm sure there are many other semi-valid reasons), keep pushing. It's a little bit like smoking, most smokers didn't enjoy their first two or three cigarettes, but suddenly one day you realise you addicted and now all other non S-Expr-Languages looks ugly. It's kinda like magic the "sudden switch" from hate-to-love. At least for me :) YMMV
- noman-land 3y agoAs someone who is semi obsessed with functional/array programming and lisps, framing it as an addiction is a turn off. We should use things because they are good, not because we are unable to stop.
- maleldil 3y agoFraming it as addiction was a mistake, but the intention is accurate: S-expressions are weird when you're used to C-like languages until they're not. You have to push yourself long enough to get used to them, and most people don't want to do that. Once you do, everything makes sense. What did it for me is realising that after some time, you don't pay attention to the parentheses. Identation in lisps is semantic, which looks weird when you're used to one level at a time. But try using a sensible formatter (e.g. Clojure's cljfmt, Racket's fixw). They will show you good ways to format your code, making it very readable, parentheses and all. Then you get used to structural editing with Paredit or vim-sexp, and you're sold on S-expresssions.
- nerdponx 3y agoMaybe an "acquired taste" is a better metaphor, like stinky cheese, sour beers, and Captain Beefheart & The Magic Band.
- rawoke083600 3y agoHaha I think you right !
- User23 3y agoLisp syntax is just a nice format for textual representation of trees in general and ASTs in particular. Having done similar work in both Common Lisp and Go, I can confidently say that working with ASTs in CL is considerably less burdensome. Lisp in general and Common Lisp in particular have a lot more going on than the syntax though. I think there's an old saw about syntax being the bikeshedding of the programming language world when it's semantics where all the real thought and expertise is required. It's the semantics that CL interesting, like for example its well defined notions of compile, load and eval time[1] and the ability to redefine existing types and functions, even while in the debugger. [1] http://clhs.lisp.se/Body/s_eval_w.htm http://clhs.lisp.se/Body/s_eval_w.htm
- reikonomusha 3y agoOne way I've come to answer "why Lisp syntax" is through the following proxy question: > If you want extensible syntax, what should the base syntax be? The regularity and austerity of Lisp syntax comes from this idea. If Lisp, by default, were loaded up with all sorts of syntactic constructs [1] many of us take for granted today (which may in and of themselves be good!), then it leaves less room for the programmer to extend it in their own way. It turns out that the syntaxes we take for granted today—like for(;;){} loops or pipe | operators—are perfectly serviceable in their S-expression-equivalent form to the working Lisp programmer. The author is right about why Common Lisp's syntax extension facilities (macros) work; the language is in a sort of syntactic Goldilocks zone. [1] To properly discuss Lisp, we really ought to distinguish meta-syntax (the parentheses) and syntax (the grammar of symbols and lists). Common Lisp has lots of syntax, like ; variable binding (LET ((<var> <expr>)*) <decl>* <expr>*) ; type declaration (DECLARE (TYPE <type> <var>)) ; function definition (DEFUN <var> (<arg>*) <decl>* <doc>? <expr>) All of this is different syntax! These are different rules about how symbols etc. are allowed to be arranged to produce a semantically meaningful program. But they wear the same clothes of meta-syntax, which is relatively small, mostly based off of the fundamental idea of S-expressions: <s-expr> := <atom> | ( <s-expr>* ) <atom> := <symbol> | <number> | ... Ordinary macros allow extension of the former class of syntax, while reader macros allow extension of the latter class of syntax. When talking about "macros" unqualified, we usually mean the former, but Common Lisp supports both.
- thesz 3y agoYou also can use mixfix syntax [1] if you want extensible syntax. [1] https://wiki.portal.chalmers.se/agda/ReferenceManual/Mixfix https://wiki.portal.chalmers.se/agda/ReferenceManual/Mixfix It is used by Agda and Maude and is quite versatile. Note that one of examples above is if_then_else_ function which implements a typical language construct, but in Agda, due to lasiness, it is just an ordinary function. [2] https://news.ycombinator.com/item?id=20697414 https://news.ycombinator.com/item?id=20697414 McCarthy did not understand lambda calculus at the time he specified Lisp and what can be a function became a special form, if I not mistaken. So, for another approach at extensible syntax you may consider mixfix notation and lazy evaluation.
- 3y ago
- sssilver 3y agoIf a kid were to learn Lisp purely for the joy of recreational programming, with no intentions of ever building production software with it, what Lisp would they pick?
- thsksbd 3y agouLISP, an arduino and a bunch of peripherals for it.
- brabel 3y agoRacket - https://docs.racket-lang.org/quick/ https://docs.racket-lang.org/quick/
- Jtsummers 3y agoRacket would be my suggestion. As much as I like Common Lisp, it has a lack of material targeting kids (other than particularly motivated ones). Scheme would be a second suggestion, but Racket is descended from Scheme and so is mostly (with a bit of effort in some cases) compatible with any Scheme learning material you might want to use. Scheme also requires you to decide which implementation to use, which can impact available libraries and tools. https://racket-lang.org/ https://racket-lang.org/ It's also very easy to get visual results in Racket which often helps to keep kids motivated (seeing results of their work quickly and easily, versus needing to jump through hoops or read lots of documentation just to render a single image).
- latenightcoding 3y agoyour own obscure lisp of course!
- pwpwp 3y agoI find the claim about image-based development being required for macros somewhat unfounded. The most trivial counterexample is an interpreter - it can simply evaluate the macros just like ordinary functions. A step up in complexity is a compiler that - during compilation - compiles macro definitions by emitting code and dynamically loading it (Goo does this http://people.csail.mit.edu/jrb/goo/goo.htm http://people.csail.mit.edu/jrb/goo/goo.htm , and I have also put a toy implementation of this together using dlopen, and there are probably many other impls that do this.)
- KingMob 3y agoYeah, that part made little sense to me. Clojure is one of the weakest lisps when it comes to macros, but you can still define and use them at run-time, and it has no image-based development.
- hota_mazi 3y agoWhile the barebones aspect of Lisp is appealing, there is no way I will commit again to a language that's not statically typed. There is a difference for a language between "readable" and "understandable". To me, languages that don't have type annotations (ideally with type inference) might look pleasing to the eye but they are a nightmare to maintain and modify because so much vital information is missing.
- Tainnor 3y agoYou can write a lisp that uses static typing. The book "The Little Typer" develops one such language as (I believe) a dialect of Scheme. Of course, that's just a toy language (and it doesn't have type inference, for example, but as far as I'm aware that's a hard problem when you add dependent types), but it shows it can be done.
- Jtsummers 3y agoThe language in The Little Typer supports not just static types but dependent typing. A much more interesting capability.
- Tainnor 3y agoWell yes, but those are still static types. :) And of course, you're not forced to use dependent types, so "regular" statically typed programs are just a subset of dependently typed ones.
- evdubs 3y agoRacket goes a step further from having types and gives you contracts. The whole language is defined by these contracts. For example, > (list 1 2 3 4) is a way to create a list consisting of elements 1, 2, 3, and 4. This procedure is defined as returning a `list?` (a contract checking for a list) and the values provided are `any/c` (a contract representing any value). But many other languages can support something like that just fine. Where contracts further help are with composition and specifying allowable values or ranges of values. For example, > (round 2.4) 2.0 as we expect. But looking at the definition of `round`, we see that `(round x)` accepts an `x` satisfying contract `real?` and returns `(or/c integer? +inf.0 -inf.0 +nan.0)`. If you try to `round` Infinity or NaN, you get what you "expect" and not some new value. If you try to `round` POSITIVE_INFINITY in Java, you'll get > Math.round(Double.POSITIVE_INFINITY) 9223372036854775807 because, with types, Math.round() must return an int or a long.
- tabtab 3y agoThe main problem I find with Lisp syntax is that everything looks the same: a giant soup of parentheses. You have to read Lisp closely to know the context. A list of statements (function calls) visually looks different than a list of parameters in C-style languages, for example. Similarly, you see square brackets and immediate know it's a subscript/index to an array-like structure. And parenthesis (usually) mean something different than curly braces. Visual Cues Help! Maybe your eyes are different, but most the programming world has agreed with me over the years and voted C-style over Lisp. I have even proposed a syntax style called "Moth" that attempts to meld the best of C-style, Lisp, and XML in terms of composability and roll-your-own control & block structures. I welcome better takes on the goal. Moth link: https://www.reddit.com/r/ProgrammingLanguages/comments/ky22dx/simplified_take_on_moth_colonfree/ https://www.reddit.com/r/ProgrammingLanguages/comments/ky22d...
- aneil 3y ago> Lisp’s unusual syntax is connected to its expressive power. How? Not because of “homoiconicity”, a word that has no meaning but leaves people somewhat impressed, because it sounds fanciful and mathematical. It’s because of uniformity. No, it _is_ because of homoiconicity, which though a fancy word, does mean something: code is data. That is the reason Lisp syntax works. Clojure is less uniform, but it is still homoiconic, and that is why it has the same powers as CL.
- kazinator 3y agoDoug McIlroy coined homoiconic as meaning that the programs are stored in the way that the programmer has entered them. The POSIX shell is homoiconic because after you have defined some functions, you can execute the command "set" (with no arguments) to see the definitions. They are stored in a form that can be copy and pasted into the shell. (There may be reformatting and comments removed). The homoiconic feature in Lisp (Common Lisp) is the ED function. It will recall the textual definition of a function, allowing it to be edited. The big idea in Lisp of using a data structure for manipulating code isn't homoiconic; the data structure definitely isn't in the source code format. It's homoiconic to the extent that uncompiled code can be stored as a data structure and converted back to a character-level of representation. (This is possible due to something that Lisp calls print-read consistency, an important concept in Lisp.) The code-to-code transformations in Lisp do not work by converting code to text and back again. We can take advantage of that even if we go through some front-end that provides a surface syntax, like infix.cl, which loses homoiconicity. So rather that homoiconicity, the two concepts important in Lisp are print-read consistency and code as a data structure.
- School-Cotton 3y agoCode is also data in C++, because a source file is a vector of bytes, which is a type of data that C++ can manipulate. I think when people say “code is data” what they really mean is something more specific, like the AST is easy to access and manipulate in the language.
- freilanzer 3y agoWhen people say 'code is data' they obviously don't mean that source code is stored in a text file which consists of bytes... (def add (x y) (+ x a)) (def sub (x y) (- x y)) (add 1 2) # 3 (sub 1 2) # -1 (first '(add 1 2)) # 'add (rest '(add 1 2)) # (list 1 2) (apply 'sub (rest '(add 1 2))) # -1 (reverse '(add 1 2) # '(2 1 add) Excuse my pseudo lisp quote syntax, it's been a while.
- shrimpx 3y agoCorrect me if I'm wrong but it seems you roughly get "lisp-ness" by taking any textual data format and defining a programming language syntax in terms of that data format. I could make a JSON-based language that looks like: [ // define some_fun(x) => let y=2;let z=y*3;return x+z {"some_fun": [["x"], [ {"y": 2, "z": ["*", "y", 3]}, ["+", "x", "z"] ]}, // call it ["some_fun", 100] ] Here I'm using JSON dictionaries to bind variables, and lists for everything else (instruction sequences, argument lists, etc.). Now I can quote stuff to define JSON data, or otherwise define programs. I'm not a lisper but it seems what's special about lisp is it defines its programs in a generic data format.
- zdragnar 3y agoYou're essentially describing homoiconicity: https://en.wikipedia.org/wiki/Homoiconicity https://en.wikipedia.org/wiki/Homoiconicity
- shrimpx 3y agoThanks!
- Jtsummers 3y ago> I'm not a lisper but it seems what's special about lisp is it defines its programs in a generic data format. One of the things that still makes Lisp special. It makes metaprogramming "easy" in contrast to metaprogramming in almost every other language out there. The other big thing is its high degree of interactivity and dynamic capabilities.
- matthewn 3y agoSimilar argument from this lengthy but enjoyable essay: https://stopa.io/post/265 https://stopa.io/post/265
- kazinator 3y agoBut JSON is somewhat impoverished in that only has floating-point numbers, strings and a handful of symbols (true, false, null, ... ?). The most obvious thing lacking from the point of view of interpreting in a Lisp-like way is an ergonomic syntax for symbols. People have experimented with computation in JSON, pretty much like how you have it; but it's lame to work with. Nobody wants to write quotes around basic identifiers like "+". And it is inefficient, to boot. Interning of symbols is a key advantage of Lisp, and it was there in 1958 already; so by using JSON this way, you're regressing before that. Lisp converts symbols into small values, which are atoms. Two or more occurrences of the same symbol are the same atom. An atom is a small word-sized quantity. Often a pointer, but not necessarily so; it could be a numeric index into a table of objects. Anyway, it is very efficient to test whether two atoms are the same object.
- kazinator 3y ago> In particular, image-based development is a rarity nowadays, a Galápagos island feature that is undesirable in many contexts, but it’s the thing that makes it possible to have Turing-complete macros that are defined in the same place as the code, without needing to involve a build system. This is false. Lisps do not have to have an image-based development system in order to have Turing-complete macros in the same language as the code, inside the code. The proof is the existence of such systems. There are Lisp dialects which do not have image dumping, yet have working macros. What you need is for the macros (and any helper functions of the macros) to be loadable into the compiler process. You do not need image saving and restoring for that to work. Image saving and restoring is an independent feature of memory management; it traverses the heap and writes a representation of all the objects which can be used to re-animate the session. Some Lisps rely on image saving for producing executables, but that's not related to how macros work.
- TheRealPomax 3y agoI expected yet another tutorial on how to implement lisp in 100 lines of code.
- slaymaker1907 3y agoI think SQL is an unfair example because the grammar is so poorly constructed. Designers of the language seemingly cared little for ease of extensibility in favor of ridiculously specific constructs. Compare that to Java's much simpler grammar https://docs.oracle.com/javase/specs/jls/se7/html/jls-18.html https://docs.oracle.com/javase/specs/jls/se7/html/jls-18.htm.... I can't find a good reference, but I suspect even Kusto/KQL has a much simpler grammar than SQL despite functioning in a very similar problem space. One of the first rules of making a new programming language should really be to do as little as possible in the parser. By making your parser extremely complicated, you also make it extremely difficult for anyone to write tools for your language. Instead, it's much better to push that out to the rest of the compiler and/or the type system.
- abrax3141 3y agoI've been a hard core lisper for almost 50 years, and have coded in pretty much every other language in that time, either professionally or for fun. But I always return to lisp, because Lisp isn't a programming language. There are no parens. There is no syntax. There is no spoon. Lisp isn't a programming language, it's hard to describe what it is with a simple term, "meta-language" is the closest I can come, but that doesn't get to it deeply enough. You don't write a program for some problem in lisp, you think beyond the problem to it's meta-problem-space and design a language in which you naturally express prose in that (meta)problem space. Then, given that you now have a natural language (and I mean that in the true sense of "natural language", but not for a human problem space, but for the problems space of the problem you are working on) for that problem space, the problem you were after to begin with is a natural expression in that new language. And you're done.