-
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
Array proposal #281
Comments
This all makes sense to me. Some things we should probably consider: Can we generate arrays?If we are adding Can we mutate arrays?We might want to append, prepend, pop, shift arrays. Not sure what the syntax of that would look like, maybe something like:
Can we mutate indexes? Is Similar to mutation is sorting, reversing, etc, we might need builtin functions or a strategy for this. Do we support generic array types?As we develop arrays, there might be some common code that does not care about array types, just that an argument is an array. Sorting and mutations can sometimes benefit from generics. Like:
vs something like
There are several generic syntaxes we could go with. Looping controlWe will likely need control structures for loops, so equivalent to |
Good idea, though I think we should leave it out of the MVP.
I'm open to array access, but assignment is still something I want to avoid for now. We can bundle it up with variable assignment if/when we get there.
I'm open to generics, wanted the feature to also tackle things like
Yes, I think this should be in scope for MVP. Should there be anything else besides |
+1 on starting without array assignment |
This proposal is great! I particularly love the type inference, although I'm worried it might be difficult or impossible for builtins with ambiguous types like The other questions that this proposal raises for me are regarding the "set"-like behaviour of |
@slushie regarding your questions about I think it is up to the implementation of the builtin being annotated to decide:
I left it out of this proposal because it was already getting too long but I have ideas around splatting too. I wanted the For example, if your function takes variadic:
And you wanted it to be multi-line to avoid git blast radius and readability:
Since its an function invocation, the args are typed so the array declaration is type inferred. Looks pretty elegant to me. |
Types have multiple categories
Scalar:
fs
,pipeline
,string
,bool
,int
,option
Array:
[]fs
,[]pipeline
, ...And future composite types if we need.
Types may have association
Association operator
::
, really only valid foroption
atm.E.g.
option::run
,option::mount
.Previously this was implemented by just allowing
:
as a valid char in theIdent
lexer symbol. It's no longer a valid char inIdent
because we don't want to confuse idents with:
with types that have association.Arrays in function signature
Array declaration
The context difference between
[]fs
andfs
functions may cause confusion, but this is the trade-off taken to afford other aspects of the array design.If we emit compiler errors on cases like
run
onscratch
, it will get rid of unintended user errors.Block literals no longer have a type prefix
Previously, block literals, e.g.
fs { ... }
are valid expressions, so can be used as arguments.The rationale will be explained in later sections, but in this proposal block literals only allow for type inference. (Declaring type is not allowed)
The function
mount
signature knows the first arg is afs
type, so that's how the checker will know what type the block literal is now.Array declarations are NOT block literals
Block literal body
{ ... }
has an modify context.Functions execute using the current value of the return register.
Block literals do not define a type, and can only be inferred.
Single line block literals are delimited by
;
, multi-line is optionally delimited.Array declaration body
{ ... }
has an append context.Functions execute and append to the current array in the return register.
Array declarations may define a type, but can also be inferred.
Single line array declarations are delimited by
,
, multi-line is optionally delimited.Where they are similar is that a singular expression is valid as a block literal with a single statement or single element array.
Note that string interpolation like
image("hinshun/${foobar}")
is a block literal too with thestring
type inferred.With Option
The grammar for a call expression is:
<func-ident> <args> ("with" <expr>)? ("as" <expr>)}
Previously, a block literal was the common expression used:
Where
option { ... }
was a block literal with theoption
type. But it has two main issues:option
wasn't the right type and had to inferoption::run
during type checking.option
block literals actually had an append context, not a modify context likefs
.Option blocks were really
[]option::run
array declarations.Note that just simply
[]option
is no longer validIf else, for loops
If else statements, and for loops are planned but syntax is considered out of scope for this GitHub issue.
In this proposal block literal became strictly type inferred because they are a parsing menace for LL parsers like
participle
. Since call expressions that have no arguments have their()
parens optional (i.e.scratch
instead ofscratch()
), the<ident>
followed by an open brace{
is parsed into a block literal in many cases.For example, consider the follow if statement construction:
If the boolean expr is a no-arg function like
foo
, then it becomes:But since block literals are also valid expressions, its ambiguous whether the
<ident> { ... }
is a block literal that forms the conditional for the if statement, or<ident>
is the conditional and{ ... }
is the body of the if statement.Once block literals are strictly type inferred, the ambiguity is gone.
The text was updated successfully, but these errors were encountered: