Clojure vs. Lisp: Why not concrete dotted pair in Clojure? [closed] - clojure

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
In this discussion, a poster (mikera) says
There's no dotted pair in Clojure.
A philosophical reason for this is that Clojure avoids the use of a
concrete "pair" data structure and instead emphasises abstract
"sequences" which can have may possible concrete implementations.
Can someone elaborate or point me to some literature on what this means? Is this a more elegant or mathematically pure approach?

Here is a link to a handy list of questions that Rich has answered about his design decisions https://gist.github.com/reborg/dc8b0c96c397a56668905e2767fd697f
While this list doesn't explicitly explain why there is no concrete "pair" data structure it might give you some insight into Rich's preference for practical, general design.
I remember there was a time when there was a discussion about introducing a "tuple" which would have been like a vector that only has two elements to avoid the needless memory allocation that occurs when using a two element vector.
Introducing these things has a complexity cost and so you can assume that the cost/benefit analysis did not warrant adding it to the code base.
Check out this discussion on Clojure's Jira project about adding tuples and you'll see how any idea gets put through its paces:
https://dev.clojure.org/jira/browse/CLJ-1517

Related

Is there a nice naming convention for nonempty lists in Haskell? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 24 days ago.
This post was edited and submitted for review 24 days ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
For example, if I have a list of names names :: [Text], and I construct a NonEmpty Text from it, I could call it neNames, names', namesNonEmpty. Is there a standard (preferably short) convention for this?
A silly question, I know, but I'd like to know people's opinions on this. Naming is, after all, one of the two hard problems in computer science.
Edit: Apparently I'm not allowed to ask for people's opinions. However, the rest of the question still stands. Whether or not there is a standard convention for this is certainly something for which it is possible to provide citations.
Not that I'm aware of, but you might be able to borrow the convention from monadic parsers of using a 1 suffix to identify "at least one". We have sepBy and endBy when parsing zero or more things, and sepBy1 and endBy1 when parsing one or more things.
So, names and names1 might do it.
Ideally, you would try to design your datatypes so that you never have to name names at all, if an empty list of names indicates an invalid state, though I understand you might be validating an existing data structure where names can be empty into a new data structure where names1 must be non-empty.

Meaning of these particular pointers [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I'm hesitant to consider this a valid question so close or downvote if you wish, I promise not to be offended :-)
I've just been watching Herb Sutter's excellent CppCon2018 talk on making C++ more powerful and simpler at the same time. I'd strongly suggest watching this if you haven't already.
Near the end, he references an xkcd cartoon on pointers, where the three pointers given are suspiciously ASCII in nature(a), usually a sure sign that you've somehow got yourself a corrupt pointer.
The three pointers are 0x3a28213a, 0x6339392c and 0x7363682e, which equate to the three character blocks :(!:, c99, and sch. (though endian issues may reverse the order of the characters).
Does anyone know if there's any significance to these pointers?
(a) Yes, I also noticed the ASCII in Homer Simpson's 3d episode sequence, meaning I've been in this game way too long :-)

Variant vs Inheritance [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Let's suppose I'm writing a compiler for some programming language. It is common to use abstract syntax tree (AST) as an internal representation. I can see two possible ways to design it:
using boost::variant
using inheritance
As hierarchy of nodes is fixed - boost::variant will suffice.
My question is what are the advantages and disadvantages of each approach from points of maintability and runtime efficiency?
Using boost::variants will work, but will require you to use visitor pattern extensively to exploit the content of a variant object. If later you extend the number of types used in your variant, you'll have to maintain all the visitors that you've implemented.
With inheritance, you have the advantage of being able to use polymorphism. Later extension will be straightforward : simply derive one of the existing base and override the polymorphic functions, without touching the rest of the code.

ASTs: prefer inheritance or variants? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In object oriented languages, it is fairly common to implement ASTs (Abstract Syntax Trees) using simple hierarchies (the Composite pattern), and to traverse them via visitors.
In functional programming languages, using variants/sum types, and then pattern matching, is the right approach.
C++ features both inheritance, and Boost.Variants. I have written several AST hierarchies using inheritance, but I'd like to get some feedback from people who would have used the variant approach. I'd like to know which one is the "best", in terms of performance (time and space), but also in terms of maintainability (easiness to create trees, and to traverse them).
I am especially interested in experience with implementation of hash-consing (keeping a single copy of each common subtree), possibly with Boost.Flyweight.
I am interested in battle field experience, not opinions. This question was original closed as "opinion-based". Which has never been the point...
Thanks!

What is meant by a "clean object model"? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I've heard systems described as a "clean object model", but a precise definition does not seem to be around. It seems to refer to the classes being complete or consistent in some way.
I'm just wondering if it's referring to a specific trait or just another favorable term like 'elegant'.
Quantlib is described as "written in C++ with a clean object model".1
It's not really a technical term. A "clean" object model is a well-designed one, by whichever standard of good design. Usually it involved orthogonal classes with a clear separation of concerns and an intuitive mapping to real-world concepts, i.e. a lot of fuzziness that you'll need to judge for yourself.