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

Functions #19

Merged
merged 8 commits into from
Oct 14, 2016
Merged

Functions #19

merged 8 commits into from
Oct 14, 2016

Conversation

tfij
Copy link
Contributor

@tfij tfij commented Oct 12, 2016

No description provided.


@Override
public CompletableFuture<?> getValue(EvalContext context) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

throw?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

if (fun instanceof OpelAsyncFunction) {
return ((OpelAsyncFunction) fun).apply(argsGroup.getListOfValues(context));
}
throw new OpelException("Can use '" + fun.getClass().getSimpleName() + "' as a function");
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

}

Rule FunctionBody() {
return FirstOf(

Choose a reason for hiding this comment

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

Why not:

return FirstOf(
                 Expression(),
                 Sequence("{ ", Body(), "} "), push(pop()));

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

enough is

return FirstOf(
                Expression(),
                Sequence("{ ", Body(), "} "));

"val fun = (x, y) -> x*y; fun(2, 3, 4, 5)" || 6
}

def 'should avoid access to val defined in function outsite its'() {
Copy link

@pawel-piecyk pawel-piecyk Oct 13, 2016

Choose a reason for hiding this comment

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

You can add similar test showing that local val declaration doesn't change outer val e.g.

val x = 10;
val y = (a) -> {
  val x = 5;
  x * a;
}(5)

assert x == 10

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test added


then:
def ex = thrown ExecutionException
ex.cause instanceof OpelException

Choose a reason for hiding this comment

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

I don't like the fact that we only check if OpelException was thrown while cause is completely ignored. I can modify the first case to val fun = x -> x*x; fun(4) * 'a' and this test will pass. Maybe it's a good time to introduce hierarchy of exceptions or check for sufficient messages in tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exception hierarchy sound good.
I can do this in separate PR

@tfij tfij merged commit aa698c5 into master Oct 14, 2016
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.

3 participants