Lurker News

Comments (131) 24 threads

jjice1 reply#
Everytime I see this domain I know I'm in for a treat. I assume the Dev's name is Justine, and they're one hell of a programmer. Pretty sure Actually Portable Executables are from this dev as well, which are also incredibly interesting.
jart4 replies#
Author here. Thanks! The other projects I'm known for here on HN are:

https://news.ycombinator.com/item?id=26271117 Redbean (2011) is a single file distributable web server. Here's a video of me giving a talk about it https://youtu.be/1ZTRb-2DZGs
https://news.ycombinator.com/item?id=24256883 αcτµαlly pδrταblε εxεcµταblε (2020) lets you build c/c++/fortran/etc. code so that it runs on seven operating systems
https://news.ycombinator.com/item?id=13769727 Operation Rosehub (2017) where I helped save a lot of people from an Apache security bug similar to Log4j issue today
I like doing these projects because they all fit together so well into a consistent story. For example, a lot of these past projects were what helped to make SectorLISP better. Thanks to APE you now have a 20kb quickly deployable and embeddable LISP interpreter. Thanks to Redbean we're going to have an online pastebin service that'll let you publish SectorLISP gists in a few days, for example: https://lisp.pub/1
Thank you Hacker News community for being so supportive and encouraging.

MonkeyClub1 reply#
Awesome work, and very enjoyable to read, kudos!

> αcτµαlly pδrταblε εxεcµταblε
You mean ακτυαλλγ πορταβλε εχεκυταβλε?

haakonhr1 reply#
Shouldn't it be: πορταμπλε (since β actually is a "v" sound so μπ is used for our "b")

Continue this thread — 1 reply

Datagenerator#
Congratulations on all your progress especially creating the worlds tiniest programming language in the world with GC!
deknos1 reply#
Hey, i have a question regarding your projects! and before that, i am a huge fan of redbean, this is so cool! as long as the world has also people like you with that cool stuff in it, there's still some fun and hope in the world.

but for the question: for your projects, do you have like a stable buildplatform (like nixos, minimal debian stable or sth like that) for which you publish your build instructions for your project?

jart1 reply#
I used to do a lot of work on Bazel. I wrote its downloader code for example. https://github.com/bazelbuild/bazel/commit/ed7ced0018dc5c5eb... Bazel is nice, but these days I'm running a small scrappy operation, so I just use GNU Make. https://github.com/jart/cosmopolitan/blob/7064d736e3ded15087...

I like Make since it's able to build a repository with 17k .o files, 80 .a archives, and 661 .com executables from scratch in under a minute on one personal computer (if the kernel page cache is warm). I wrote a couple small helper commands to make the make config more manageable, like package.com, mkdeps.com, compile.com, ar.com, zipobj.com, and runit.com.
The reason why Make works for me, is because I think the root cause of needing things like Autoconf and Cmake is because most projects need to depend on seven different C libraries. I decided that, rather than focusing on writing a better build config, I'd rather use an unfancy build system and instead devote my energy towards having a single C library that runs on all seven of the platforms I'm targeting. I owe a lot of thanks to projects like musl, dlmalloc, dtoa, llvm, etc. from whom I borrowed source code. That enabled me to abstract portability at the libc level, rather than punting to #ifdefs and configs.

Continue this thread — 1 reply

Ericson2314#
How do I get you interested in the Nix ecosystem? It's a great sandbox for all sorts of portability and bootstrapping experiments.
MaxBarraclough6 replies#
Very impressive.

> SectorLISP uses what we call an ABC garbage collector and it took only 40 bytes of assembly.
> [...]
> Fast immediate garbage collection with zero memory overhead and perfect heap defragmentation is as easy as ABC when your language guarantees data structures are acyclic.
Neat, but my understanding was that even pure functional languages can't generally make this guarantee, because things like letrec complicate matters. If SectorLISP can take this approach, why doesn't Haskell? (Or does it?)

WJW1 reply#
I'm pretty sure that Haskell supports cyclic data structures and that GHC garbage collection is more complicated than that. See for example the presentation by Ben Gamari over here: https://www.youtube.com/watch?v=EQqBpVRA3wU. Haskell GC is a generational copying design. Optionally you can enable the low-latency GC in newer runtimes, which is still generational and copying for the youngest generation but uses a parallel mark-and-sweep algorithm for the later generations.
__s#
Potentially cyclic values are statically known

