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

order after yield gives 'unbound variable' error #64

Closed
julianhyde opened this issue Sep 14, 2021 · 2 comments
Closed

order after yield gives 'unbound variable' error #64

julianhyde opened this issue Sep 14, 2021 · 2 comments

Comments

@julianhyde
Copy link
Collaborator

order after yield gives 'unbound variable or constructor' error.

For example:

val emps = [
   {id = 100, name = "Fred", deptno = 10},
   {id = 101, name = "Velma", deptno = 20},
   {id = 102, name = "Shaggy", deptno = 30},
   {id = 103, name = "Scooby", deptno = 30}];
from e in emps
  yield {e.name, e.deptno}
  order deptno
unbound variable or constructor: e
@julianhyde
Copy link
Collaborator Author

In this fix, we also clarify the type of from with various clauses.

yield with record returns a record, even if that record has 1 field:

- from i in [1, 2, 3]
=   yield {i};
val it = [{i=1},{i=2},{i=3}] : {i:int} list

yield can also have a scalar value:

from i in [1,2,3]
  yield i mod 3;
val it = [1,2,0] : int list

But if the yield is in the middle of a pipeline, the scalar form is pretty useless; you need a field name in order to be table to use it in the next clause, so use a single-field record:

- from i in [1,2,3]
=   yield {j = i mod 3}
=   order j;
val it = [{j=0},{j=1},{j=2}] : {j:int} list

You can add another yield to convert it back to a scalar:

- from i in [1,2,3]
=   yield {j = i mod 3}
=   order j
=   yield j;
val it = [0,1,2] : int list

@julianhyde
Copy link
Collaborator Author

Fixed in d1c0352.

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