Skip to content

Negative numbers are not syntactic literals #1799

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

Open
moodymudskipper opened this issue Apr 25, 2025 · 2 comments
Open

Negative numbers are not syntactic literals #1799

moodymudskipper opened this issue Apr 25, 2025 · 2 comments

Comments

@moodymudskipper
Copy link

moodymudskipper commented Apr 25, 2025

Since they use -.

We dismiss complex numbers with a real part, presumably because of the +, so it would make sense to return FALSE for negative integer, double, and imaginary numbers.

x <- quote((-1))
y <- substitute((X), list(X = -1))
x
#> (-1)
y
#> (-1)
typeof(x[[2]])
#> [1] "language"
typeof(y[[2]])
#> [1] "double"
rlang::is_expression(x) # correct
#> [1] TRUE
rlang::is_expression(y) # incorrect
#> [1] TRUE

Related: rlang::is_syntactic_literal(NA + 1i) is currently TRUE, to be a syntactic literal a complex number must have a real part of 0.

@lionel-
Copy link
Member

lionel- commented May 1, 2025

I'm tempted to deprecate this functionality as we don't use it for anything important and it sounds like a pain to keep maintaining it.

Would you have any interest in taking over these functions and maintaining them in another package?

@moodymudskipper
Copy link
Author

moodymudskipper commented May 3, 2025

In constructive I have already is_expression2() and is_syntactic_litteral2(), both unexported, which are mostly similar, though I don't think I based the former on yours directly. I need those so i can generate the code to construct language objects faithfully. I can remove the "2", make sure they pass rlang's own tests and export them there, but don't you need those in rlang for expr_deparse() and friends ?

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

2 participants