Live data from Hacker News

Carp – A statically typed Lisp, without a GC, for real-time applications

github.com

41–50 of 139 posts

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#41

Can somebody please explain or give me some links how FP is supposed to work without a GC? For example Rust has different types of function pointers (Fn, FnMut, FnOnce), to guarantee the possibility of lifetime analysis (so it is arguable to consider it a functional programming language). On the other hand the most common FP languages (OCaml, Haskell) all come with a GC. Or am I wrong in assuming this is a functional…

Lisp is definitely not as functional as for instance Haskell is. Side-effect-freeness was never really a topic for Lispers.

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#42
post #25

I was thinking of building my own LISP-like language, but seeing so many pop up on here I don't think I'll bother.

Millions of CS students build their own language for compiler classes every year.

As learning exercise of everything that goes into making a compiler/interpreter is very worthwhile endevour.

As means to make the next big thing, maybe not.

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#43
post #36

Can somebody please explain or give me some links how FP is supposed to work without a GC? For example Rust has different types of function pointers (Fn, FnMut, FnOnce), to guarantee the possibility of lifetime analysis (so it is arguable to consider it a functional programming language). On the other hand the most common FP languages (OCaml, Haskell) all come with a GC. Or am I wrong in assuming this is a functional…

Lisp is not necessarily functional. There's a lot of mutation in Common Lisp even if the community favors a functional style. I think the question is: how does Lisp function without garbage collecting cons cells? For one, I'm not sure they even rely on cons cells like "real" Lisp. Clojure doesn't either. They cite ML as inspiration. Carp language guide states object lifetimes are statically inferred [1] which my gues…

You're correct, somewhat like clojure's Vector, the default collection at runtime in Carp is an Array which is heap allocated C array with an attached length. At compile time however the dynamic language uses more standard lispy lists.

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#44
post #11

Earlier quoted context omitted.

For "real-time", they would need a real-tune OS, datastructures with forward guarantees, non-blocking IO and so on. GC is like the least of the problems.

Not an expert at all here, just a few thoughts and experiences. I think "forward guarantees" (meaning "lock-free"?) can be implemented anywhere. Non-blocking IO can still be slow in my experience, for example a write() syscall on Linux to a non-blocking TCP socket on Linux sometimes took dozens of milliseconds when I measured. I don't have enough experience to know if one can get better timing guarantees with tuning…

lock free does not guarantee all participants have a fair treatment, e.g. one thread can keep losing the CAS (CompareAndSwap / LoadLinked/StoreConditional / etc.) and effectively spinning or need to yield. releasing the CPU resources.

A non-blocking write should just copy the data to the socket buffer, definitely not taking milliseconds.

Allocate buffers in separate threads - ok, that's the crux of it - the memory is shared amongst the threads within a process, so the allocator has to be non-blocking as well or the large allocation would prevent allocations in other threads. Next release memory to the OS (or unmapping memory mapped files) - mumnmap requires TLB flush for all cores assigned to the process. There is a lot that can 'block' sometimes and void the "real-time" properties.

> interrupted by the GC doing OS interaction

Normally GCs trigger only at 'safe points' and unless they need to allocate more memory (should never be the case for a real-time application), GCs should have no OS interaction. Copying and moving memory within a process is no OS functionality. Concurrent GC with read-barrier exist as well, so no need for stop-the-world pauses. (Edit: creative use of memory mapping hardware to avoid copying may need OS calls)

It seems quite common to see on hacker news - "No GC for real-time". Writing a good/multi-threaded real-time application is a lot harder than just GC's dreaded stop-the-world.

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#45
post #28
post #16

Earlier quoted context omitted.

the doubling of the sizes is an issue. Yet, I'd consider all single threaded datastructures a non-issue. The hard part is multithreading. Flip note: java's hashmap uses red/black tree for nodes when there are too many collisions (and the keys are Comparable)

but java's hashmap still resizes when breaching the loadfactor. so any similar implementation, even for singlethreaded cases can't achieve (soft)realtime. I am not aware of any linear hashing or similar approach for in memory hash tables to mitigate such latency spikes.

of course it does; it's possible to pre-allocate the entire table though (c-tor with size, rounded to the next power of 2, compensated by the load factor). Massive waste of memory but no resizes.

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#46
post #40

> (the Int x) I like the cute syntax for type annotations.

I had to double-take because CL also has a THE also for declaring types, but it's a bit different; THE declares the type of an expression, not a variable (there is a separate type declaration for variables). so e.g. (the fixnum (+ x 1)) would assert that (+ x 1) produces a fixnum.

That is also the case in Carp, x being an expression here.

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#47
post #46
post #40

Earlier quoted context omitted.

I had to double-take because CL also has a THE also for declaring types, but it's a bit different; THE declares the type of an expression, not a variable (there is a separate type declaration for variables). so e.g. (the fixnum (+ x 1)) would assert that (+ x 1) produces a fixnum.

That is also the case in Carp, x being an expression here.

Ah, okay. So is there a way to declare that a variable will always be of a given type in Carp?

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#48
post #25

I was thinking of building my own LISP-like language, but seeing so many pop up on here I don't think I'll bother.

As stated by others, it's a very enjoyable exercise. Think about it like Marathon for programmers. Yes, lot's of people run marathons. But people usually don't go "Maybe I should run a marathon - but so many others are doing it. Meh, maybe not."

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#49
post #27

The name is strange. Reminds me of a product-naming story I heard years ago. Papenmeier from Germany was once planning to create a small notetaker with built-in braille display. They originally planned to name it "Braille Assistant", but the US distributors objected on the ground that they can already see users shortening the product name to "Braille Ass". I have a similar feeling with Carp, isn't the obvious transpo…

Given the kind of niche, self-deprecating humor often found in our ecosystem, it was probably seen as a plus :)

Re: Carp – A statically typed Lisp, without a GC, for real-time applications

#50
post #42
post #25

I was thinking of building my own LISP-like language, but seeing so many pop up on here I don't think I'll bother.

Millions of CS students build their own language for compiler classes every year. As learning exercise of everything that goes into making a compiler/interpreter is very worthwhile endevour. As means to make the next big thing, maybe not.

> Millions of CS students...

Are there millions of CS students in the world?? I would guess a few hundred thousand, at most.

Post reply on HN