NHacker Next
login
▲Show HN: Using Common Lisp from Inside the Browserturtleware.eu
78 points by jackdaniel 6 hours ago | 12 comments
Loading comments...
adamddev1 5 hours ago [-]
Ah, in an alternate world where Brendan Eich wasn't pressured by his superiors to make JS more Java-like, we could have had something like this as very normal.

I wonder how much faster that would have pushed the world into FP ideas. While sometimes I prefer the bracket/C syntax, I wonder how things would have evolved if JS was a lisp originally. Instead of things moving to TypeScript, would they be moving to something like typed Lisp or OCaml, or PureScript ?

umanwizard 4 hours ago [-]
Is CL really particularly more “functional” than JavaScript? I don’t know CL but I know it bears some passing similarity to Emacs Lisp, which is usually written in a pretty imperative style. Sure, it has first-class closures but so does JS.
iLemming 52 minutes ago [-]
Both CL and Elisp are arguably more functional than Javascript in several key ways - Immutable data by convention, First-class function from the start (js added this later), powerful higher-order function are more idiomatic, lexical closures, FP culture that goes back decades. JS has caught up in some aspects - arrow functions, array methods, const, libs like Rambda.

I think, Lisp in general is very flexible - you can write imperatively, or you can do more FP; if you need object-orientation - you have it, polymorphic dispatch - sure why not?, etc., etc.

wk_end 2 hours ago [-]
I kind of agree, but in the interest of discussion: even if CL isn't necessarily a more functional language in practice, culturally it's got a long history of being more functional. It took something like a decade at least for people to widely recognize to how elegant (in its quirky way) JavaScript could be. Just as a point of comparison (I'm sure the idea goes further back) PAIP - one of the definitive CL books - was first published in 1991 and encourages pure functions and immutability wherever possible.

Devs in the 90s were handed a language that looked like a weird Java and so they programmed it like a weird Java. If they were handed a language that looked like Lisp instead, maybe they would have made their way to SICP that much sooner.

taeric 3 hours ago [-]
As the sibling says, CL can be written in most any style. Which, I think it is fair to say for any general programming language? The book Exercises in Programming Style highlights that. That said, CL feels far friendlier to the various styles than other languages, to me.

Link to book on Amazon: https://www.amazon.com/dp/0367350203

jackdaniel 3 hours ago [-]
CL enables many paradigms of programming, including functional one and imperative. Currently the most popular way of programming among CL programmers is OOP with CLOS.
shadowgovt 25 minutes ago [-]
It's hard to predict. There's a nonzero possibility that in that world, developers would have rejected the Netscape scripting solution, embraced the alternative that VBScript support in IE briefly represented, and we'd either be in a world where Microsoft dominated the web because only their browser did the fancy stuff that web 2.0 ended up needing to support ecommerce... Or where a couple of mud-pit-fight court cases had resulted in a vbscript-alike being the lingua franca of web scripting because Microsoft lost their exclusive control over it.
bitwize 4 hours ago [-]
The JS backend to Gambit is now pretty mature. If you're willing to deal with Scheme, Gambit, and its FFI, you can live in that alternate "Scheme in the browser" universe even without WASM.
jackdaniel 4 hours ago [-]
There's also Guile Hoots compiling directly to WASM.
iainctduncan 38 minutes ago [-]
I will definitely look at this in detail. I'm doing something similar with S7 Scheme (a scheme that is heavily Common Lisp influenced), and it's working really well. Getting the plumbing going was a fair bit of work, but it's a huge win to be able to reuse my domain-code engine across the browser, C++ apps, and in Max/MSP (through my OSS Scheme for Max extension). Writing music theory related domain code is much nicer in a symbolic lisp family language than in JS.
octopoc 5 hours ago [-]
WebAssembly is about an improved Developer Experience. It lets us write in the languages we like :)

I can't say how many times I've reinvented pieces of Common Lisp to do my job. Now I want to start a side project with this.

shadowgovt 23 minutes ago [-]
My only concern with this approach from an ecosystem standpoint is that runtimes (and more importantly, their standard libraries) can be expensive. JS is still the heavyweight engine that everyone running a browser already has installed; a world where the browser has to download a novel runtime per website is going to be hard on the end-user on the back of a low-bandwidth connection.

... but it doesn't have to be that way. Proper tree-shaking of libraries and smart caching of common resources should make it possible for that cost to get minimized or amortized.