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

bug: $x.$number() incorrectly returns no value #155

Open
tommy opened this issue Jan 9, 2025 · 0 comments
Open

bug: $x.$number() incorrectly returns no value #155

tommy opened this issue Jan 9, 2025 · 0 comments

Comments

@tommy
Copy link
Contributor

tommy commented Jan 9, 2025

The . syntax introduces a "context" variable named $. Some built-in functions ($string, $number, $abs, etc) are meant to use the value of $ as the first parameter if no explicit arguments are provided. This is probably a discrepancy with our other functions as well.

/* in the Javascript reference implementation: */
( $x := "123"; $number($x) ) /* evals to 123 */ ,
( $x := "123"; $x.$number($) ) /* evals to 123 */ ,
( $x := "123"; $x.$number() ) /* evals to 123 */ ,

/* in jsonata-rs: */
( $x := "123"; $number($x) ) /* evals to 123 */ ,
( $x := "123"; $x.$number($) ) /* evals to 123 */ ,
( $x := "123"; $x.$number() ) /* returns no match */ ,

Note that this behavior is (as far as I can tell) specific to each function. That is, it's not the case that every function invoked in this way gets the context parameter injected. Eg:

/* Javascript */
( $f := function($arg) { $arg } ; $x := "123" ; $x.$f() ) /* returns no match */ ,
( $f := function($arg) { $arg } ; $x := "123" ; $f($x) ) /* returns "123" */ ,
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

No branches or pull requests

1 participant