You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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: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
:Note that all of the above examples so work in Morel today. But a more intuitive
group...compute
syntax would be welcome.The text was updated successfully, but these errors were encountered: