Arrays (lists) of a Type

634 views
Skip to first unread message

Ryan Collingwood

unread,
Oct 18, 2016, 10:02:43 PM10/18/16
to Blockly
Good Day

I understand that blocky is implemented in a untyped language (javascript) and targets untyped languages.

However, I do believe there would be some value in being able to restrict an array to only contain elements of a certain type. 
Any thoughts on this idea?

Ryan Collingwood

unread,
Oct 18, 2016, 10:17:31 PM10/18/16
to Blockly
For instance, you could mock enumerations or relationships if an array was able to explicitly restricted to only a certain type.

Ryan Collingwood

unread,
Oct 18, 2016, 10:46:42 PM10/18/16
to Blockly
It seems to be possible, 
https://ensembl.github.io/XML-To-Blockly/

If you load example 2 which is an address book of contacts, the address book will only accept contacts as additional blocks, and not the email or phone number.

So does setCheck apply to arrays? Is this simply a limitation of the block builder and something I could achieve building my blocks in JS?

Matthieu Muffato

unread,
Oct 19, 2016, 4:10:57 AM10/19/16
to blo...@googlegroups.com
Hi Ryan,

It is the latter. You need to do setCheck("array_type") on the slot that
will accept the array, and setPreviousStatement(true, ["array_type"])
and setNextStatement(true, ["array_type"]) on the block that represents
an item

Matthieu

Ryan Collingwood

unread,
Oct 19, 2016, 6:33:43 AM10/19/16
to blo...@googlegroups.com

But can I restrict it to an array of only strings?


--
You received this message because you are subscribed to a topic in the Google Groups "Blockly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/blockly/IOW1qlddElU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthieu Muffato

unread,
Oct 19, 2016, 7:05:44 AM10/19/16
to blo...@googlegroups.com
If you want to use the block collection shipped with Blockly, I don't
think you can add such restrictions. There's been other emails on the
list regarding strongly-typed structures, I can't remember the
conclusion, but I think the idea was to leave the default blocks
type-agnostic (works for JavaScript and Python).

If you're in control of the block definition, you can define your own
blocks and allow them to connect to one another the way you want (see my
previous email). But you'll need to define a block for the array and a
block for the item.

Matthieu

On 19/10/16 11:33, Ryan Collingwood wrote:
> But can I restrict it to an array of only strings?
>
>
> On 19 Oct 2016 7:10 PM, "Matthieu Muffato" <muf...@ebi.ac.uk
Reply all
Reply to author
Forward
0 new messages