But yes, GCs have evolved in the past decade, so these things are subject to change

kmill#
That page is incorrect about GHC's memory management -- I verified this with a question to haskell-cafe around 2014, and I guess no one got around to updating it.

The linked paper at the bottom of the article explains how things work and have worked for a long time now. The source of cyclic references, and even references from old to new generations, comes from "thunks" (unevaluated lazy computations). Haskell guarantees that a thunk only ever gets evaluated once, and the way this is implemented is that the thunk is mutated with a pointer to the evaluation result.
So the garbage collector needs to deal with mutations, cyclic references, and references from old to new generations. (All that in a language with supposedly immutable data!)

aidenn01 reply#
I mean even a doubly-linked list is a cyclic data structure...
MaxBarraclough#
Sure, but presumably they can't be expressed in SectorLISP.
ridiculous_fish#
I believe Erlang makes this guarantee and exploits it in the GC:

...the terms are immutable and thus there can be no pointers modified on the old heap to point to the young heap
so old objects cannot refer to young objects. This means it doesn't have to deal with write barriers, etc.

supergarfield2 replies#
Letrec requires either laziness (which implies some sort of internal mutability, as thunks get replaced by values at some point), or "internal" mutability that may not be visible to the programmer (like in OCaml, where in a `let rec` some variables will initially be null pointers, and get updated once other definitions have run).

In languages with no mutability at all (not even internal mutability like with these two features), you can't create cycles and refcounting becomes possible, but I'm not aware of non-academic general purpose languages that actually fall in this category.
Esoteric functional languages like Unlambda do make that guarantee, and implementations can use a ref counter as their GC.
I've written more about this here: https://terbium.io/2019/09/cyclic-immutable/

macintux1 reply#
> I'm not aware of non-academic general purpose languages that actually fall in this category.

Erlang?

masklinn#
Erlang does have some mutability (the process dictionary, and the mailbox), but the fact that the language is largely immutable is leveraged by the GC: if I remember correctly the private heap GC is a generational semi-space copying GC, but because the language is immutable it doesn’t need to have write barriers, to perform a minor collection only a scan of the stack(and process dict) is necessary to know the valid roots of the young heap.
isaacimagine#
If data is immutable and you tie the lifetime of data to a single stack frame, you only need a single bit for reference counting: whether the current frame owns the reference. Calling a function just requires setting this to bit low (some asterisks here), and all objects tied to a given frame can be collected when the frame returns.
IsTom3 replies#
Strict purely functional languages will sometimes provably introduce log n slowdown that can't be amortized away. This is certainly a trade-off.

This doesn't happen when you've got mutation or laziness.
One language that I'm aware which makes this tradeoff is Erlang.

foldr1 reply#
Elm is also strict and purely functional.
masklinn1 reply#
elm does not have its own runtime so this discussion doesn’t really apply.

Continue this thread — 1 reply

mixedmath1 reply#
When you say log n slowdown, what is n here? The length of the program? Or something completely different?
dan-robertson5 replies#
I think the theme is ‘you can’t do arrays; the best approximation is made of trees, hence log n in the size of the array vs 1’.

Continue this thread — 5 replies

tooltower1 reply#
If you are talking about Pippenger-Fischer theorem, then that's about Turing machines, not machines with RAM. Or is there another theorem I don't know about?
jart2 replies#
Author here. Why would it? Let's have a look at Scheme letrec (or let* in Emacs Lisp) translated to pseudo-SectorLISP:

    (LETREC ((IS-ODD?  (QUOTE (LAMBDA (X) (CAR X))))
             (IS-EVEN? (QUOTE (LAMBDA (X) (NOT (IS-ODD X))))))
      (IS-EVEN? (QUOTE (NIL T NIL T))))
The oldskool LISP way of writing that is:

    ((LAMBDA (IS-ODD? IS-EVEN?)
       (IS-EVEN? (QUOTE (NIL T NIL T))))
     (QUOTE (LAMBDA (X) (CAR X)))
     (QUOTE (LAMBDA (X) (NOT (IS-ODD X)))))
