-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposing the composite type: arrays #211
Comments
interesting ideas, the I do have a few clarifying questions and ideas, not sure they are terribly practical... 1) fs/pipeline array usageso can we do this? What does this return?
Similar for pipelines, what does this return:
2) array generation with
|
That's valid and equivalent of running this target:
I'm not sure how to combat this, one thought is to make use of the
Good point, I think that's actually the correct way of writing pipelines and that my example is wrong. I'm not sure a single element
So for this proposal, the statements in the body of a for loop behaves the same as its outer block. So in a function with an array return type, those statements are appending so you can think of it as a If the return type was
I didn't mention it in this proposal, but we could possible expose the return register as
Yes I was thinking of
But I don't have anything concrete atm. Another thought is that we should decouple real I'm also not sure how far we should support functionality in this way, there's certainly better tools for this than a build language. I was hoping for loops was more of a macro than anything.
Yeah I've been thinking about user-defined types of |
This is pretty confusing to me. I was originally thinking something more like this:
The
or more used like
Maybe these would be equivalent to:
Sounds good to me.
Yeah, I would personally skip |
Tangentially, have you considered adding a void return type? In the managed artifacts workshop, there is more than one case of the following:
|
I may be way off here, but it feels like the arrays tend to be used as stacks. Is there any reason not to make them first-class stacks instead of arrays that typically are used as stacks? Do you think we will get value out of random access, slicing, etc? That's not to say that there's anything wrong with providing functionality for random access and slicing, but there's a certain beauty in stack-based languages like FORTH, so I think it's worth considering making the primitive a stack.
Making the behavior so contextual feels like it would be confusing (to me, at least). What about having separate I'm accustomed to thinking of
My instinct is to design the syntax in a way that would eventually allow multidimensional arrays if we decide it's worth it, but start by only supporting one-dimensional arrays to keep things simple and get a better feel for how people use the feature. |
Currently, the types supported are
string
,int
,bool
,fs
,option
, andpipeline
.This proposal introduces composite types, allowing for
[]string
,[]int
,[]bool
,[]fs
,[]option
, and[]pipeline
, as well asfor loops
.Proposal
For arrays to work well in practice, we want to ensure we have data flow analysis to return compile errors for
dead code
, so that will be a prerequisite.Here is a function returning an array. Instead of overriding the value of the return register, they are appended similar to declaring the elements of an array. (1. Statements in array blocks append to return register instead of modify)
You can invoke functions that also return the same type array and they are splatted automatically. (2. Arrays are splatted automatically)
This is useful when combined with
for loop
, here's the proposed structure.For example, when you need to publish an image to multiple registries:
Since the
for loop
expects an expression, you can also provide a block literal as an expression.Note you can still do this inline, but follows regular block syntax (i.e. separate statements by
;
).Elements or slices of an array can be accessed through array indexing. For example, if we need to bind the digest of one of the registries we pushed to.
You can also pass arrays to functions that expect variadic arguments because they are splatted automatically.
This proposal also addresses the special handling of option blocks, where they behaved like arrays when arrays didn't exist. By changing
with option
->with []option
and function declarations foroption
->[]option
in the linter.Suppose we have a builitn
localWalk
, we can combine this withfor loop
to produce a list of options for mounting decrypted secrets.The text was updated successfully, but these errors were encountered: