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

Add back table<R> #153

Closed
jclark opened this issue May 29, 2019 · 3 comments
Closed

Add back table<R> #153

jclark opened this issue May 29, 2019 · 3 comments
Labels
Area/jballerina Improves alignment of spec with jballerina Area/Lang Relates to the Ballerina language specification design/incomplete Part of design not yet worked out status/pending Design is agreed and waiting to be added
Milestone

Comments

@jclark
Copy link
Collaborator

jclark commented May 29, 2019

Table is supposed to be iterable in its rows. This means the lang.table module needs an iterator function.

We previously allowed table<R> as a shorthand. With this we can write iterator like this:

@typeParam
private type Type = anydata|error;

public function iterator(table<Type> tbl) returns abstract object {
    public next() returns record {|
        Type value;
    |}?;
} = external;

Without this we would need to invent something else.

I am 90% sure we will want this anyway and it is still in the implementation. We can leave the semantics a bit vague until we fix issue #47.

@jclark jclark added Area/Lang Relates to the Ballerina language specification design/incomplete Part of design not yet worked out Area/jballerina Improves alignment of spec with jballerina labels May 29, 2019
@jclark jclark added this to the 2019R2 milestone May 29, 2019
@sanjiva
Copy link
Contributor

sanjiva commented May 30, 2019

So table<R> == table { *R; } right? So its a lightweight table without keys.

+1 for this.

@jclark
Copy link
Collaborator Author

jclark commented May 30, 2019

Right, at least when R is closed.

@jclark jclark added the status/pending Design is agreed and waiting to be added label May 31, 2019
@jclark jclark closed this as completed in 5dad364 May 31, 2019
@jclark
Copy link
Collaborator Author

jclark commented Jun 1, 2019

We previous removed this for two reasons:

  • mutation: mutating the values you get from an iterator does not affect the table, as it would do for map and T[]
  • the record type has to be sealed, but it would be annoying to always require users to write the !...

But both of these can be dealt with:

  • I believe tables should contain only frozen values, which means the record returned from an iterator can also be frozen
  • open table types actually make sense and are useful, provided they are not used as inherent type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/jballerina Improves alignment of spec with jballerina Area/Lang Relates to the Ballerina language specification design/incomplete Part of design not yet worked out status/pending Design is agreed and waiting to be added
Projects
None yet
Development

No branches or pull requests

2 participants