What are input names in a ring used for

Like I know they can be used with

 (call(()@> ::ring)@:>) 

but what else can it be used for?

Nothing else really, except for providing inputs to rings:
call ({((a) + (b))} input names: ((a)) ((b)) @<>) with inputs [1] [2] @<:> // returns 1 + 2 run ({say ((a) + (b))} input names: ((a)) ((b)) @<>) with inputs [1] [2] @<:> // says the result of 1 + 2

if youre talking about any other uses, all I realy know is tthat you can get the inputs using the ([ V] of [ V]) block:
([input names V] of (put your ring here :: other)

I saw it being used in (map (() input names: ((foo))@<> ::ring ) over @list )

Oh, right.

The ring went up to (() input names: ((value)) ((index)) ((list)) @< ::ring)

Basically, the ring for map, filter, those type of blocks take all value index and list. “value” is the current value in the list, “index” is the current index in the list, and list is the list itself.

“map” goes through each itrem and the ring should return the new item for that position
“keep items” goes through each item, and if the ring returns true keep it, else remove it
“find first item” finds the first item in the list that matches the ring,
and finally “combine” combines each item in the list by having the previous item as the first input to the ring, and the second being the current item.

I suggest you read the Snap! Manual for more information on rings and mostly everything else.

The purpose of a ring is to create a function without giving it a name. Instead of saying

untitled script pic (8)

you can say

I know, that looks like a lot of fuss, rather than like the most elegant thing in computer science. It doesn’t pay off in a one-off invocation like this, but it lets you build things like a list of functions:

untitled script pic (12)

untitled script pic (13)

untitled script pic (14)

And you can operate on that list with higher order functions, same as any other list:


The fact that rings used in inputs to the higher order functions have special default names for the parameters is just a kludge pedagogic optimization to remind people how those functions treat their inputs.


One feature in Snap! that I’m very proud of, although I know some people don’t like it, is that in many simple cases you can dispense with explicit naming of parameters. Instead of


you can say

The theory is that people find the idea of plugging values into an empty slot intuitive. Every elementary school teacher knows that if you show an eight-year-old x+3=7 and ask “what’s the value of x?” you’re likely to get “huh?” as the response, but if you show the same kid :white_square_button:+3=7 and ask “what value goes in the box?” you’ll get an answer.