Ensure unboundFunction is bound to the right symbol #439
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
That way the error messagae will be correct regardless if we invoke it
like symbol.fvalue() or if we assign it first into a variable, losing
the
this
context.Detailed
I started debugging #438, narrow it down to this simple issue:
It should be more intuitive than that error. Like the regular
equalp
is not bound.Looking at the definition, and how it dispatches by sequence type, I tried with other couple of sequences:
jscl/src/sequence.lisp
Lines 353 to 383 in 29885f7
still happens. So it seems that it migth be in the generic util
satisfies-test-p
, and indeed:The only thing this does is calling
funcall
So we can simplify it even more to just
funcall
:At this point this is a primitive compilation defined in the compiler. I did generate the code for that simple example with
resulting in:
Not a lot happening.. no mention of the
name
. Except I noticed something.symbol.fvalue
is initialized tounboundFunction
in order to generate an error if a undefined function is called. Code code in prelude isjscl/src/prelude.js
Lines 334 to 336 in 29885f7
This could explain. If
unboundFunction
's this is only defined if we call it like symb.fvalue. If we get that value out into another expression and call it.this
will be undefined.We can try that int he JS console:
that is correct. But if the compiler generates:
Then we can reproduce the problem.
That is kind of what the compiler generates!
Possible solutions for this would be:
this
inunboundSymbol
, bind it it to the symbol when the symbol isintern
edthis
context associated.We could generate fo rinstance
The
bind
method is more robust probably.