How can I initialise a list

I want to create a list of length 10 with empty elements but programatically

cloudFileList script pic

I came up with this but feel there must be something better :slight_smile:

cloudFileList script pic (1)

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?

I think

is your best bet.

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]

what about

?

I've accidently discovered that this will do it

image

It's not very intuitive though and maybe just is an undiscovered bug :slight_smile:

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 :slight_smile:

hey use the ([id v]of ()) thing replace the empty function

untitled script pic (7)

@bh fix this please
it shouldn't be like this even if it is a math block
oh well it is a math block

I think I've found a nice looking way to do it :slight_smile:

Star_Trek_Mayfield_1972_16Feb21 script pic

or ?
image

That is one extra mouse-click! :slight_smile:

But you win the prize for best-looking :slight_smile:

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:

init

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 ...

image

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

image