I want to create a list of length 10 with empty elements but programatically
I came up with this but feel there must be something better
I want to create a list of length 10 with empty elements but programatically
I came up with this but feel there must be something better
What about just [scratchblocks]
(map ([]::grey) over (numbers from(1) to (10))
[/scratchblocks]?
What is that block inside the map?
I was really after a neat solution that doesn't need need custom or library blocks
I'm guessing you don't want
[scratchblocks]
repeat (10)
add[]to (list v)::
end
[/scratchblocks]
then?
Initialize list:
[scratchblocks]
set [variable v] to (list [hello]::list)
[/scratchblocks]
Add to list:
[scratchblocks]
add [world] to (variable)
[/scratchblocks]
This:
[scratchblocks]
(variable)
[/scratchblocks]
Will report this:
[scratchblocks]
(list [hello] [world]::list)
[/scratchblocks]
I've accidently discovered that this will do it
It's not very intuitive though and maybe just is an undiscovered bug
I don't think it is a bug. It uses hyperblocks, and instead of throwing an out-of-bound error, Snap! reports an empty string.
try this?
[scratchblocks] (empty string :: operators ) :: control hat report [] :: control cap (map ({ (empty string :: operators) } @delInput @addInput:: grey ring) over (numbers from (1) to (10) :: list) :: list) [/scratchblocks]
Too much effort for me
hey use the ([id v]of ()) thing replace the empty function
I think I've found a nice looking way to do it
or ?
That is one extra mouse-click!
But you win the prize for best-looking
A number input always reports a number inside of the block, so if the input is blank it reports 0.
since v6.6 you can simply use reshape
on any scalar to fill a new data structure with it:
In this case, since there scalar is "empty", you get a 10-item long list filled with empty values.
here's another example of using a scalar instead of a list to fill every leaf in a new table with it:
Nice but ...
shouldn't reshape give an error on empty (or non-list) parameter like all the other list blocks do?
[edit]
To explain further what I mean to others
All other list reporters (pre version 6.6) give an error if the list slot is empty or filled with a non-list item
Therefore, I'd expect this block to as well
Just in case its current behaviour is changed to match the other blocks - I'll use