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

[WIP] Closures prototype #570

Closed
wants to merge 10 commits into from
Closed

Conversation

nhuurre
Copy link
Collaborator

@nhuurre nhuurre commented Jun 5, 2020

Add closures to the Stan language. The math library implementation is stan-dev/math#1924

See also the desing-doc stan-dev/design-docs#6 and the forum discussion https://discourse.mc-stan.org/t/closures-discussion/14932/

A closure definition begins functions keyword and otherwise looks just like a function definition. The keyword isn't ideal but something is needed to avoid ambiguity with ordinary variable declarations.

@rybern
Copy link
Collaborator

rybern commented Jun 6, 2020

Hi Niko. You mentioned on Discourse that the parser isn't behaving. I just went through the gauntlet with the parser for declarations, so I thought I'd have a look.

The issue is a reduce/reduce conflict between return_type inside closure_def and sized_basic_type inside var_decl. You could %inline return_type, but then you run into the more fundamental issue of a reduce/reduce conflict between basic_type and sized_basic_type. Essentially, when the parser sees int..., it doesn't know whether to reduce the int to an unsized type (leading up to a declaration) or a sized type (leading up to a closure). It becomes unambiguous when the parentheses are read, but it needs to be unambiguous at the point of decision between sized and unsized.

I came up with a trick to solve a similar issue in #561 that I think I can apply here. But, since it'll take some work, I'd rather do it when you're stable here and when #561 is merged (since it included some refactoring).

@nhuurre
Copy link
Collaborator Author

nhuurre commented Nov 18, 2020

Closing in favor of #742

@nhuurre nhuurre closed this Nov 18, 2020
@nhuurre nhuurre mentioned this pull request Feb 23, 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

Successfully merging this pull request may close these issues.

2 participants