TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Egison Programming Language

99 pointsby ubavicabout 2 years ago

11 comments

barristerabout 2 years ago
Here is my brief explanation of the example given on the website in order to clear up some confusion, that I gleaned from the thesis paper. Admittedly, this language does require knowledge of Haskell to really comprehend:<p><pre><code> -- Extract all twin primes from the infinite list of prime numbers with pattern matching! def twinPrimes := matchAll primes as list integer with | _ ++ $p :: #(p + 2) :: _ -&gt; (p, p + 2) </code></pre> &quot;matchAll is composed of an expression called target, matcher, and match clause, which consists of a pattern and body expression.&quot;<p>In the example `primes` is a list of primes as in Haskell: `[2,3,5,7...]` considered the &quot;target&quot;, and the &quot;matcher&quot; `list integer` may be thought of as a Haskell type like `[Int]`. So I suppose you could simply write it as `primes :: [Int]` and mean the same thing. This notion of a &quot;Haskell list&quot; is important because in the &quot;match clause&quot; the &quot;pattern&quot; is a combination of concatenation using the operator `++` and cons from Lisp using the operator `::`---note that this deviates from Haskell syntax in a somewhat confusing way where Haskell uses `:` and `::` for typing. Nonetheless, the integer list is deconstructed according to concatenation first, in every way, i.e. `[] ++ [2,3,..]`, `[2]++[3,5..]`, etc.., then according to cons&#x27;ing with the head stored in the variable `$p`. Yet, the &quot;rest&quot; of the list in this case is actually matched according to the pattern `x::y::_`, therefore, the second element must be 2 from the first, which is why the first pattern `[]++(2::3::_)` is discarded. The `#p` notation simply means to reuse the previous value of p to create a literal match, therefore for the first pattern `p is 2` and `#(p + 2) is 4` thus the pattern becomes 2 followed by 4 followed by the rest, which again doesn&#x27;t exist. Finally if a match does exist, the values are constructed according to the &quot;body expression&quot;, in this case a pair, and all of the results kept in a list. Therefore the type of this value is<p><pre><code> twinPrimes :: [(Int, Int)]</code></pre>
评论 #35794807 未加载
sidkshatriyaabout 2 years ago
I really like this language. Very intuitive and simple syntax (once you understand the fundamentals). And very powerful too! The pattern matching examples get addictive after you&#x27;ve read a few.<p>Egison can be used to build a symbolic math backend and do all kinds of pattern matching. But its really niche requirement and it&#x27;s never really occurred to me in all this time &quot;hey, this might be a good time to use Egison&quot;<p>I wonder when it might be a good idea to use Egison and if there are some current users in production.
评论 #35757685 未加载
dangabout 2 years ago
Related:<p><i>The Egison Programming Language</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=17524239" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=17524239</a> - July 2018 (67 comments)<p><i>Egison – Pattern-matching-oriented Programming Language</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7992661" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7992661</a> - July 2014 (33 comments)<p><i>Egison: A Lisp Written in Haskell with Advanced Pattern Matching</i> - <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7924168" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=7924168</a> - June 2014 (27 comments)
wizzwizz4about 2 years ago
It looks interesting, but I don&#x27;t understand the syntax. The only documentation is a doctoral thesis, which contains the usual padding:<p>&gt; Interestingly, this basic definition of map has been almost unchanged for 60 years since McCarthy first presented the definition of maplist in [62].<p>but it jumps from what looks like standard Haskell, to the new syntax, without explanation.
评论 #35756267 未加载
评论 #35756112 未加载
2habout 2 years ago
<p><pre><code> def twinPrimes := matchAll primes as list integer with | _ ++ $p :: #(p + 2) :: _ -&gt; (p, p + 2) </code></pre> 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?
评论 #35757245 未加载
评论 #35758609 未加载
评论 #35757259 未加载
评论 #35758950 未加载
评论 #35756301 未加载
crabboneabout 2 years ago
Another Haskell-style cuneiform where a ten-lines-long function will give you a massive headache for days before you can decipher it.
pasquinelliabout 2 years ago
&gt; Egison makes programming dramatically simple!<p>that doesn&#x27;t mean anything, it should be &quot;Egison makes programming dramatically simpler!&quot;
评论 #35761506 未加载
评论 #35758038 未加载
sevensevennineabout 2 years ago
This is not hard to read. The main novelty is pattern matching itself, which is making its way into languages that are used (java, javascript, etc) from languages that are interesting (Haskell, lisp, etc)<p>Take a look at this example from the text, which contains an obvious domain modeling error while demonstrating cool things:<p><pre><code> def suit := algebraicDataMatcher | spade | heart | club | diamond def card := algebraicDataMatcher | card suit (mod 13) def poker cs := match cs as multiset card with | [card $s $n, card #s #(n-1), card #s #(n-2), card #s #(n-3), card #s #(n-4)] -&gt; &quot;Straight flush&quot; </code></pre> This matches a new kind of poker hand called the &quot;wrap around straight flush,&quot; where a straight can wrap around Q, K, A, 2, 3.<p><pre><code> assertEqual &quot;poker hand 1&quot; (poker [Card Spade 3, Card Spade 2, Card Spade 1, Card Spade 0, Card Spade 12]) &quot;Straight flush&quot; TRUE </code></pre> IOW, in their eagerness to demonstrate a really cool match on a mod 13 expression (something I haven&#x27;t seen before), the author models the domain incorrectly.<p>It&#x27;s also somewhat confusing that the cards are modeled as n-1 - ace=0, 2=1, 3=2, etc, which is also confusing. I tried for about 10 minutes to fix it, but the only notation documentation I found is math that is way over my head.
1letterunixnameabout 2 years ago
For systems use, binary manipulation is essential. Elixir&#x2F;Erlang&#x27;s binaries are nearly optimal in this regard. I maybe wrong, but it doesn&#x27;t seem far removed to include such features.
omneityabout 2 years ago
I’ve had the chance to chat with the author of Egison a while back. A brilliant character.
BaculumMeumEstabout 2 years ago
if i wanted abstractions for the problems this language aims to solve i would personally prefer to either find a suitable libraries in lisp or write some myself than learn an esoteric language where i don’t know how it works under the hood
评论 #35758415 未加载