11 ms·
Clio: A functional, distributed programming language that compiles to JavaScript
- efdb 6y agoi really like the syntax, very intuitive use of ->
- runeks 6y agoI wonder if there’s such a thing as intuitive syntax. As far as I can see, the arrow signifies function application. Why do you consider “a -> f” more intuitive than, say, “f(a)” or “f a”?
- aloisdg 6y agobecause a -> f -> g -> h is better than h(g(f(a))). It is the functional way of doing the OOP fluent builder pattern: a.f().g().h() It is the pipe operator (F#, Elixir, Haxe, etc.). There is a proposal to add it to js too.
- mlajtos 6y agoOn top of that, it is a symmetrical to fat arrow functions, which is a shorthand for lambda: fun: x => x * 2 res: 4 -> fun
- vorticalbox 6y agoI have always used ramdajs for this. const R = require('ramda'); R.pipe(a,f,g,h)
- bijinpanicker 6y agoI added it on python. Check it in https://github.com/LangTrans/Py_Trans https://github.com/LangTrans/Py_Trans
- dvh 6y agoI made something similar (temporal distribution rather than spatial) an it was 70x slower than javascript, how slow compared to JS is clio?
- speedgoose 6y agoI wrote the fib example in plain JavaScript without async, just old recursively in a loop, and it ran twice as slow compared to Clio. It's not a very high quality benchmark, but the overhead doesn't seem bad on tiny examples.
- deleted 6y ago[deleted]
- SamBam 6y agoSince Clio compiles to JS, that speed up must be available in vanilla JS as well. Is it the use of web workers that makes that twice as fast?
- chrisseaton 6y agoClio has automatic parallelisation. JavaScript does not.
- mcherm 6y agoHow is generation of fibonacci numbers parallelized? I mean, I can think of some ways to do it but I have trouble believing that any compiler could generate them.
- chrisseaton 6y ago> How is generation of fibonacci numbers parallelized? Not sure if you're joking or not? Fib is the classic first parallel benchmark, especially for functional languages. The two tasks in each step are embarrassingly parallel. > I have trouble believing that any compiler could generate them Hah! I'd say I'd have a hard time believing compilers can automatically parallelise anything else... because fib is usually the only thing they're shown being able to do!
- e-clinton 6y agoBeautiful syntax indeed. Has a very rustie feel
- toolslive 6y agoI couldn't find any information on the type system, But by the look of it, there's no type inference. Is that correct?
- zemnmez 6y agoHow do you make a parallel language that transpiles to a reentrant one?
- chrisseaton 6y agoCan you use the Web Workers API and lower to a message passing model?
- twiss 6y agoIt seems like it uses Web Workers (https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers...)
- brundolf 6y agoTo get more specific for those who may not be as familiar with the nuances of JS: JS can start parallel threads, it just - importantly - cannot share memory between them (instead it must pass messages, copying data at boundaries). This eliminates a large number of benefits and usecases that tend to be associated with "multithreaded programming", but saying JS "isn't multi-threaded" isn't quite true.
- twiss 6y agoFor what it's worth, there's some limited ability to share memory (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...), though you can only share binary data, not other types, and it only works in secure and cross-origin isolated contexts, due to security concerns. That being said, at first glance it doesn't look like Clio is using this, instead it's passing messages as you suggest. It might actually be interesting to use SharedArrayBuffers as a compilation target, as they're probably hard to use correctly manually. That being said, WebAssembly threads (https://github.com/WebAssembly/threads https://github.com/WebAssembly/threads) may be more appropriate for this. For completeness, Workers can also transfer memory (https://developer.mozilla.org/en-US/docs/Web/API/Transferable https://developer.mozilla.org/en-US/docs/Web/API/Transferabl...) with less security restrictions. They can also collaborate by accessing a shared database (https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_A...) though this is obviously slower than shared memory.
- ubertaco 6y agoAs a heads up, on the front page for the language (https://clio-lang.org/ https://clio-lang.org/), there's a "Visit our tutorial page" link that 404's. There is a tutorial though, if you go to the "Learn" link, so prolly the other link just needs to be updated.
- avinassh 6y agoWhat is a distributed programming language?
- capableweb 6y agoDistributed computing is when you take a bunch of tasks one computer (or CPU/computing units of choice) usually do and spread it out to many computers (or CPU/computing units of choice). This is to give faster execution compared to if you did the work sequentially and is generally a pattern that is gaining more and more popularity as of late. A distributed programming language in this context means that the programming facilitates this paradigm so it's easy to do distributed programming with the language. In the case of Clio, it also means it is distributed by default, so you write code like normal and it's executed in a distributed fashion.
- keithalewis 6y agoA distributed system is one in which the failure of a computer you didn't even know existed can render your own computer unusable. - Leslie Lamport
- mirekrusin 6y agobtw. julia implements fantastic idea in its ssh cluster manager - such a simple thing yet so powerfull; without knowing much about the language I was able to distribute some computation across all computers I had at home, really awesome. As a side note it was also so easy to drop it on GPU. I'm really impressed by julia, I'd love to use it more at work.
- cies 6y ago> Suitable for scientific programming How's that possible? JS does not have a good reputation in sci prog, why would clio have?
- capableweb 6y agoBecause Clio is not JS, it compiles to JS? There is plenty of ways of making JS handle any "scientific programming" you can throw at it. It'll probably run slower than what you can do by default in python-land or Julia, but since Clio seems to automatically parallize your code, it might have a chance.
- cies 6y agoSorry that's just an unfair claim. With this explanation every general purpose programming language handles "scientific programming".
- capableweb 6y agoNo, that's a weird conclusion if I ever saw one. What can be claimed though is that any general purpose programming language "can be made to" handle scientific programming. I'm not saying you should, but it's possible for sure. Libraries like big.js for example make arbitrary-precision decimal arithmetic possible on JS, which many considered impossible to do in JS.
- mgerullis 6y agoV8 is quite a lot faster than python (in most comparisons, not all)
- Garlef 6y agoisn't python fast because it uses specific c++ (or c?) modules in the background? for example keras is a wrapper for tensorflow (c++). numpy relies on c if i understand this correctly.
- lelanthran 6y agoSo many programming languages popping up like mushrooms overnight... That does it - I'm creating my own programming language (again) which is going to be a mashup of C++ and Lisp; I shall call it "Thee-Pluth-Pluth".
- dastx 6y agoDon't forget the blackjack and hookers.
- lelanthran 6y agoActually, forget about the language.
- dunefox 6y agohttps://github.com/clasp-developers/clasp https://github.com/clasp-developers/clasp
- wealthyyy 6y agoI built my own language recently and called it Casi-no.
- egonschiele 6y agoIs this a bad place to post my language that compiles to JS and PHP? https://github.com/egonschiele/salty https://github.com/egonschiele/salty
- deleted 6y ago[deleted]
- crowdhailer 6y agoI'm struggling to get my head around why this is a distributed programming language. I saw the await key word for parallel fib but would like a bit more information about what's actually happening to be parallel.
- montebicyclelo 6y agoWould be interesting to see a discussion of this vs Elm, which I guess is the incumbent functional programming language that compiles to Js (?).
- transfire 6y agoI just want to know what the `-> *` is all about. I assume `->` is a pipe like sugar, but what about the asterisk?
- liminal 6y agoI think I worked out it's an array.map function that takes the same three arguments: (value, index, array)
- deleted 6y ago[deleted]
- coolreader18 6y agoHmm, I'm not sure about this at the moment, at least based on the available documentation - the first thing I tried to do was extend the "parallel fib" example to be fully parallel inside `fib` itself[0] but I wasn't able to figure out how to create a `sum :: [int] -> int` function at first (it wasn't clear that arrays are just JS Arrays, and I can just call methods on them) and I'm still not sure why my code doesn't output anything. [0]: https://clio-playground-pouyae.vercel.app/ https://clio-playground-pouyae.vercel.app/ with code: fn fib n: if n < 2: n else: [n-1 n-2] -> * await |fib| -> * console.log sum fn sum arr: arr.reduce add 0 fn add a b: a + b export fn main args: [5 6] -> * await |fib| -> * item: console.log item
- nudpiedo 6y agoI got a bit late to the party, but I have to say it looks awesome. It seems an ML + APL descendant. Looking forward for more as I see they are puting good design and pragmatism together first.