owned this note changed 2 years ago
Published Linked with GitHub

Passing Flags and Named Parameters Around

TODO: How to create wrappers around external commands? Allow extern to have blocks:

Problem no. 1: How to pass flags around

Functional call syntax

foo(flag: true)

apply command

(requires const record and/or dynamic signature verification)

apply foo { flag: true }

Special unpacking syntax

(requires const record and/or dynamic signature verification)

bar ...$kwargs

}

Unpacking single flag: bar ...$foo

Problem no. 2: How to allow arbitrary flags in signature

(such that it's compatible with Problem no. 1)

> def foo [...rest, ...--kwargs] {
    print 'rest:' $rest
    print 'kwargs:' $kwargs
}

> foo spam -x --foo --bar baz
rest:
 0  spam
kwargs:
 x     true
 foo   true
 bar   baz

Conclusion

The "Functional call syntax" solution seems to me like the simplest method for passing flags around. The other methods based on record unpacking (apply or ...$kwargs) require either a const record, or dynamic signature verification.

Allowing arbitrary flags in signature also required dynamic signature verification. IMO it is not necessarily needed since you can pass a normal record around:

def foo [x: record] { ... }
Select a repo