browser engines 

webkit is still the only one which lets you do proper functional programming, huh

Follow

re: browser engines 

; { const sum = (() => {"use strict"; return (x,i=0) => x === 0 ? i+x : sum(x-1,i+x)})(); sum(5000000) }

Works On My Machine

· · Web · 3 · 0 · 0

re: browser engines 

@Lady based on this example being in JavaScript I assume you mean V8, then, rather than Webkit? I wonder why SpiderMonkey doesn't optimize tail recursion? I know they put quite a bit of work into supporting the WebAssembly tail calls extension efficiently, so there's some support somewhere in there already

re: browser engines 

@jamey no, i mean webkit (well, JavaScriptCore)

webkit has implemented PTC for ages: webkit.org/blog/6240/ecmascrip

chrome implemented in V8, but refused to ship, and eventually removed: v8.dev/blog/modern-javascript#

firefox bug is very sleepy: bugzilla.mozilla.org/show_bug.

more of a summary here: mgmarlow.com/words/2021-03-27-

re: browser engines 

@Lady I have learned a lot by reading all of those links, thank you 😁

re: browser engines 

@jamey i’d be very interested in <bun.sh/>, which is built on JavaScriptCore instead of V8, because i do think JSC is generally the better runtime (well, and i don’t like Google)

but unfortunately i don’t care at all about the kind of development they are targeting and my needs are much better served by Deno

re: browser engines 

@Lady at work I've been helping a bit to hack on SpiderMonkey, contributing to the effort my teammate Chris started and wrote up (cfallin.org/blog/2023/10/11/sp). we compile SpiderMonkey as a WebAssembly module so we can run JavaScript in our serverless platform without needing to trust the JavaScript implementation. I've learned a lot about that particular JavaScript implementation in the process and yet there's still so much more to learn

re: browser engines 

@Lady why are you creating sum from a factory?

re: browser engines 

@wallhackio proper tail calls are only a thing in strict mode, which can't be set in functions which take default parameters, so i threw an IIFE around it

re: browser engines 

@Lady oh I did not know that. Thanks

re: browser engines 

@Lady i keep furgetting that tail call optimization is actually in the standard, not that it means anything in purractice

re: browser engines 

@aescling technically it is not “tail call optimization” but “proper tail calls”, meaning that tail calls can’t overflow the stack, but they don’t have to be any faster than other calls (some complain PTC is actually harder to optimize)

re: browser engines 

@aescling anyway it could mean something in practice if you built your JS runtime on top of JavaScriptCore instead of V8…

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.