News for hackers. Stuff that matters.
Re:The Janet Language by progre on Saturday February 18, 2023 @03:12AM (#34845036)
I think its a pretty nice language.

Those extra bits of syntax that makes it "not a lisp" are mostly around defining "not list" kind if data structures. I find it practical.

Re:The Janet Language by cosmojg on Saturday February 18, 2023 @03:38AM (#34845173)
What data structure isn't just a list with extra steps?
Re:The Janet Language by MathMonkeyMan on Saturday February 18, 2023 @05:40AM (#34845806)
Almost anything but a list
Re:The Janet Language by adenozine on Saturday February 18, 2023 @07:35AM (#34846441)
Any examples to add, or you just want to leave it at pithy comment?
Re:The Janet Language by MathMonkeyMan on Sunday February 19, 2023 @01:53AM (#34855184)
Sure, my thinking is that a cons cell can build singly linked lists and node-based binary trees. Some data structures are based only on those, but most involve an array of some kind. In scheme, for example, it's the combination of cons (i.e. lists and trees) and vector (i.e. arrays) that allows for arbitrary data structures. It's very constraining to have only the lists.

- array: not a singly-linked list.

- hash table: often an array of singly-linked lists, so not a list.

- red-black or AVL tree: can be built with cons cells.

- doubly-linked list: not a singly-linked list

- double-ended queue: array of double-ended queues, so not a list. Could also be implemented as a doubly-linked list.

Re:The Janet Language by adenozine on Tuesday February 21, 2023 @09:27PM (#34890792)
So what about streams? Functions? Closures? Call/cc structures?

I understand your point if you are speaking in literal terms about just simple cons cells, but in practical Lisp/Scheme code, you don’t really rely on just the basics to do things.

I think there’s a hyperfocus sometimes on the simplicity of the core of lisp, the apply/eval balance, but it’s quite possible and often easy and convenient to perform normal programming tasks with these languages as well.

Re:The Janet Language by MathMonkeyMan on Saturday February 25, 2023 @11:52PM (#34943152)
> I understand your point if you are speaking in literal terms about just simple cons cells, but in practical Lisp/Scheme code, you don’t really rely on just the basics to do things.

Agreed.

> So what about streams? Functions? Closures? Call/cc structures?

Those are interesting examples. They are all data structures in a sense (especially streams and closures), but to me they are more like functions than data (yes, yes, functions are values, blah, blah). Call/cc is a reification of execution control; thinking of it in terms of data stretches my brain.

Re:The Janet Language by jb1991 on Saturday February 18, 2023 @07:33AM (#34846431)
…anything that requires hashing as a fundamental part of the guarantee. Which happens to be quite a lot of the structures most of us use every day. Sets, maps, etc.
Re:The Janet Language by injidup on Saturday February 18, 2023 @07:57AM (#34846563)
Sets and maps do not required hashing. Specifically std::map and std::set in the C++ standard library are based on ordered trees.
Re:The Janet Language by jb1991 on Saturday February 18, 2023 @08:23AM (#34846755)
They’re often called “hash sets” or “hash maps” in other languages - they are called this for a reason, and certainly not because they could be implemented as a list.

std::map is not a good example anyway, you want to consider std::unordered_map for a more appropriate comparison. C++ is weird that way. (What C++ calls a map is not what most languages call a map. std::map doesn’t even satisfy O(1). You’d be surprised how many working C++ developers don’t even realize the unnecessary performance cost they take when they decide to use std::map, because it’s not a proper hash map. )

But this thread is not about the finer differences in implementation of maps but rather whether or not they are basically just lists. They are not.

Re:The Janet Language by glasshug on Saturday February 18, 2023 @10:55AM (#34847802)
Agree broadly that this thread has gotten too long off what was basically a joke, but!

Please measure before you make changes to your maps for perf reasons. Yeah this forum all knows their big-O, but B-tree maps like std::map often perform better than hash maps on real-world architectures.

Re:The Janet Language by injidup on Saturday February 18, 2023 @01:02PM (#34849226)
You said "requires" hashing. Sets and Maps do not require hashing. Through it is correct to observe the unfortunate naming convention in the c++ std lib.

std::set and std::map should be std::ordered_set and std::ordered_map sts::unordered_set and std::unordered_map should be std::hash_set and std::hash_map

If this were so then it might make the incorrect usage of these two options less prevalent. But they are both map and set structures just each version has other guarantees that in some scenarios may be more or less useful.

Re:The Janet Language by xigoi on Saturday February 18, 2023 @03:09PM (#34850549)
> But they are both map and set structures just each version has other guarantees that in some scenarios may be more or less useful.

And similarly, linked lists and arrays are just different "versions” of the same data structure: a list.

Re:The Janet Language by mirekrusin on Saturday February 18, 2023 @04:24PM (#34851250)
Let's simplify it even more - everything is just ones and zeroes.
Re:The Janet Language by jb1991 on Sunday February 19, 2023 @02:35AM (#34855372)
You interpreted my reply as “all sets and maps require hashing“ instead of “sets and maps are examples of data structures that can require hashing”… which they are.

Imagine someone says, every fruit in the world is sour, and someone answers, no there are plenty of fruits that are sweet, such as apples, and then an entire thread gets launched in an irrelevant direction pointing out that actually some apples are sour. That’s effectively what’s been done here, and it’s a waste of everyone’s time.

Re:The Janet Language by krapp on Saturday February 18, 2023 @09:34AM (#34847205)
An array in C is a list with fewer steps. Just a continguous chunk of memory of sizeof type * length.

You could fill that with linked list nodes, but it would be pointless.

Re:The Janet Language by otabdeveloper4 on Saturday February 18, 2023 @09:58AM (#34847347)
If by "list" you mean "linked list", then those are never used in practice. There is no place for this data structure in a modern CS toolbox.
Re:The Janet Language by drdec on Saturday February 18, 2023 @10:34AM (#34847617)
The people behind the Elixir programming language certainly disagree.
Re:The Janet Language by otabdeveloper4 on Saturday February 18, 2023 @04:15PM (#34851165)
Maybe that's why Elixir never gained real traction.
Re:The Janet Language by mtlmtlmtlmtl on Saturday February 18, 2023 @10:48AM (#34847730)
That's a ridiculous statement. Linked lists have real performance benefits in some applications. A good "modern CS toolbox" includes the ability to make the right choice. Which, if you believe they are fundamentally useless, clearly you lack.
Re:The Janet Language by otabdeveloper4 on Saturday February 18, 2023 @04:16PM (#34851174)
> Linked lists have real performance benefits in some applications.

Maybe in 0.01% of the cases. In reality they just ruin your cache and memory allocator performance for no real good reason.

Re:The Janet Language by mtlmtlmtlmtl on Saturday February 18, 2023 @05:25PM (#34851730)
In many cases you can get around these issues by being a little more clever in how you allocate nodes. In some cases you don't have the luxury of allocating all elements next to eachother anyway, in which case an intrusive linked list is often the best option to minimise copying. You might say use a vector of pointers or a circular buffer, but if you're in a timing sensitive context you might be unable to realloc.

Hell, memory allocators themselves are often implemented using some form of linked list. You tend to see them quite a bit at very low levels like in kernels.

Re:The Janet Language by lispm on Saturday February 18, 2023 @03:57AM (#34845260)
Lisp usually has a lot of non-list data structures like arrays. records, strings, classes/objects, hashtables, ... For some data structures there is built-in syntax and with an extensible reader (the extensible parser for s-expressions) the user can add additional syntax. Janet uses a non-extensible parser for the data syntax.

What Janet makes a 'not really a Lisp' is that "LISP" stands for "List Processor". Janet isn't exactly that, since it is not using linked lists as a core data structure - unlike Lisp where its List Processing features are built on top of linked lists made of cons cells.

(1 2 3) is called a "tuple" in Janet and represents something like an immutable array.

Re:The Janet Language by xigoi on Saturday February 18, 2023 @07:39AM (#34846461)
An array is just a different way to implement a list data structure.
Re:The Janet Language by lispm on Saturday February 18, 2023 @08:28AM (#34846781)
Lisp especially is built upon linked lists, which have different costs for (more or less) primitive operations (add to the front, get the front item, get a rest list, get a random element, add to the end, ...) compare to a primitive vector. There are also other features not easily replicated by vectors.

  CL-USER 40 > (rest '(1 2 3))
  (2 3)
Above does not allocate any memory.

  CL-USER 41 > (subseq '#(1 2 3) 1)
  #(2 3)
OTOH getting a random element has a different complexity in a linked list vs. a vector.

Above returns a new vector. Alternatively it would need a more clever implementation underneath.

Re:The Janet Language by ravi-delia on Saturday February 18, 2023 @02:20PM (#34850114)
Op was thinking of Julia