"Destructuring" in FOR-EACH

@gchiu wrote some code that made a list of drugs and filenames related to those drugs:

 drugs: [
     ["Benzbromarone" "SA1537.pdf"]
     ["Teriparatide" "SA1139.pdf"]
     ["Adalimumab" "SA1847.pdf"]
     ["Etanercept" "SA1812.pdf"]
 ]

This is inconvenient to enumerate. It won't work if you say:

for-each [drugname filename] [...]

Because what you get then is two successive blocks... e.g. drugname winds up being ["Benzbromarone" "SA1537.pdf"] and then filename is ["Teriparatide" "SA1139.pdf"].

If this were to work, it would have to offer something like:

for-each [[drugname filename]] [...]

That could communicate that the information you were looking for was actually in a nested block level.

Though we don't want to get too literal with the dialect. If you have:

 drugs: [
     ("Benzbromarone" "SA1537.pdf")
     ("Teriparatide" "SA1139.pdf")
     ("Adalimumab" "SA1847.pdf")
     ("Etanercept" "SA1812.pdf")
 ]

...we don't want to make the meaning of GROUP!s in FOR-EACH have to be related to this structure, because we use groups to say that the variable's name is calculated. :-/

Similarly, we might imagine more interesting meanings for blocks in FOR-EACH than to point out a nested block level. Maybe this would be done with quoted blocks and quoted groups?

for-each ['(drugname filename)] [...]

It gets a bit hairy because you're starting to tread into parsing territory. Hard to know where to stop.

Since I'm not sure I just switched Graham's case to use a flat block.

 drugs: [
     "Benzbromarone" "SA1537.pdf"
     "Teriparatide" "SA1139.pdf"
     "Adalimumab" "SA1847.pdf"
     "Etanercept" "SA1812.pdf"
 ]

But it should be thought about more.

2 Likes

In case of the nested block, it becomes something like for-each blck [d: first blck f: second blck]