Recreating Snap! blocks

i’ve been trying to recreate the “item x of y” block for days. this alone retrieves the first item of the list, which is progress…

however, there’s a really cool functionality with this: the more variables you pull out of the ring (e.g. #1 is the first item, #2 is the second, and so on…) the more items of the list you can instantly get.

but i don’t want to and won’t hardcode that, because what if you had a list of something like 1k items? or even 100 - it kind of breaks down… so i’m curious if there’s a way you can fetch the nth input (not the name, the value!) of a specific ring? i’m recreating some Snap! blocks mostly from scratch, so i can’t use any other list blocks, unfortunately. it’s a really restricted palette thats fun to work with

I’m pretty sure there’s already a block that does this. But I could try and help recreating the block. Also welcome to :snap:!

untitled script pic

Hope this helps!

They are trying to recreate it without using it.

Well, if you want the logic here ya go:

thanks, but i’m trying to recreate that block :P

thanks! but that uses a for each loop. i’m trying to get the value of a specific non-declared ring input

Sure, but both methods would achieve the same result.

There’s this thing called the “XY problem” where someone is trying to solve for X (recreating the ITEM OF block), they figure out on their own that you need to solve Y (getting the value of a non-declared ring input), and then ask how to solve Y, when there’s a simpler solution for X.

right, but it’s a challenge - i’m recreating some Snap! blocks from scratch, so a “for each” isn’t viable in this challenge.

what? I don’t get it. by “recreating some Snap! blocks from scratch” can’t you use any or all snap blocks?

i think they mean if they were to use for each, they would need to program it in terms of item of. if they use for each in the item of definition, it wouldnt work if they were to describe for each as discussed

yeah, thats what i mean.

to get the “for each item in …” block in the first place id have to make the item x of y block

if it makes more sense, “i’m creating snap! blocks from basically nothing”, not “i’m RECREATING snap blocks”…

so the call method I screenshotted is one of my only methods (given there MIGHT be other ways to do it?) because unhiding blocks would be cheating :P

This one works for lists that only have unique values.

This version works for non-uniques too.

@vblackmar

thanks, but I am trying to fetch the value of a ring input i haven’t declared, specifically because i can’t use those list blocks (i am doing a challenge with a highly restricted palette so i would have to build them first, but I need to create the item x of y block in the first place to do so.)

i would consider all but first of list an extremely essential list operator - its one of the linked list operators in lisp.
for context, what blocks do you have to work with? we can’t help if we don’t have the full picture.

sorry about that

(sorry for being so vague in previous posts)

maybe I should have done some research on Lisp before i picked the base blocks i was allowed to work with…

given all of the answers i mightve restricted myself to oblivion

if its ok, could you list all of the necessary & basic Lisp operators so i can go about this in a better way?

(keep in mind i havent ever used vanilla honest-to-goodness lisp, so this may be incorrect)
for your list operators, you have the three big ones: car, which reports the fist element or “head” of a list; cdr, which reports everything but the first element, the “tail” of the list (these roughly correspond to item (1 v) of $list and all but first of $list, respectively); andcons, which reports an element at the front of another list: this is [] in front of $list. the block primitives’ names actually reference this somewhat: reportCONS and reportCDR (though “item of list” is just reportListItem)

the reason these methods for list manipulation exist are because of how lisp stores a linked list: linked lists are made up of “cons-cells”: chunks that contain the data of the list, and where the next element of the list can be found in memory. car reports just the data of a cons-cell, and cdr reports the list that the cons-cell points to. cons defines a new cons-cell, with the specified list referenced at the end. im not sure if snap uses linked lists, though the help screens do seem to say that cons and cdr work more effeciently on lists constructed using only those operators.

theoreticially, you could perform any list operation using just these operators, even arbitrary list indexing

adding to this, you could theoreticially perform any operation with just rings and call, though it wouldn’t be very fun: “Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy.”

tysm!!!

car should definitely be possible with just the block i showed in the original post so yayyy

i recall seeing somewhere that it does use linked OR something LIKE linked lists but i may be wrong.

as for a lot of the math operators i think its gonna be a BIT difficult to recreate those, so i’m probably going to keep all five and possibly the x of number operator because those are just basic operations the computer can do !

also yeah i saw other stuff about it being possible to do stuff with just rings and call but… that means youre gonna have to make ALL TYPES from just those which is Not Fun lol

i love subsets of languages like this since it makes you think in more convoluted ways on a simple problem.
for example: how would you store a string? easy: make a “master string” with each letter and store everything as a list of values.
it would be hard to display this string without a join, however.

im probably specifically keeping casting stuff (like join) specifically for that capability because its not really that possible without that block - but stuff like length of list/string and repeats/untils and things of that nature i’ll code manually. this is the first pass so i might find an even more complicated way of doing it for fun :P