ZoKrates icon indicating copy to clipboard operation
ZoKrates copied to clipboard

Interpret multi-line function parameters / array assignments

Open iAmMichaelConnor opened this issue 4 years ago • 2 comments

Hi team! This is probably a low priority 'nice-to-have' feature...

Currently, multi-line comma-separated 'lists' aren't supported.

Examples of 'comma separated lists' (I can't think of a better term for these):

struct MyStruct {
    field key1
    field key2
    field key3
}

def myFunction(field a, field b, field c) -> (field):
    field[3] myArray = [a, b, c]
    field d = otherFunction(a, b, c)
    MyStruct myStruct = MyStruct { key1: a, key2: b, key3: c }

Sometimes, especially working with long variable names, or accessing structs, these 'lists' can spill onto many lines and be difficult to read.

Would it be possible to allow multi-line lists? E.g.:

def myFunction(
    field a,
    field b,
    field c
) -> (field):
    field[3] myArray = [
        a,
        b,
        c
    ]
    field d = otherFunction(
        a,
        b,
        c
    )
    MyStruct myStruct = MyStruct {
        key1: a,
        key2: b,
        key3: c
    }

iAmMichaelConnor avatar Jun 17 '20 13:06 iAmMichaelConnor

Hey @iAmMichaelConnor, this should work today:

def main(\
    field a,\
    field b,\
    field c\
) -> (field):
    field[3] myArray = [\
        a,\
        b,\
        c\
    ]
    field d = otherFunction(\
        a,\
        b,\
        c\
    )
    MyStruct myStruct = MyStruct {\
        key1: a,\
        key2: b,\
        key3: c\
    }
    return 1

How do you feel about it?

Schaeff avatar Jun 19 '20 13:06 Schaeff

Ah, super, this looks good to me! Thanks @Schaeff.

If it's easy to infer a new line from a comma , instead, then that would be even better. But if it's too much work at this stage of development, then this issue can be closed (because a line break \ will still make my code much more readable than it was previously).

iAmMichaelConnor avatar Jun 19 '20 16:06 iAmMichaelConnor