What do these do?

when looking at list utilties, i found these link blocks

Screenshot 2024-05-18 131048

what do these blocks do, im kinda afraid that these are buggy because of the skull icon

i know what they do

what even is their purpose?

From the manual

hehe, i dont understand

my guess is that it checks if a list is itself by linking it

Brian will probably come along and explain the difference properly

My understanding is one just stores the values one after another - e.g the way a simple array is normally stored in other languages)

The other (linked list) is where each item in the list contains both the value of the item and a pointer to the next item in the list

i get it now, its a list pointer

i might use it, if i need to

I'm not sure you have

The boolean reports what type of list it is stored as
The reporter converts an array type list into a linked list

wow, my brain is that tiny

I wrote that library before we had the ability to hide blocks in a library; the :skull_and_crossbones: in the block titles just means that users of the library aren't meant to use them. The big idea here is that we try to support different programming styles efficiently without users having to think about the implementation. So, abstractly, a Snap! list is a sequence of items, period. But under the surface, a given list might be stored either in a single contiguous block of memory (as a dynamic array) or with each item pointing to the next (as a linked list). We try to make this all work without the user thinking about it. But this means that the primitives we provide, including quasi-primitives in libraries, have to know what kind of list they're dealing with.

As it turns out, because Snap! is written in JavaScript, and JS gives us primitive support for dynamic arrays, it's pretty much always faster to use those, and especially since we added hyperblocks our lists are almost always kept as dynamic arrays, so this is all less useful than it was once. The BJC curriculum, Snap!'s first customer, puts the emphasis on recursive functions, which is why I insisted on linked list support. :~)

TL;DR: Don't worry about it.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.