-
Notifications
You must be signed in to change notification settings - Fork 440
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
Weird errors when abusing functions #100
Comments
Also weird: {
identity(obj)::
function(obj) obj,
addOne(obj):
obj + 1,
bind(func1, func2)::
function(obj) func2(func1(obj)),
"1": self.bind(self.identity, self.addOne)(1),
"2": self.bind(self.addOne, self.identity)(1),
} case 1 gives:
case 2 gives:
|
Why
and not
or
|
ya that's definitely what I meant. thanks. Both of these still return an error {
identity(obj)::
obj,
addOne(obj):
obj + 1,
bind1(func1, func2)::
function(obj) func2(func1(obj)),
bind2(func1, func2)::
function(obj)
local tmp1 = func1(obj);
local tmp2 = func2(tmp1);
tmp2,
"1": self.bind1(self.identity, self.addOne)(1),
"2": self.bind2(self.identity, self.addOne)(1),
} Error:
Is that correct? |
and a third: ...
"3": self.bind2(self.identity, self.addOne)(1)(1),
} calling what the previous error said was a function, results in:
|
You only have one colon on addOne, but in this case the stacktrace is bad as it did not point you at addOne. I'll look into that quickly... |
Awesome! Works great. Thanks for the extra pair of eyes. $ cat libmonad.jsonnet
{
identity(obj)::
obj,
addOne(obj)::
obj + 1,
bind1(func1, func2)::
function(obj) func2(func1(obj)),
bind2(func1, func2)::
function(obj)
local tmp1 = func1(obj);
local tmp2 = func2(tmp1);
tmp2,
"1": self.bind1(self.identity, self.addOne)(1),
"2": self.bind1(self.addOne, self.identity)(1),
"3": self.bind2(self.identity, self.addOne)(1),
"4": self.bind2(self.addOne, self.identity)(1),
}
$ jsonnet libmonad.jsonnet
{
"1": 2,
"2": 2,
"3": 2,
"4": 2
} So the error was coming from trying to serialize addOne where it was declared since it wasn't marked private... |
s/private/hidden :) |
I just committed a fix for the stacktrace, it now refers to the line containing the obj + 1 which is not exactly perfect, but other than pointing to the (obj) tokens at which I don't currently record location information, it's the best I can do. |
Can you tell me if this is expected?
Given this code:
case 1 and 2 fail with:
case 3 and 4 (which switch the order of the arguments from case 1 and 2) fail with:
case 5 and 6 (which add an extra (1) to 3 and 4) work without error and produce and semi unexpected result:
case 7 and 8 produce the expected result:
It seems like anonymous and declared functions act differently
The text was updated successfully, but these errors were encountered: