Lurker News

Comments (131) 24 threads

Show all comments

Showing thread 11 of 24

chubot1 reply#
Wow, when did the C-JavaScript polyglot thing happen? I don't recall that, and looking back on the October article, it doesn't mention that. What's the motivation for it?

https://news.ycombinator.com/item?id=29047584
I would expect that to add a constraint that makes the code bigger, not smaller? Or I'm probably misunderstanding how the different variants of the interpreter work.

jart2 replies#
SectorLISP has always had a C implementation for explainability. It started off as ugly C because it was actually used to generate the assembly code for the first ~900 byte version. See https://github.com/jart/sectorlisp/blob/a561e031aec03270459f... and https://github.com/jart/sectorlisp/blob/a561e031aec03270459f... Once we reached 512 bytes I started deleting a lot of the C code since things like assembly macros weren't needed anymore, since the assembly was now being written by hand. https://github.com/jart/sectorlisp/blob/main/lisp.c

Once I cleaned up the C code, I noticed that the entire program didn't use pointers at all! (Except of course to interop with Bestline, but that could be replaced with fgetwc() instead). That's when the idea occurred to me that, since it didn't use pointers, it was also technically valid JavaScript too. So I asked around on Twitter to see if anyone's done a C / JS polyglot before. I got some helpful tips from a code golfer in Estonia who experimented with the idea and he told me about the paragraph separator trick. https://twitter.com/angealbertini/status/1463755612345540611 So I updated the C code to hybridize the two: https://justine.lol/sectorlisp2/lisp.js It's a shell script and a C program and it runs in the browser unaltered without needing to be compiled.

int_19h1 reply#
For the sake of just-for-lulz purity, you could #define var auto instead, and then it wouldn't have any uses of int in the code at all.
jart1 reply#
Wow. I didn't notice that. A real C program without types, pointers, or macros. Who'd've thought such a thing would be possible!
int_19h#
It kinda makes sense when you remember that implicit int is there in K&R C for compatibility with B (which only had one type, the machine word).

B might be an interesting choice of language for an uber-minimalist compiler, by the way.

machawinka#
This blew my mind.