3 ms·
A new C++ back end for ocamlc
- QuadmasterXLII 6mo agoBrilliant stuff. A tip for writing long-running C++: bizzarely, the C++ interpreter completely lacks tail call optimization. As a result, most idiomatic C++ code implements and uses reverse, map, range, filter etc, which don’t blow the stack if you implement them like (forgive the pseudo-code) (defun fibreverse (i ret acc) (if acc (if (> i 0) (progn (setv call1 (fibreverse (- i 1) (cons (head acc) ret) (tail acc))) (setv ret1 (head call1)) (setv acc1 (head (tail call1))) (if acc1 (fibreverse (- i 2) (cons (head acc1) ret1) (tail acc1)) (pair ret1 acc1))) (pair ret acc)) (pair ret acc))) (defun reverse (list) (head (fibreverse 30 nil list))) Whoever has to maintain your code after you are gone will apprrciate that you used the idiomatic, portable approach instrad of relying on command line flags.
- deleted 6mo ago[deleted]
- dnmc 6mo agoIs this the Stephen Dolan of "mov is Turing Complete" fame?
- loeg 6mo agoI believe so.
- dolmen 6mo agoIs this the Stephen Dolan creator of jq? https://jqlang.org/ https://jqlang.org/
- deleted 6mo ago[deleted]
- LeonidasXIV 6mo agoYes, its exactly that Stephen Dolan.
- hudsonhs 6mo agoShe (Jane Street) is not gonna notice you, bro
- shorsher 6mo agoI believe they already work for Jane Street.
- binarycrusader 6mo agoIndeed: https://blog.janestreet.com/author/sdolan/ https://blog.janestreet.com/author/sdolan/ https://signalsandthreads.com/memory-management/#:~:text=Stephen%20Dolan%20works%20on%20Jane%20Street%E2%80%99s%20Tools%20and%20Compilers%20team%20where%20he%20focuses%20on%20the%20OCaml%20compiler. https://signalsandthreads.com/memory-management/#:~:text=Ste...
- znpy 6mo agoInteresting fact: it was recently "revealed" in a podcast episode by Bryan Cantrill that Jane Street was one of the early customer of the Oxide Computer company.
- zorobo 6mo agoThis made my day, thank you!
- Caum 6mo ago[flagged]
- kristjansson 6mo agoPer TFA C++ is a purely functional, interpreted language. Should be trivial to embed into?
- fayash 6mo agoMight have missed the joke here. This isn't a traditional C++ backend; it's a C++ Template Metaprogramming backend. The code isn't meant to be run—it’s meant to be compiled. The "output" you see is actually just a compiler error message because the program forces the compiler to calculate primes during type checking. The "runtime performance" the author mentioned is actually just how long g++ takes to crash your ram.
- tux3 6mo agoThis account is low-effort spam, the LLM generated comment seems to only look at the title. They should at least feed the contents of the page to the AI if they're going to spam.
- ygritte 6mo agoAccounts like that should be deleted.
- anitil 6mo ago> Using these more sophisticated data structures, g++ is able to compute the prime numbers below 10000 in only 8 seconds, using a modest 3.1 GiB of memory. Finally, I can get some primes on my laptop!
- ajbt200128 6mo agoWow Stephen Dolan never fails to impress
- foltik 6mo ago> which produces primes.cpp, containing your program translated to idiomatic, readable C++ code: As a C++ enjoyer I can confirm this is some excellent idiomatic, readable C++ code.
- sheepscreek 6mo agoMost of it yes, but what about: typedef I<((I<((n::val (p::val))>::val) != (I<0>::val))> res; }; There is some top class wizardry going on there! I don’t think I’ve ever used conditions in a type definition in C++ :) Update: Ah, alright - so that evaluation logic is part of the template, not the code that eventually compiles. It’s basically offloading some of the higher level language compiler logic to the templating engine. Honestly might be a better time investment than spending more time writing this in the parser. Now I’m sort of intrigued and inspired to use C++ as a lowering target for elevate (a compiler framework I’ve been working on).
- blanched 6mo agoMy eyebrows raised at "C++ is a purely functional language", but I thought it was just a typo. The rest is fantastic, and I'm glad it wasn't a typo.
- classified 6mo ago> C++ is a purely functional language, with no support for mutable state. > To run a C++ program, you'll need a C++ interpreter. I thought 1. April is already over?