21 ms·
The Earl Grey programming language
- htilford 11y agoWhat was the inspiration to create yet another compile to JS language?
- brudgers 11y agoThe ubiquity of the browser one would expect.
- breuleux 11y agoI guess I wanted macros and pattern matching without Lisp syntax, and I wanted to retain and use the JS/node ecosystem. There's also a few language features I couldn't find anywhere else that I wanted to try out (my % operator, ad hoc exception classes, some pattern matching features like coercion and "match" inside a pattern to define sub-patterns, the each operator, some features of the macro system that I have yet to document, etc.) It's kind of fun, really.
- visarga 11y agoWhat does the % operator formally do? All I could find in the documentation was : > Earl Grey's % operator can be used to easily build HTML, DOM, virtual DOM, and other things:
- breuleux 11y agoThere are examples below that statement for common usage, but if you want a deeper understanding: tag.xyz % property = value child1 child2 Will produce the data structure: {tags = {"tag", ".xyz"} props = {property = value} children = {child1, child2}} as an instance of the ENode class. Then, transformer functions can process the data structure to generate HTML or other things, e.g. require: /html html(thing) ==> <tag class="xyz" property="value">child1child2</tag>
- ffn 11y agoBecause folks feel there is a need for them, and it's a really good way to get one's feet wet in the compiler pound. Besides, a programming language (dialect) is to a programmer what different size wenches, pipes, or hoes are to a plumber. You need different tools for different jobs and a lot of it depends on your personal preference and what it will take you to be efficient. Besides, how we as engineers solve problems is just as much an expression of our personality as it is a statement about the correct operation of systems. But that's just my view, and I'm definitely biased on the subject because I'm working on a flavor of coffeescript that will compile to msft's typescript as we speak (well, in my spare time).
- deleted 11y ago[deleted]
- mbroshi 11y agoLooks interesting, but odd that the very first code snippet is an infinite loop.
- breuleux 11y agoGod damn it how did I miss that. The condition was wrong, too. Fixed, thanks :)
- Dewie3 11y agoWhy not have a "Show HN" if you're the one who made it (assuming from the URL)?
- breuleux 11y agoI... actually did, a while ago. I got no feedback at all, so I thought I'd do things differently this time around. Might just be a matter of luck.
- kzhahou 11y agoThis is showing HN.
- saraid216 11y agohttps://news.ycombinator.com/item?id=8150346 https://news.ycombinator.com/item?id=8150346
- voteforchange 11y agoby the end of this century I fully expect there to be a joke about an engineer a lawyer and a woman walking out of a bar. Get on it.
- voteforchange 11y agoAlexander Wang had more imagination than these cunts. He put a slice in the middle of "let us be clear" What a cunt!
- voteforchange 11y agoWhatacunt! Its like a forward thinking husband who JUST who JSUST wants his fucking AMERICAN wife to settle down. TO SETTLE DOWN and Let him EAT her PUssy in their hotub. Can we PLEASE FOCUS on the HOTUB. Can a man eat his wife's pussy in a hottub without it appearing in the Pacific agreement now or ever or forever or quite especially. There are many forgotten roman tubs I'd luxuriate in squelching into. Ohh EE ohh aahhhh ahhh
- voteforchange 11y agoNo matter how many P's you put in front of it I spit!
- voteforchange 11y agoJames McDonough bleeds fresh grass smell onto my lawn which I evaluate and often men of my caliber.
- trafnar 11y ago"Oh god, do we need another language that compiles to javascript?!" —Everyone, probably
- yellowapple 11y agoThere shall be no peace until every language compiles to Javascript.
- webjprgm 11y agoDoes a VM of a PC count as a JIT compiler? Can we compile VirtualBox to JS using one of those C->JS compilers? I'm sure we can come up with some stack of turtles here ...
- bbrennan 11y agoJS is the new JVM. Write once, run anywhere is still the dream, I'm glad new programming languages are taking advantage of JavaScript's versatility.
- TazeTSchnitzel 11y agoIt's better than the JVM. It provides an excellent, high-performance runtime for dynamic languages (JS), and an excellent, high-performance runtime for static, memory-unsafe languages (asm.js)!
- toyg 11y ago> Write once, run anywhere is still the dream More like "write once, run in the browser". I don't think most compile-to-js languages care too much about "anywhere", they are just trying to get nicer alternatives in what is basically a platform (the browser) closed to anything except JS.
- fineline 11y agoThe examples in the article seem much more focused on NodeJS.
- deleted 11y ago[deleted]
- mikejholly 11y agoAwait, pattern matching and macros are great language features Node and CoffeeScript both lack. Nice work!
- pooriaazimi 11y agoIcedCoffeeScript had await/defer three of four years ago: https://github.com/maxtaco/coffee-script/ https://github.com/maxtaco/coffee-script/ But I agree, excellent set of features.
- thomasfoster96 11y agoAsync/await is coming in ECMAScript 7, so Node will have it soon.
- Dralletje 11y agoDefine "soon" haha. With the speed of adopting ECMAScript 6 this "soon" could become really long.
- shakethemonkey 11y agoHyphens in variable names. It's a bold strategy for a scripting language, Cotton.
- TazeTSchnitzel 11y agoImagine being able to type style.border-width in JS instead of style.borderWidth
- Shoop 11y agoI think a lot of lisps use hyphens in variable names
- shakethemonkey 11y agoThere's plenty of precedent. It's just rare for a reason. I'm not sure allowing slightly easier access to CSS syntax justifies it.
- yellowapple 11y agoOn the other hand, pinky fingers everywhere are collectively breathing sighs of relief from not having to push down the shift key nearly as often.
- fenollp 11y agofact(match) = 0 or 1 -> 1 n -> n * fact(n - 1) why not simply fact(0 or 1) -> 1 fact(n) -> n * fact(n - 1)
- istvan__ 11y agoI think the first one is a single function that has pattern matching for the parameter while the second one is defining the function twice and relying on the language to call the right one based on the parameter. I think in Erlang the function identification is the name and the arity and this is as close I know of what you would like to have.
- TheDong 11y agoIn haskell you can write exactly the following: fact 0 = 0 fact 1 = 1 fact n = n * fact (n-1) It works as you would expect and really they aren't that dissimilar.
- FreeFull 11y agoSmall correction, fact 0 = 1
- arh68 11y agoErlang does it very much like GP's suggestion with the one downside of being 'noisy' with its punctuation (some might say 'clearer'): factorial(0) -> 1; factorial(N) -> N * factorial(N-1). factorial(Foo, 0) -> .. ; factorial(Foo, Bar) -> .. . Semicolons separate partial definitions for a single function of a single arity, and periods end those definitions. Removing the punctuation might make parsing a bit more difficult (will there be more partial definitions?), so it's understandable to not offer it.
- Vignitus 11y agoOff-topic: I'm kinda new here, what does GP stand for ?
- sssilver 11y agoActually, the language looks and reads great. Keep up!
- childintime 11y agois it just me, tiring quickly of this syntax?
- webjprgm 11y agoI'm not a fan of using -> like CoffeeScript does. It doesn't seem to mean function-body / algorithm-to-do-the-thing to me. That operator makes sense for pointers or for function return value type expressions.
- breuleux 11y agoI think that's just because you are used to see it used that way. And it's not like CoffeeScript invented this. Haskell does it: \x -> x + 1 OCaml does it: fun (x : int) -> x + 1 It is very common in functional languages to use -> both for function bodies and return types.
- webjprgm 11y agoI suppose. Kinda like => for "maps to" in some math / theory classes.
- davenportw15 11y agoDoes 'each' serve as both forEach and map? It appears that way from the fib example.
- breuleux 11y agoYes. The compiler detects whether the return value is used or not to determine whether to accumulate the results in an array or not. Also, unlike forEach and map you can use continue or break.
- xxyyxx 11y agoI like it. It goes further than coffeescript and livescript can. Especially with macros and better react support
- makmanalp 11y agoI really like how the tooling to create a full application is already there, it isn't like "here's my new language, but there are no libraries, good luck!". > Global variables need to be declared to be accessible: > globals: > document, google, React If I'm getting this correctly, what a brilliant idea! Contain the shittiness by having one single location where all globals are declared. So very helpful.
- baldfat 11y agoAm I the only one childish enough to ask for the language to be called Earl Grey Hot in honor of Star Trek?
- gresrun 11y agoThe JS transpiler should be named 'picard'
- webjprgm 11y agoThis is also what I thought. I was disappointed to see no TNG references on the page.
- ianstallings 11y agoWe could always write a little utility in it called Engage to make things right.
- breuleux 11y agoI like Earl Grey tea, but I don't watch Star Trek, so it didn't even occur to me. Sorry about that :( On the other hand I have to admit I like the idea of calling utilities Picard or Engage, they have a nice ring to them. Hmm.
- baldfat 11y agoIf you do add those references the people will love you!
- myhf 11y agoIf we write a Webpack Hot-Module-Replacement plugin for it, the natural name would be earl-grey-hot.
- ChrisArchitect 11y agoimmediately went looking for a Tea.js.....
- ufo 11y agoThe "fact(match)" is very strange. In Haskell you have "lambda-case" and in Ocaml you have "fun" as syntaxes to define lambdas that pattern-match on the argument. That said, I really like the inclusion of async and a DSL for documents. These two are things that benefit a lot from having language support.
- breuleux 11y ago"fact(match)" is just making use of a generic feature: the "match" keyword in a pattern dictates that the body defines a sequence of sub-patterns to match at that position. An argument uses pattern syntax, so it works there, but it works in other situations, for example this contrived example: f(x, y) = match x: {m, n} -> match m: <= 0 -> n + y else -> m + n + y n -> n + y Can be rewritten: f(match x, y) = {match m, n} -> <= 0 -> n + y else -> m + n + y n -> n + y So you can match hierarchically like that (sorry if the example is strange, it's not supposed to mean anything).
- ufo 11y agoIs there any other language that does this? For me the second example doesn't look better than the first one.
- breuleux 11y agoI haven't seen the feature elsewhere. The second example looks better to me (syntax highlighting helps) and reduces redundancy and indent, but I guess views may vary on this. Good to know!
- ufo 11y agoIf your goal is to reduce redundancy than I think a "lambda-case" syntax might be a better fit. As a bonus it also lets you use this feature on anonymous functions! https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/syntax-extns.html#lambda-case https://downloads.haskell.org/~ghc/latest/docs/html/users_gu... http://stackoverflow.com/questions/1604270/what-is-the-different-between-fun-and-function-keywords http://stackoverflow.com/questions/1604270/what-is-the-diffe...
- petegrif 11y agoThis language has it down to a tea.
- karmakaze 11y agoHope it fares better than Ceylon.
- andrezsanchez 11y agoGlad to see this addressed CoffeeScript's silly issue of variable scope by just requiring a `var` statement like regular JS. Also, love the name :)
- visarga 11y agoI love the name but it will get mixed up a lot on Google searches. Just like it was with the TV series "24" that matched every 24 that was to be found online.
- loopbit 11y agoI typed 'earl grey language' and the first three results refer to this, the HN article is in fifth position. The same as typing '24 tv series' will mostly return relevant results.
- M8 11y agoWhat level of automated refactoring and IDE integration does it offer?
- myhf 11y agoThe maximum possible level: a self-hosting compiler.
- evincarofautumn 11y agoOne one hand, this is yet another syntactic reskin of ideas from modern imperative-land. On the other hand, it looks like a good one, by a thoughtful author who also cares about integration with existing platforms, and that’s not nothing.
- moomin 11y agoNow add an absolutely vital library called Milk and watch tea lovers everywhere shudder.
- relet 11y agoearl-mocha should be bad enough.
- IsTom 11y agoThere's nothing wrong with milk tea.
- spacemanmatt 11y agoMade correctly, earl grey (really any black tea) needs some milk fat to neutralize the tannic acid or it could turn your stomach.
- CocaKoala 11y agoI had actually noticed that I didn't feel great after drinking earl grey without milk, but never realized why. Thanks for mentioning this!
- spacemanmatt 11y agoTrue story: One day I was out of milk, but figured it wouldn't be too bad to go without and have my tea anyway. Dropped the kids off at school, lost my stomach in the parking lot. 8:00am, lookin' classy at the private school.
- spacemanmatt 11y ago...now it occurs that maybe the GP comment meant shudder in a good way. In which case, well played. Quite cricket, my good man.
- rev_bird 11y agoI've thought milk in tea was so silly for years, and you've changed my mind in one sentence. Thank you, did not realize there was a practical reason for making it... taste worse.
- Grue3 11y agoLooks like another Coffeescript. Braces/parens are not bad, they structure the code and make it easier for the eyes. Lack of punctuation is as bad as too much punctuation.
- explorigin 11y agoHigh-level comparison with Haxe: EG and Haxe share: - compiles to Javascript - Macros - Pattern Matching - async/await (Haxe requires a 3rd party macro lib, but it integrates well) EG has: - cleaner syntax - document-building DSL - "One of EG's primary goals is to be as compatible as possible with existing JavaScript libraries and frameworks and the node/iojs ecosystem." (Haxe makes compromises here to support other platforms) Haxe has: - static type-checking - dead-code elimination - support for more platform targets (PHP, Python, C#, Java and more) - years of experience
- deleted 11y ago[deleted]
- danneu 11y agoGreat README. Gives me a good sip of the entirety: the syntax, macros, patmatching, integrating with React, and even how to gulp it and write tests with it. Yet succinct enough to scroll in one swipe.
- dwg 11y agoAs someone who currently uses LiveScript professionally, I look forward to trying out Earl Grey. At first glance it looks very promising. I'm aware there are many people who don't see the value in creating "yet another compiles to JS language," or those who view them as simply "syntax sugar," but I for one very much appreciate the work done by yourself and others on similar projects.
- hderms 11y agoThis is just extremely exciting. I love the language design and it looks usable as all hell. First compile-to-js language I've ever seen that got me excited, let alone the first one that i'd actually use outside of the browser. Congrats.