6 ms·
-> the Lisp linked lists were gone Cons cells and linked lists are not completely gone, though: user=> (cons 1 (cons 2 nil)) (1 2) Cons cells however
by ventuspilot 2y ago
-> the Lisp linked lists were gone
Cons cells and linked lists are not completely gone, though:
user=> (cons 1 (cons 2 nil))
(1 2)
Cons cells however are somewhat limited in that the second argument to cons must be an ISeq.
- lispm 2y agoand then you get this in Clojure: user=> (list? (cons 1 '(2 3))) false user=> (cons 1 '(2 3)) (1 2 3) That's "strange", isn't it? It prints as (1 2 3), but it is not a list? So there are things which print as lists, but aren't lists? What? Which also means that when we print it and read it back, it will be of a different type and list? will be true?! ELISP> (listp (cons 1 '(2 3))) t Puh, Emacs Lisp got it right.
- anthk 2y agoYes, I'm tired of Clojure fanboys recommending their language as a Lisp. It's not.
- iLemming 2y agoYou can probably make many like minded friends in r/haskell. Just post something about Clojure and pedants most likely crawl out, saying how it is not an FP-language. :)
- anthk 2y agoNot about FP; it' just that Clojure tries to be a Lisp and it fails on the simplest basic list cons'ing. Like declaring some mini-C 'ANSI C compatible' and you can't even provide a complete but basic stdio.h header.
- iLemming 2y agoIt's not "failing" on the simplest basic list cons'ing, it did what's expected, it consed the list. You're trying language features without even bothering to ask if the function you're using does what you think it does. Have you read the docstring for (list?)? It says "Returns true if x implements IPersistentList". (cons 1 '(2 3)) results in a clojure.lang.Cons not the instance of clojure.lang.PersistentList. A clojure dev would be using (seq? (cons 1 '(2 3))) instead of what you tried. Maybe before hating something so fervently try to learn it a bit more first?
- kazinator 2y ago> A clojure dev would be using (seq? (cons 1 '(2 3))) instead of what [the Lisp dev] tried. Well, no kidding. > (cons 1 '(2 3)) results in a <Java thing> not the instance of <another Java thing>. :)
- iLemming 2y agoClojure is a hosted language. It embraces the idioms, strengths, and ecosystems of the platforms it runs on (JVM, Javascript, .NET, Dart, etc.) without trying to "change the platform" or impose an absolute uniform behavior across different environments. Clojure encourages using idiomatic patterns that align with the host platform’s best practices. For instance, when running on the JVM, it leverages JVM's threading model and garbage collection; in Clojurescript, it adopts patterns suitable for JS's event-driven model. Clojure does not try to provide a uniform abstraction layer that masks platform differences. Instead, it exposes platform-specific capabilities, making developers aware of and able to exploit the unique features and strengths of each platform. Clojure compiles down to the native code of the host platform. For the JVM, it compiles to JVM bytecode; for JS, it compiles to JS code. This means the compiled code runs as if it were natively written in the host language. Clojure operates within the host runtime, using the host platform’s execution model, memory management, and runtime services. Being a hosted language means that Clojure does not attempt to hide or abstract away the platform it runs on. Instead, it integrates deeply with the host platform, leveraging its native capabilities and interoperation features. This allows Clojure code to be idiomatic to the host environment and benefit fully from its strengths.
- iLemming 2y agoI can only add to that - the hosted nature of Clojure is one of the most underrated awesome features of it. You can write for example a macro that's defined in Clojure code, but to be used in Clojurescript, and changes the behavior of a browser app based on a condition detected in JVM - for example, you can parse some .js library and based on that (clojurescript compiler would) emit modified compiled Javascript code. That stuff is useful for dynamic polyfilling, i18n, css-in-js, feature-flagging, using shims to ensure compatibility, and more. Moreover, you can have namespaces where Clojure and Clojurescript code is intertwined. I have never seen so much code reusability, even when I was heavily writing for Node. Check this out: you can write specs that would represent your data, alright? Then, you can generate some random collections of data based on those specs. The data that you can use both - on front-end (e.g., for end-to-end testing) and back-end (e.g., for testing the domain logic). You can also use the same specs for validation in UI controls - 'not a valid email', etc. Neat, right?
- behnamoh 2y agoI just tried your first example on tryclojure.org and it returned "true": user=> (list? (cons 1 '(2 3))) true
- lispm 2y agoYour example looks like Clojurescript? It is also inconsistent between variants? Clojure 1.11.3 user=> (list? (cons 1 '(2 3))) false
- behnamoh 2y agoInteresting! The tryclojure.org website says it's Clojure, not ClojureScript. If it's inconsistent between variants then I'm absolutely not going to code in it...
- iLemming 2y agoIt's not "inconsistent" between the variants. Clojure is a hosted language, it depends on the underlying platform. In Clojurescript, the implementation details and type checks differ slightly from Clojure due to the different runtime environments (Javascript vs. JVM). As a result, certain predicates like `list?` might behave differently. In Clojure, it's generally better to use (seq?) instead of (list?) when you need to check if a value is a sequence, as (seq?) is more encompassing and works for all sequence types, not just lists. You almost never use (list?) in Clojure unless you explicitly need to check for a list created via (list ...), and most of the time we use (seq?) instead. Maybe Clojure doesn't work for you because you haven't even bothered checking the documentation? At least you could've asked Google or ChatGPT, before crying how "broken it is". The language after all wasn't created last weekend, it's been around for 17 years