Just starting with Julia/VSCode - new to both so not quite sure where best to post this question.
I have an “invalid identifier” error in my first program which is diagnosed by GitHub CoPilot as below.
I suspect this is a “hallucination” - am I correct or am I misunderstanding something?
If it is a hallucination, should I report it, and if so to GitHub or Julia?
Many thanks!
@workspace /explain invalid identifier
The error "invalid identifier" is likely caused by the line:
squb += 2ub + 1
In Julia, you need to explicitly use the multiplication operator `*` between numbers and variables. So `2ub` is invalid; it should be `2 * ub`.
Here's the corrected line:
// ...existing code...
if (n > squb)
ub += 1
squb += 2 * ub + 1
end #
// ...existing code...
**Gotcha:**
Julia does not allow implicit multiplication between numbers and variables (unlike some math notation). Always use `*` for multiplication.
Let me know if you see this error elsewhere or need further help!
Developers of the original software can’t do anything about what Copilot learned to parrot. Most you can do is discuss it in a community, which won’t begin to fix Copilot’s outputs either. Unfortunately we’re personally responsible for factchecking generative AI, which isn’t great when you’re learning the language and its Manual is unwieldy.
In your case, you are correct and Copilot is wrong.
However, I recommend to only, if ever, use such syntax with a single literal number prepending a single variable. Once it’s two compound expressions juxtaposed, hard to know in advance if that’ll work.
julia> x = 3
3
julia> 4(x+1)
16
julia> (x+1)4
ERROR: ParseError:
# Error @ REPL[2]:1:6
(x+1)4
# ╙ ── extra tokens after end of expression
julia> y = 4
4
julia> (x+1)y
16
julia> y(x+1)
ERROR: MethodError: objects of type Int64 are not callable
Maybe you forgot to use an operator such as *, ^, %, / etc. ?