News for hackers. Stuff that matters.
Re:I Accidentally a Scheme by cfiggers on Wednesday November 15, 2023 @12:25AM (#38273618)
There's literally dozens of us!

If you're serious about learning a Lisp but motivated more by, as you say, "having more fun" rather than, say, landing a six-figure job writing it professionally... then may I recommend Janet[0] for your consideration. Janet is an embeddably-small, yet surprisingly batteries-included Lisp implemented in pure C. In terms of syntax and core library it borrows more directly from Clojure than from Scheme, but all the modern Lisps have their bits of influence. I've found both the language and the tiny little community that exists around it delightful.

As an example of the latter, somebody smart wrote a real actual book[1] about Janet recently that was on the HN front page for a day or so when he first released it. It's a gentle introduction not just to Janet but to Lisp in general, and assumes only general proficiency with JavaScript to get you up to speed. I recommend it.

[0] https://www.janet-lang.org

[1] https://janet.guide

Re:I Accidentally a Scheme by TylerE on Wednesday November 15, 2023 @01:10AM (#38273809)
Ooh that's actually really interesting. I've always been a bit into lisp... even did a bit of amatuer CL back in the day..but always thought the distribution model of basically a memory dump was just the worst of all possible worlds.
Re:I Accidentally a Scheme by bigfishrunning on Wednesday November 15, 2023 @03:29PM (#38281997)
I agree with this sentiment -- from a reproducability standpoint, CL images aren't great. My workflow has always been to maintain a source file and then use emacs to shove s-expressions into the repl -- that way, rather then save the image, i can just re-evaluate my source file and get a reasonable facsimile
Re:I Accidentally a Scheme by cfiggers on Wednesday November 15, 2023 @06:50PM (#38284063)
Janet has an excellent distribution story (IMHO, anyway). You can do everything from Python-style distribution of .janet scripts all the way up to compiling stand-alone native executables.

You can also do the memory dump thing, if that's your preference--and, under the hood, that's actually how the native executables work too. The Janet compiler/interpreter and core library all together is approximately 1MB in size (that's not a typo! One Megabyte!). So when you compile an executable, what you're really doing is packaging together a serialized image of the compile time state bundled together with a full copy of the Janet abstract machine. On startup, the Janet runtime boots (extremely quickly, FWIW), it rehydrates the compile time state (which includes all your function definitions, variable declarations, etc.), and then it executes your `(main)` function.

This means there's all kinds of compile-time metaprogramming magic you can do _without_ needing a whole separate build language to do it, and also without impacting run time performance (like, for e.g., macro expansion all happens during that step). Because all that will have calculated during compilation, the results are saved to your embedded image and so they'll be accessible at run time, wherever and whenever that may happen.

I'm honestly not that well-educated on programming languages in general so I don't know if this is all super boring run-of-the-mill type stuff that other languages do too (probably so), but learning how Janet does it was super fun when it all clicked in my brain and it's the one language I know a little bit about, so hey, now you get to know about it too. :)

Re:I Accidentally a Scheme by dleslie on Wednesday November 15, 2023 @02:00AM (#38274058)
While I like Janet, and find it to be a lovely little language; I think it's important to note that it lacks lists and cons cells, and so as a result some people don't label it a lisp, and programming in it is unlike other lisp languages. It's similar, because the syntax is similar and the macros and various forms are lifted straight from lisps; but the feel of programming in it is very much like programming in C, and I find it's less like Scheme or Common Lisp.

Because it's not built around linked lists, the core type most encountered for lists of data is arrays and tuples. Neither is conducive to efficiently removing elements mid-set, or composing two sets, or interleaving two sets, or other operations that require reordering, replacing, adding or removing elements in the set. When I'm writing code in lisp I don't think about that overhead much, because for linked lists it's not an issue.

Re:I Accidentally a Scheme by cnity on Wednesday November 15, 2023 @04:23AM (#38274822)
> Neither is conducive to efficiently removing elements mid-set, or composing two sets, or interleaving two sets, or other operations that require reordering, replacing, adding or removing elements in the set

Read this: https://isocpp.org/blog/2014/06/stroustrup-lists

Re:I Accidentally a Scheme by dleslie on Wednesday November 15, 2023 @09:59AM (#38277276)
That's based around a contrived problem that was posed to him:

> Insert a sequence of random integers into a sorted sequence, then remove those elements one by one as determined by a random sequece of positions: Do you use a vector (a contiguously allocated sequence of elements) or a linked list?

The key is that the sequence is sorted; and is kept sorted throughout the insertion process. With a linked list that means at least an O(n) traversal for insertion, so of course it's terrible.

Re:I Accidentally a Scheme by TylerE on Wednesday November 15, 2023 @10:20AM (#38277569)
Feature not a big in my book. A linked list is almost never the right answer. Certainly shouldn't be the default.
Re:I Accidentally a Scheme by hajile on Wednesday November 15, 2023 @11:11AM (#38278285)
> A linked list is almost never the right answer.

And yet a subset of the linked list called a tree is usually the right answer to problems.

Re:I Accidentally a Scheme by TylerE on Wednesday November 15, 2023 @11:26AM (#38278481)
because it avoids all the pathological worse case performance unless you get insanely unlucky with the order the data is inserted... and even then you can do a rebalance if you're that concerned about it.
Re:I Accidentally a Scheme by dleslie on Wednesday November 15, 2023 @01:04PM (#38280045)
It depends on how you approach solving problems, and what the problem is.

In the contrived example, a linked list is clearly a terrible option for manipulating a sorted set of integers. Modern computers can slice and dice contiguous integers with vectorized routines, and those benefits are lost with linked lists that are storing their data haphazardly across the heap.

If your problem space is best defined with contiguously-stored numbers, then for sure, don't use linked lists. Most lisps will happily provide you with vectors and arrays for these use cases.

Re:I Accidentally a Scheme by vindarel on Wednesday November 15, 2023 @07:56AM (#38276153)
But is Janet as interactive as Common Lisp? (REPL, image-based development, debugger, restarts…) The fun is there!
Re:I Accidentally a Scheme by cfiggers on Wednesday November 15, 2023 @09:18AM (#38276826)
Yes, 100% to both the REPL and image-based development!

Janet's REPL has a debug mode, but I'm sadly not qualified to evaluate whether/how it measures up to CL's due to my own inexperience with either. :)

As for restarts (I had to Google around to get an idea of what that means)—it seems to me that Janet does not have first-class support for restarts in the way that some other Lisps, for e.g. CL, do. Presumably (as it would be in most other languages I would suppose) one could recreate that experience in Janet by tapping into the first-party error handling and REPL primitives. But you'd definitely be rolling your own rather than having it already in Janet out of the box.

Re:I Accidentally a Scheme by ikurei on Wednesday November 15, 2023 @09:39AM (#38277037)
Since you mentioned this, what would you say would be the right Lisp for more pragmatic, cynical reasons?

What Lisp should we learn if we want to make money from it?

Re:I Accidentally a Scheme by cfiggers on Wednesday November 15, 2023 @10:27AM (#38277663)
If I knew the answer to that question I'd probably have a very different job than the one I have. :)
Re:I Accidentally a Scheme by stcg on Wednesday November 15, 2023 @11:15AM (#38278334)
Maybe Clojure. In 2022 it took the top spot for "Top paying technologies" in the annual StackOverflow survey [0], and in 2023 it tied with other lispy languages [1].

That said, I don't think it matters much. A developer familiar with some lispy language (and perhaps functional programming) should be able to quickly pickup any other lispy language. And the developers that make the most money have probably used a lot of programming languages, with different paradigms.

[0]: https://survey.stackoverflow.co/2022/#top-paying-technologie...

[1]: https://survey.stackoverflow.co/2023/#section-top-paying-tec...