As far as I can tell, letrec is just a nicer syntax for the same thing. So I don't know why it should require any mutability. It works probably because LISP is dynamically scoped. Most languages and modern LISP implementations prefer different scoping models to make the Assoc() equation faster. However that comes at a cost, since it can turn the difficulty of LISP up to 11. Next thing you know, you're discovering things like the Y combinator. So I have major respect for what languages like Haskell and Scheme are doing, because it's incredibly difficult. One of the reasons why I created SectorLISP is because I wanted to have a fun bastion of simplicity when I don't need the more mature tools.

SectorLISP doesn't have any kind of internal mutability last time I checked. But I have experimented with it. For example, the Peel() optimization described in the blog post is how we solve the "make Assoc() faster problem". As it's written in the blog post, it's 100% pure. But if you introduce a tiny bit of mutability, it can go even faster on benchmarks even though it doesn't change the complexity class. See https://justine.lol/sectorlisp2/fast.js

dan-robertson3 replies#
I think you’ve a trivial error in your function definitions but I don’t think it’s relevant.

I think you’re right about avoiding cycles. I think the parent was talking about a let rec construction for data, e.g. in Haskell:

  let funky_list = 1:2:3:4:funky_list
(Note that : is the cons operator).

If this is allowed then you may have issues. I think the problem is perhaps that the GC won’t work if you have pointers in the opposite of the normal direction. The fix though is relatively simple: add forwarding pointers (somehow), then after copying from the ‘B’ region to the ‘C’ region you leave behind a forwarding pointer and, if you see it again in your copying, you don’t make a duplicate copy of the data. Then I think you can proceed as before. But representing forwarding pointers efficiently is hard, I suspect.
Actually I think I don’t understand the GC sufficiently. Do you end up with a lot of memory usage after this or a little?

  ((LAMBDA (D Z) (D Z))
   (QUOTE (LAMBDA (X)
     (COND
      (X ((LAMBDA (Y) (CONS Y Y)) (D (CDR X))))
      ((QUOTE T) (QUOTE T)))))
   (QUOTE (A A A A A A A A)))
This should get you a binary tree about 8 levels deep with T on every leaf, and I think it should use linear memory (in the depth of the tree) but I don’t understand how the GC avoids ending up with an exponential amount of memory being used?
jart2 replies#
Ah yes I missed that that when posting my earlier comment.

As for your example, it uses exponential memory because your example produces exponential data. The only thing I'd need to show is that SectorLISP's ABC garbage collector doesn't grow at a large rate as the input size increases. According to the simulator's "heap" statistic, your example needs 449 doublewords of memory to compute a data structure that's 266 double words in size. That seems linear, but it's not, because if you add a few A's then the gap narrows.
The cool thing about your example is that even though it's generating exponential data, that data structure doesn't require an exponential amount of memory to be stored internally. Currently the SectorLISP simulator only does things like de-duplication for DEFINEs which the simulator reports as "code" size in doublewords. However that's a friendly branch feature and the rest of the time SectorLISP just does plain "what you see is what you get" evaluation. I'm sure much more advanced techniques have been discovered since McCarthy wrote his original paper.

Continue this thread — 2 replies

jhgb4 replies#
> a let rec construction for data

Is there actually any Lisp dialect where letrec works for data? I'm not aware of such, at least where it comes to major ones (CL and common implementations of Scheme).

Continue this thread — 4 replies

MaxBarraclough#
> I think the parent was talking about a let rec construction for data

You know more Haskell than I do ;-)
What I had in mind were recursive and mutually recursive functions, defined with letrec, as examples of reference-cycles in functional programming.

nils-m-holm#
LETREC requires mutability in the presence of lexical scope. Otherwise it works fine in the way you describe it. Using lexical scope, IS-ODD and IS-EVEN would be bound in parallel and (LAMBDA (X) (NOT (IS-ODD X))) would close over IS-ODD before it is bound, so it would be undefined when applied inside of the outer LAMBDA.

Of course dynamic scoping will bite you earlier or later because of the upward and downward FUNARG problems. See my book (http://t3x.org/lfn/) for lots of entertaining details.

titzer1 reply#
This is such an awesome project! Writing interpreters in assembly is something of a lost art. That's part of the reason I wrote a Wasm interpreter in asm. I hope this does not stay a lost art.
ngcc_hk#
Convert his into a wasm lisp perhaps? Just a suggestion. Both these attempts are crazily great.

Load more comments