6 ms·
def twinPrimes := matchAll primes as list integer with | _ ++ $p :: #(p + 2) :: _ -> (p, p + 2) why do people do this? this is unreadable to me.
by 2h 3y ago
def twinPrimes :=
matchAll primes as list integer with
| _ ++ $p :: #(p + 2) :: _ -> (p, p + 2)
why do people do this? this is unreadable to me. what is the second line, a
comment? then they somehow found a way to cram 11 symbols in a single line after
that. bravo?
- wizzwizz4 3y ago| begins a pattern match. ++ is list concatenation. :: means "thing-on-the-left is of type thing-on-the-right". That's all standard Haskell syntax. Egison seems to introduce some kind of advanced pattern-matching syntax with $ and #. I can't figure out what it is, or how it works; but I imagine it's quite simple once you actually know what it means.
- tromp 3y agoInterpreting :: as a typing judgement makes no sense here. What does make sense is interpreting :: as a list "cons", i.e. as : in Haskell.
- kristopolous 3y ago> I imagine it's quite simple once you actually know what it means. The first part isn't notable. Olympian athletes, for example, do the most baffling of intricate movements in grace and simplicity. Instead it's the amount of effort and context to get to the understanding that's at play. Maybe this syntax is intuitive for a mathematician, formal logician or some other specialist, but as just a mere every day programmer, it looks like nothing I'm familiar with. This is fine. Just let's not pretend that it's low effort to get onboard
- kragen 3y agoit's probably low effort for a 'mere every day' haskell programmer; it's just a question of what you're familiar with, not actually deep math (minor correction, as tromp points out, :: is evidently list construction, as in ocaml or haskell, not a type annotation) you asked what `matchAll primes as list integer with` meant ('what is the second line, a comment?') but apparently the person who answered you didn't understand that you didn't understand. it means 'evaluate the expression `primes`, which should have the type `list integer`, and then attempt to match the value resulting from that evaluation against each of the following expressions in order' deep math isn't simple to do even when you know what it means; it isn't just a matter of learning what all the symbols mean. this is just a matter of learning what all the symbols mean, like reading english instead of chinese. so to me your complaint reads like someone saying (in chinese) 'just a mere every day reader of novels, it looks like nothing I'm familiar with' because some text is written in english however, the situation is not quite so symmetric as with chinese and english. with a good notation, cramming lots of symbols onto a line is a really good lever to empower your reasoning ability. consider trying to explain how to play the seventeenth measure of pachelbel's canon in words. or writing assembly instead of c, even though they're both at pretty much the same level of abstraction pattern-matching really significantly improves the clarity of certain kinds of code, and you're missing out if you don't know what that's like i'm guessing that #() (the only weird part) is analogous to ${} in `-strings in javascript or #{} in ""-strings in ruby: it embeds an expression to be evaluated in a context where you wouldn't normally expect expression evaluation, in this case a pattern for pattern-matching (disclaimer, i don't actually know haskell, though i've implemented my own programming language featuring pattern-matching)
- kristopolous 3y agoThanks. As a correction, the comment you are directly replying to is the only one that I personally made. I just happened to agree with the sympathies of the first person and was trying to rephrase things in a more productive and positive manner. I appreciate the response not only for myself but for others who may be reading it as well. Thank you for taking the time.
- kragen 3y agoi appreciate both the correction and the appreciation
- imtringued 3y ago>or writing assembly instead of c, even though they're both at pretty much the same level of abstraction They aren't.
- pasquinelli 3y agoit must be simple because this code is, i presume, runnable.
- kristopolous 3y agoThat's now how simple works. Malborge's "Hello World" is a single line! (=<`#9]~6ZY327Uv4-QsqpMn&+Ij"'E%e{Ab~w=_:]Kw%o44Uqp0/Q?xNvL:`H%c#DD2^WV>gY;dts76qKJImZkj Look at how compact that is! Must be simple! You can't claim simplicity by using character or line count.
- kragen 3y agothere are an awful lot of separate entities in that line
- crabbone 3y agoNah, this mess isn't intuitive to anyone. There also isn't anything like an agreed upon mathematical or logical notation. Everything in this field beyond the basics of algebra / set theory is awful one-off NIH languages with awful / inconsistent grammar that nobody beside the "inventor" can understand, while the inventor has perhaps a 50/50 chance of understanding their own writing. The lack of requirement of mechanically verifiable proofs and adherence to common standards of expression of mathematical concepts is a huge drawback of what happens in this area of academia. People who come up with languages like Haskell (which this one certainly is) are people who want the absurdity of languages created w/o system or any general design to spill over into the programming land. Solely based on the fact that they've been exposed to this cuneiform during their apprenticeship and learned to associate it with the actually valuable stuff it's meant to convey.
- lelanthran 3y ago> That's all standard Haskell syntax It's the reason Haskell has remained a niche language. > I can't figure out what it is, or how it works; but I imagine it's quite simple once you actually know what it means. You can't figure it out but you're sure it must be simple? Newsflash: if you, a 1 in a 500 programmer who knows Haskell syntax cannot figure it out just by context, it's nowhere near simple. Simple is when 9 out of 10 programmers understand the thing.
- lgas 3y agoYou're confusing simple and easy.
- lelanthran 3y agoFor the rare occasion when the author doesn't mean easy when they say simple, they should probably clarify that they mean non complex and difficult.
- kragen 3y agowords have different meanings; the root sense of 'simple' is 'one-fold', that is, only having one layer rather than two or four, and that sense is still present in phrases like the spanish hoja simple, meaning 'one-ply' (toilet paper, for example), but it's had multiple meanings for thousands of years including 'mentally disabled', 'honest', 'harmless', 'pure', 'unadorned', and, as you point out, 'easy' it's true that using a word with multiple meanings gives rise to ambiguity, and avoiding that by choosing a different word is desirable unfortunately there isn't a better term for 'simple' in the sense of 'not possessed of much detail' or 'composed of very few parts'; saying 'non complex' doesn't really help because 'complex' is often used to mean 'difficult' for the same reason 'simple' is often used to mean 'easy' except in hucksters' advertising brochures, i don't agree with your implicit assertion that all the polysemic complexity of 'simple' is merely historical, leaving only 'easy' as a live meaning; i think all the meanings i listed above except for 'harmless' have some currency today, even merely in english https://en.wiktionary.org/wiki/simple#Adjective https://en.wiktionary.org/wiki/simple#Adjective lists nine main meanings of which seven are current, though i admit i just added the 'easy' one myself; it wasn't listed previously (i think because of confusion induced by the polysemy of 'complicated')
- crabbone 3y ago"Quite simple" is the same thing as "left as an exercise for the reader", i.e. when someone couldn't be bothered to do things right / didn't know how to do things right, but made it work by shuffling and other kinds of rearrangements before it sorta worked. Maybe this language is simple to write if you know the rules. It won't be easy to read, ever, not even if this is the only language you have ever learned and practiced for decades.
- Avshalom 3y ago>why do people do this do what? write programming languages that you don't already know?
- pmontra 3y agoInvesting so much creativity into obfuscation of meaning.
- pasquinelli 3y ago>>> why do people do this >> do what? write programming languages that you don't already know? > Investing so much creativity into obfuscation of meaning. that's just saying the same thing in different words. of course the meaning is obfuscated to you, you don't know how to read it.
- junon 3y agoI don't know Ruby, and I'd argue it has dissimilar syntax to many other languages I use regularly (that's changed over the years but whatever, my point still stands). I can still read ruby code, because it's still readable. Same with Lisp, which I never bothered to sit down and learn until about a year ago. Prior to that, I still had no problem reading and understanding it (perhaps not as intuitively as someone who writes it regularly). The quoted example is, for all intents and purposes, gibberish to me. And I have worked with CoQ.
- roetlich 3y agoWell, and to me this syntax makes sense intuitively. And to most beginner programmers, all code looks very hard to understand. I'm really bad at understanding pgsql, I dont't like it at all. People just have different experiences. Ruby still has algol-like structure, like most common languages. And basic lisp syntax is "normal" function calls with the parens moved around. Of course, some things are objectivly more complex than others, but making that argument here requires a bit more evidence.
- galaxyLogic 3y agoI'm starting to see the allure of plain Lisp. All it has is functions and functions have names which convey a meaning. Plus some syntax for creating macros. Now CAR and CDR don't convey a lot of meaning I agree. But that's just a matter of poor naming. They should (in my opinion) be called 'first' and 'rest', or something similarly meaningful and descriptive. Of course short-hands and aliases are good for most often used functions. But I would prefer those to be aliases, with a proper descriptive name available as well. And operator precedence, that makes code in a different language really hard to understand. Parenthesis make it explicit. Keep it simple. That makes code more verbose but then you can use macros to make it less so.
- msla 3y ago> Now CAR and CDR don't convey a lot of meaning I agree. But that's just a matter of poor naming. They should (in my opinion) be called 'first' and 'rest', or something similarly meaningful and descriptive. Some Lisps do that, but I think it's important to remember what CAR and CDR actually do, which isn't always related to lists: They access what's being pointed to by the pointers in a cons cell, which can be used to create multiple data structures in a given Lisp, so keeping the names abstract prevents the code from having the wrong names all over the place. For example, if I'm using cons cells to construct a key-value store, CAR isn't "head of list" it's "key" and CDR isn't "tail of list" it's "value" especially if the cons cell looks like this: (a . b) such that the CDR isn't a list of any kind. In Common Lisp, of course, there are more efficient data structures for a lot of what older Lisps used cons cells for, so this is less of a concern, but I still think it's important to prevent confusion.
- galaxyLogic 3y agoGood to understand. So maybe key() and value() would be good, more descriptive names for them then. But I do think using a natural-language name like CAR even if very specialized, is better than using single-char symbols as function names.
- msla 3y ago
- hayley-patton 3y agoJust got it in my head after wondering the same. So we have some prefix of the list we don't care about (_) appended (++) to a variable ($p) consed before p + 2 (#(p + 2)) consed before a suffix we don't care about (_), then produce the pair (p, p + 2) for each match.
- crabbone 3y agoYeah... and nobody knows what happens first. It's impossible to follow the execution of this gibberish because nobody knows operator precedence, and even if that was somehow hard-wired into your brain, having to re-scan the same line multiple times and sort out the priorities still takes a lot of time and will fail for large-ish (5+ elements) problem instances because people cannot hold that many elements in active memory.
- mathgladiator 3y agoPeople do it because they work mostly in isolation or small groups of experts on things that compute values once from command line.