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

Reducer dev #226

Merged
merged 22 commits into from
Apr 12, 2022
Merged

Reducer dev #226

merged 22 commits into from
Apr 12, 2022

Conversation

umuro
Copy link
Contributor

@umuro umuro commented Apr 11, 2022

// Multiple statements and variables

describe("assignment", () => {
testEvalToBe("x=1; x", "Ok(1)")
testEvalToBe("x=1+1; x+1", "Ok(3)")
testEvalToBe("x=1; y=x+1; y+1", "Ok(3)")
testEvalToBe("1; x=1", "Error(Assignment expected)")
testEvalToBe("1; 1", "Error(Assignment expected)") //No position info from MathJs parse...
testEvalToBe("x=1; x=1", "Error(Expression expected)")
})

Umur Ozkul added 14 commits April 5, 2022 18:56
format only reducer

reformat lint

multi-line test

spelling

multi-line semantic mapping

todo multi-line eval

multi-line tests todo

change context to bindings

simplify tests

rename exception test methods

bindings is an expression value

make bindings callable

reformat

Emphasize the nature of Lisp AST

Initial definition of macros

make functions private

fixed functionNode type casting

macro call skeleton

sort ReducerInterface

fix test

macros skeleton

bindings is not a value

assignment semantics

let semantics defined

format

reformat

reformat

TODO function calls and list hd variables are confused

reformat

tmp

works

reformat

reformat

add test

reformat

add test
@netlify
Copy link

netlify bot commented Apr 11, 2022

Deploy Preview for squiggle-documentation canceled.

Name Link
🔨 Latest commit fea990d
🔍 Latest deploy log https://app.netlify.com/sites/squiggle-documentation/deploys/62560c794535cb0008c7ad5f

@netlify
Copy link

netlify bot commented Apr 11, 2022

Deploy Preview for squiggle-components failed.

Name Link
🔨 Latest commit fea990d
🔍 Latest deploy log https://app.netlify.com/sites/squiggle-components/deploys/62560c79475e460008cca42c

Copy link
Contributor

@quinn-dougherty quinn-dougherty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some preliminary comments, may come back for a more substantial pass.

@quinn-dougherty
Copy link
Contributor

testEvalToBe("1; x=1", "Error(Assignment expected)")

This is not par with old squiggle, I think? we allow the evaluation of expressions in a non-bottom-of-file spot. It's not an important feature, but we should think twice about removing it. @OAGr

@OAGr
Copy link
Contributor

OAGr commented Apr 11, 2022

This is not par with old squiggle, I think? we allow the evaluation of expressions in a non-bottom-of-file spot. It's not an important feature, but we should think twice about removing it. @OAGr

image

