News for hackers. Stuff that matters.
Re:I Accidentally a Scheme by __MatrixMan__ on Wednesday November 15, 2023 @12:02AM (#38273510)
Note to self: learn a lisp. Lisp people appear to be having more fun than the rest of us.
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...

Re:I Accidentally a Scheme by defenestration on Wednesday November 15, 2023 @02:34AM (#38274223)
I had a lot of fun learning Clojure. While I don't use it in daily practice, I learned a lot about elegancy, the advantages of data immutability and using code as building blocks. For learning I used the 4clojure website where you can solve interactive coding puzzles and learn from solutions of others. See: https://4clojure.oxal.org
Re:I Accidentally a Scheme by jimbob45 on Wednesday November 15, 2023 @02:36AM (#38274233)
learn from solutions of others

I got my first job furiously doing that for nights on end. It felt like cheating but it’s ultimately way faster than waiting potentially years to figure out those tricks on your own.

Re:I Accidentally a Scheme by defenestration on Wednesday November 15, 2023 @02:43AM (#38274263)
Yeah, good to hear. I also did this for nights on end. My strategy was to try to solve the puzzle myself first (in a reasonable amount of time) and then check the solutions of others. Always fun to see if I could make my solution faster/shorter/more elegant/etc. with the inspiration of the other solutions.
Re:I Accidentally a Scheme by Obscurity4340 on Wednesday November 15, 2023 @09:14AM (#38276781)
What are the odds that someone gets accused of plagiarism for doing exactly that? Like, say there's a perfect solution in existence with the fewest lines/tokens of code all the elegant shortcuts and maybe a little bit of "sorcery", how likely is it for two people to work their way down the perfect solution and it basically looks exactly the same, maybe they followed the same logical workflow to arrive there, who knows...
Re:I Accidentally a Scheme by kagevf on Wednesday November 15, 2023 @06:39PM (#38283969)
I don't know what the odds are of getting accused, but let's say this was in the context of an interview question, and every answer submitted looks almost 100% the same, or even more telling, has the same logic mistakes, then the odds could be high that plagiarism is afoot.
Re:I Accidentally a Scheme by Obscurity4340 on Wednesday November 15, 2023 @08:42PM (#38284937)
Say there's no mistakes. Its literally perfectly logical and conventionally written code. Its the epitome of that thing with Michaelangelo where he assumes his vision for the sculpture is correct and all he needs to do is surgically remove the excess marble to get to the essential form that is perfect and ideal and intutitive.
Re:I Accidentally a Scheme by tmtvl on Wednesday November 15, 2023 @03:50AM (#38274632)
I recommend Common Lisp, it's fast, it's mature, and it has some wicked cool tools. You can find some resources here: <https://stevelosh.com/blog/2018/08/a-road-to-common-lisp>. You can also look at CLiki (the Common Lisp wiki), the Common Lisp Cookbook, and the Common Lisp Community Spec for information any basically anything you may be interested in.
Re:I Accidentally a Scheme by _0ffh on Wednesday November 15, 2023 @04:31AM (#38274869)
On the risk of drawing the ire of our lisping friends, I find that I have more fun writing lisps than using them, at least unless I equip them with a syntax.
Re:I Accidentally a Scheme by LocalH on Wednesday November 15, 2023 @05:57AM (#38275392)
Does modding a game that uses a bespoke Lispish scripting language count?
Re:I Accidentally a Scheme by bigfishrunning on Wednesday November 15, 2023 @03:34PM (#38282060)
Yes! All you have to do to make a lisp is to make a thing and call it a lisp. Lists are recommended, but optional.
Re:I Accidentally a Scheme by carapace on Wednesday November 15, 2023 @10:28AM (#38277682)
One great way to learn Lisp is to write your own:

> The goal of the Make-A-Lisp project is to make it easy to write your own Lisp interpreter without sacrificing those many "Aha!" moments that come from ascending the McCarthy mountain. When you reach the peak of this particular mountain, you will have an interpreter for the mal Lisp language that is powerful enough to be self-hosting, meaning it will be able to run a mal interpreter written in mal itself.

~ https://github.com/kanaka/mal/blob/master/process/guide.md

https://github.com/kanaka/mal

Re:I Accidentally a Scheme by kazinator on Thursday November 16, 2023 @04:28AM (#38287390)
If you don't know Lisp, and start writing your own, you're only learning your own concoction, and not any other Lisp. And that concoction has its limits. It doesn't compare to the breadth and scope of the Lisp culture.

Interacting only with something you have made is the worst possible way to learn anything about existing, mainstream Lisp.

Not knowing anything about the prior art will practically ensure that your own thing is a collection of quirks specific to it, and that then ensures that your Lisp knowledge is entirely rooted in and limited to that thing.

You're just not going to single-handedly reinvent things that took numerous hackers over several generations to figure out. You may be "good", but so were they, and there is only one of you.

You will not even be able to converse with actual Lisp people, due to not having the right concepts and terms.

Re:I Accidentally a Scheme by carapace on Thursday November 16, 2023 @09:19AM (#38289768)
Are you criticizing the MAL project or just offering general advice?

I feel MAL does a decent job illustrating the core concepts of Lisp, but then I'm not a Lisp expert by any means.

Re:I Accidentally a Scheme by kazinator on Friday November 17, 2023 @07:20PM (#38312861)
I'm not sure which, if any, of my remarks apply to MAL specifically.

I don't have the impression that the author of the MAL project used it as a way of learning Lisp.

To my best understanding, MAL provides a step by step recipe and test cases for implementing a language dialect, plus example implementations for which that has been done.

Someone going through the MAL exercise will mainly interact with the chosen implementation language. Writing a new MAL implementation could be used as an exercise to learn some unfamiliar language.

I'm not convinced that programmers implementing MAL are actually learning how to use MAL, since it doesn't look as if the exercise requires them to write MAL code to solve problems. To learn MAL, you would take the project as-is with its integrated implementations and use that to get other work done.

Suppose someone actually learns MAL by working with it. Are they learning Lisp?

I'm not sure how much of their acquired skill will transfer to working with a mainstream Lisp. MAL looks rather like a kind of Mock Lisp (see: https://en.wikipedia.org/wiki/Mocklisp). It's implemented even in Bash and Awk using string processing.

The good thing about MAL is that at least the participants in the exercise are following a specification instead of just making something up as they go along and calling it Lisp. Making something that is compatible with a spec and other implementations is a good exercise for software engineering students, regardless of what it is. MAL would still be valuable that way if it was, say, MAVE: make a vi editor, or MAM: make a Mario game.

I have no idea how effective MAL is educationally in teaching the concepts themselves that underpin MAL, which revolves around this question: is it possible to mechanically follow the recipe and get a new implementation working, without understanding the concepts? Separately from the question of whether MAL concepts are Lisp concepts, is the MAL implementor who follows the structured workflow learning the MAL concepts, or are they just massaging code to get some tests to pass. (But, of course, even if they are, so what; nothing stands in their way of learning any concepts they want in any other manner.)

Re:I Accidentally a Scheme by ookdatnog on Wednesday November 15, 2023 @10:56AM (#38278067)
I haven't done any serious lisping outside of tutorials and books, but I warmly recommend the wizard book of myth and legend, SICP (https://mitp-content-server.mit.edu/books/content/sectbyfn/b...). I had a lot of fun working through it.
Re:I Accidentally a Scheme by tmtvl on Wednesday November 15, 2023 @03:34PM (#38282047)
Remember to watch the video lectures.
Re:I Accidentally a Scheme by zem on Wednesday November 15, 2023 @02:25PM (#38281175)
I've played around with a number of lisps and racket is the one I find the most enjoyable to use.