Skip to content
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

syntax for creating empty n-dimensional arrays #41389

Closed
simeonschaub opened this issue Jun 27, 2021 · 2 comments · Fixed by #41618
Closed

syntax for creating empty n-dimensional arrays #41389

simeonschaub opened this issue Jun 27, 2021 · 2 comments · Fixed by #41618
Labels
arrays [a, r, r, a, y, s] parser Language parsing and surface syntax

Comments

@simeonschaub
Copy link
Member

These currently throw an error:

julia> [;]
ERROR: syntax: unexpected ";"
Stacktrace:
 [1] top-level scope
   @ none:1

julia> [;;]
ERROR: syntax: unexpected ";"
Stacktrace:
 [1] top-level scope
   @ none:1

julia> [;;;]
ERROR: syntax: unexpected ";"
Stacktrace:
 [1] top-level scope
   @ none:1

I think it would make sense for them to return an empty vector/0×0 matrix/0×0×0 array respectively.

@simeonschaub simeonschaub added arrays [a, r, r, a, y, s] parser Language parsing and surface syntax labels Jun 27, 2021
@BioTurboNick
Copy link
Contributor

I don't have time to implement it myself right now, but I looked into it:

[;] makes it into parse-cat and then the token stream is sent into parse-eq to determine the first value. The error originates inside parse-eq. Perhaps just need to check if the first value is a semicolon? Could set first to null, send it into parse-array. I'm not sure what parse-array would do when first is null, but I'm guessing it might generate (or could be made to generate) the syntax vect, ncat 2, ncat 3, with no contents. Then expand-ncat in julia-syntax.scm may need to check if a is null, or the helper functions all need to be made aware of the potential for a could be null (hasrows-flatten, is-1d). is-1d should return true, which would lower into hvncat(2), hvncat(3), which with #41197 will produce the desired output.

@StefanKarpinski
Copy link
Sponsor Member

StefanKarpinski commented Jul 8, 2021

Nice idea. This would "only" leave us with no literal syntax for empty zero-dimensional arrays, but fortunately there is no such thing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] parser Language parsing and surface syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants