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

Change syntax to make it more obvious whether group...compute will return scalars or records #68

Open
julianhyde opened this issue Sep 25, 2021 · 0 comments

Comments

@julianhyde
Copy link
Collaborator

Find a better syntax for group...compute to return singleton records and scalars.

Currently, group...compute sometimes returns a list of records, and sometimes a list of scalars:

(*) two fields (one key, one compute), therefore a list of records
= from e in scott.emp group e.deptno compute sum of e.sal;
val it = [...] : {deptno:int, sum:real} list

(*) one field (a key), therefore a list of scalars
= from e in scott.emp group e.deptno;
val it = [20,10,30] : int list

(*) one field (an aggregate), therefore a list of scalars
= from e in scott.emp group compute sum of e.sal;
val it = [29025.0] : real list

(*) zero fields, therefore a list of records (unit is a zero-field record)
= from e in scott.emp group;
val it = [()] : unit list

It's not obvious from the syntax whether it will produce records or singletons. It would be good if there was a more explicit syntax. For example, could we alter the syntax of group ... compute that has braces if and only if the output elements are records?

Note that if you want records in the singleton case, you can add an explicit yield:

= from e in scott.emp group compute sum of e.sal yield {sum};
val it = [{sum=29025.0}] : {sum:real} list

= from e in scott.emp group e.deptno yield {deptno};
val it = [{deptno=20},{deptno=10},{deptno=30}] : {deptno:int} list

Note that all of the above examples so work in Morel today. But a more intuitive group...compute syntax would be welcome.

@julianhyde julianhyde changed the title Find a better syntax for group...compute to return singleton records and scalars Change syntax to make it more obvious whether group...compute will return scalars or records Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant