This gave me a "Variable RESULT is undefined": ``...
# cfml-general
p
This gave me a "Variable RESULT is undefined":
Copy code
function add1(arg) {
   var result = arg
   result += 1
   return result
}
two = add1(1)
WriteOutput(two)
But changing it to this fixed it:
Copy code
function add1(arg) {
   var result=0
   result = arg
   result += 1
   return result
}
two = add1(1)
WriteOutput(two)
b
Code runs in Lucee, seems like a bug
I noticed if I dump out result after declaring it, it dump out fine AND the code below runs without error
Adding semi-colons to each line, makes it work
I noticed because I had to go all the way back to CF 2016 to get it to run (which required semicolons) and then the code worked in all versions
I assume two of the lines are getting parsed as a single expression/statement, but without being able to see some sort of parse tree, I'm not sure how ACF is parsing it
Just adding a semi colon to this line
Copy code
var result = arg;
allows it to work, so I can only guess the next line is some how being parsed as part of the previous line, which is odd since
Copy code
var result = arg result += 1
shouldn't be parsed as a single statement so far as I can tell
πŸ™ƒ 1
πŸ† 1
I'd put in a ticket
p
Wow Brad. Thank you very much!
m
A new dent in my keyboard. Nice find Brad.
πŸ‘ 1
s
Maybe a besides the point, but why not use ; as a general rule to define a line ending to your code? I mean, this isn't python or something similar, right?
p
If I remove semi colons then it improves every line of code just a little bit.
And if I make a little bitty improvement to every single line of code, then that ends up being a big improvement
s
But does it make it more readable? That's my beef with python and modern JS, where the end of codinglines is a big guess at times πŸ˜‰
p
Yeah, I think it makes it more readable without having a bunch of semicolons at the end of every line sure. I don’t like how python uses a space as a way to designate a loop. I think that goes a little too far.
I don’t use semicolons in my JavaScript either despite what Papa Crawford says
s
Coding is an artform πŸ™‚ I guess we'd be at opposite sides of a wide spectrum of modern art :-D
b
Language designers love semicolons because they remove ambiguity in the parser. Coders, not always so much πŸ™‚
s
Guess I'm a language designer - and I like 2 make sure other developers understand my code without a doubt. For me, semicolons are an integral part of that πŸ˜‰
p
Sometimes people are worried that it might be a logic bomb, but it scares out with a syntax error the first time you try to run the code.