I think I don't care too much about this case. However, this might break the functionality we currently have of showing each item that's rendered, no matter what the output is. However, my guess is that that's not going to work with the Reducer set up, as is, anyway, so it doesn't matter much. (I'd think)

@umuro
Copy link
Contributor Author

umuro commented Apr 11, 2022

It is assignment; ... assignment; expr. Because assignments return bindings as a result. If you simply insert an expression then that expression's result passes up as bindings. Oops. To simulate statements in the middle, one has to convert them to "fake" assignments. Your feature is possible. But I need to count the array index and prepend a "_ = " assignment to every statement if they are not the last one. Could be handled as a feature. However, I don't see a use for it in a functional language. There are other ways of creating side effects in the middle. (to be discussed).

@umuro
Copy link
Contributor Author

umuro commented Apr 11, 2022

This is not par with old squiggle, I think? we allow the evaluation of expressions in a non-bottom-of-file spot. It's not an important feature, but we should think twice about removing it. @OAGr

image

I think I don't care too much about this case. However, this might break the functionality we currently have of showing each item that's rendered, no matter what the output is. However, my guess is that that's not going to work with the Reducer set up, as is, anyway, so it doesn't matter much. (I'd think)

{1; 2} => {_ = 1; 2} //feasible feature
{1; y=2} // y is unused variable. This is a functional programming mistake

umuro#52

@umuro
Copy link
Contributor Author

umuro commented Apr 11, 2022

testEvalToBe("1; x=1", "Error(Assignment expected)")

This is not par with old squiggle, I think? we allow the evaluation of expressions in a non-bottom-of-file spot. It's not an important feature, but we should think twice about removing it. @OAGr

Additional note. The philosophy of reducer is connecting a parser with the reducer using "functional semantics". Not implementing it per grammar. The semantic definition assignments is really a function that return bindings. But eventually any grammar is possible. Of course as long as it is a functional language. Not functionalish.

Semantic definitions are how you define the meaning of the parsed grammar.

{1; 2;} can become {_ = 1; 2;} via an additional semantic definition and it can work.
You can even make {1; y=2;} to work. In this case the semantic conversion would be
{_ = 1; y=2; $currentBindings['y'] }

@quinn-dougherty
Copy link
Contributor

quinn-dougherty commented Apr 11, 2022

Sorry, Components lint and Website lint shouldn't be triggering. I don't know why they're running. I know why it's because of the rebasey MC resolve push. It shouldn't happen on subsequent pushes.

@quinn-dougherty quinn-dougherty added the Language Regarding Squiggle language semantics, distributions and function registry label Apr 12, 2022
Copy link
Collaborator

@Hazelfire Hazelfire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'd like to see a couple of critical features that might require you to give up on the concept of lisp like purity within the reducer:

  • I think it's critical that calls to evaluate also return the bindings that were created during that expression. This is because I want to share these variables between different executions. I think evalWBindings will be the main part of the API. But to get the bindings object from previous executions it needs to return the bindings at some point
  • It should be possible to return nothing in an execution and give only variables, or return multiple things in an execution. Both of these features would prove useful in practice.

Other than that. I really can't wait to see this in! I'm super excited about this work. Thank you!

@umuro
Copy link
Contributor Author

umuro commented Apr 12, 2022

  • Bindings

Ok. I am adding this as a feature to do. eval will return just an answer but evalWBindings will return the bindings as well
umuro#58

@OAGr
Copy link
Contributor

OAGr commented Apr 12, 2022

I think I'd like to see a couple of critical features that might require you to give up on the concept of lisp like purity within the reducer:

I think it's critical that calls to evaluate also return the bindings that were created during that expression. This is because I want to share these variables between different executions. I think evalWBindings will be the main part of the API. But to get the bindings object from previous executions it needs to return the bindings at some point
It should be possible to return nothing in an execution and give only variables, or return multiple things in an execution. Both of these features would prove useful in practice.

@umuro I think it's fine for us to punt these to later, they don't have to be part of this PR. (Especially given that they weren't part of the previous version anyway)

Copy link
Collaborator

@Hazelfire Hazelfire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be cool to see this merged, and punt returning the environment down the line. Would love to see that somewhat soon though considering it's the last step needed to get Squiggle notebooks

@umuro
Copy link
Contributor Author

umuro commented Apr 12, 2022

I think I'd like to see a couple of critical features that might require you to give up on the concept of lisp like purity within the reducer:

I think it's critical that calls to evaluate also return the bindings that were created during that expression. This is because I want to share these variables between different executions. I think evalWBindings will be the main part of the API. But to get the bindings object from previous executions it needs to return the bindings at some point
It should be possible to return nothing in an execution and give only variables, or return multiple things in an execution. Both of these features would prove useful in practice.

@umuro I think it's fine for us to punt these to later, they don't have to be part of this PR. (Especially given that they weren't part of the previous version anyway)

I think I'd like to see a couple of critical features that might require you to give up on the concept of lisp like purity within the reducer:

I think it's critical that calls to evaluate also return the bindings that were created during that expression. This is because I want to share these variables between different executions. I think evalWBindings will be the main part of the API. But to get the bindings object from previous executions it needs to return the bindings at some point
It should be possible to return nothing in an execution and give only variables, or return multiple things in an execution. Both of these features would prove useful in practice.

@umuro I think it's fine for us to punt these to later, they don't have to be part of this PR. (Especially given that they weren't part of the previous version anyway)

umuro#58 Added as a feature. I will provide bindings as a return from evalWBindings.

@OAGr OAGr dismissed Hazelfire’s stale review April 12, 2022 11:31

Changes could be done in future PRs

@umuro
Copy link
Contributor Author

umuro commented Apr 12, 2022

I think I'd like to see a couple of critical features that might require you to give up on the concept of lisp like purity within the reducer:

* I think it's critical that calls to evaluate also return the bindings that were created during that expression. This is because I want to share these variables between different executions. I think evalWBindings will be the main part of the API. But to get the bindings object from previous executions it needs to return the bindings at some point

* It should be possible to return nothing in an execution and give only variables, or return multiple things in an execution. Both of these features would prove useful in practice.

Other than that. I really can't wait to see this in! I'm super excited about this work. Thank you!

A) Return multiple things. Just build a record or array We have records. Instead of relying on internal structures of resolver. Don't create a script with invisible assumptions.
B) I would rather explicitly return void. Or better a record of the variables.

Instead of hunting variables in the bindings, why don't you write
{a = 1
b = 2
%{a: 1, b: 2}
}

Moreover, we can add the semantic rule that returning nothing is auto constructing a record of variables and returnint it :)

@umuro
Copy link
Contributor Author

umuro commented Apr 12, 2022

I think I'd like to see a couple of critical features that might require you to give up on the concept of lisp like purity within the reducer:

I think it's critical that calls to evaluate also return the bindings that were created during that expression. This is because I want to share these variables between different executions. I think evalWBindings will be the main part of the API. But to get the bindings object from previous executions it needs to return the bindings at some point
It should be possible to return nothing in an execution and give only variables, or return multiple things in an execution. Both of these features would prove useful in practice.

@umuro I think it's fine for us to punt these to later, they don't have to be part of this PR. (Especially given that they weren't part of the previous version anyway)

I think I'd like to see a couple of critical features that might require you to give up on the concept of lisp like purity within the reducer:

I think it's critical that calls to evaluate also return the bindings that were created during that expression. This is because I want to share these variables between different executions. I think evalWBindings will be the main part of the API. But to get the bindings object from previous executions it needs to return the bindings at some point
It should be possible to return nothing in an execution and give only variables, or return multiple things in an execution. Both of these features would prove useful in practice.

@umuro I think it's fine for us to punt these to later, they don't have to be part of this PR. (Especially given that they weren't part of the previous version anyway)

umuro#58 Added as a feature. I will provide bindings as a return from evalWBindings.

Instead of hunting variables in the bindings, why don't you write
{a = 1
b = 2
%{a: 1, b: 2}
}

Umur Ozkul added 6 commits April 12, 2022 15:46
packages/squiggle-lang/src/rescript/Reducer/Reducer_Expression/Reducer_Expression.resi
Too many changes. Hot target. Preventing development
@Hazelfire
Copy link
Collaborator

Hey! Sorry about the review earlier, I realised that I probably didn't give enough context and it could have seemed overly harsh. I'm very new to coding with other people.

I'd love to see this merged soon, the bindings thing can be done later. I'll put more context as to why bindings is important in #234. But basically the reason I put that review in is because I looked into the future a tad (by merging this on my local machine), saw variables working, but only needed the environment to be returned to recreate a Squiggle Notebook. Because I thought it was a minor change (although I might be wrong), and is to me the most important feature (because it gets us back to the Squiggle Notebook milestone) I thought it would be nice to include it here.

@Hazelfire
Copy link
Collaborator

However, that can easily be another story

@Hazelfire
Copy link
Collaborator

Hey @umuro , here's your patch for the JS tests to pass

diff --git a/packages/squiggle-lang/src/js/index.ts b/packages/squiggle-lang/src/js/index.ts
index 1a53aa6..4b8cdda 100644
--- a/packages/squiggle-lang/src/js/index.ts
+++ b/packages/squiggle-lang/src/js/index.ts
@@ -88,6 +88,7 @@ function tag<a, b>(x: a, y: b): tagged<a, b> {
 export type squiggleExpression =
   | tagged<"symbol", string>
   | tagged<"string", string>
+  | tagged<"call", string>
   | tagged<"array", squiggleExpression[]>
   | tagged<"boolean", boolean>
   | tagged<"distribution", Distribution>

@OAGr OAGr merged commit 263c427 into quantified-uncertainty:develop Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Regarding Squiggle language semantics, distributions and function registry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants