goyamp icon indicating copy to clipboard operation
goyamp copied to clipboard

Enhance dot notation to allow nested expressions

Open birchb1024 opened this issue 4 years ago • 1 comments

Consider this case:

define:
  $data1:
      atom1: 12
      atom2: 13
  $data2:
      items: 
           atom2
---
$data1,$data2.items

We get an error

Error: Subvariable value { items : atom2  } for not string or int in $data1.$data2.items

because this is being interpreted as `$data1,($data2).items.atom2

The workaround is to declare an intermediate variable:

define:
  $data1:
      atom1: 12
      atom2: 13
  $data2:
      items: 
           atom2
---
define:
   $inter:  $data2.items
---
$data1.$inter

This enhancement is to add sub-expressions to make the evaluation order explicit such as

$data1.[$data2.items]

Thereby eliminating the intermediate variable.

birchb1024 avatar Jun 20 '20 02:06 birchb1024

This is a good idea because it saves programmer time. However, I had a look at the code changes needed - I will need a proper parser for dot notation, not just a string.split(). Let me know how important this enhancement is to you...

birchb1024 avatar Jun 20 '20 03:06 birchb1024