A string literal passed into a function's parameter is not treated like a string type variable
Root / SmileBASIC Bug Reports / [.]
MZ952Created:
DEF F(A$) A$[0] = "A" RETURN A$ END
DIM TEST$ = "Z" ?F(TEST$) > A
?F("Z") > Type mismatch in 0:2It seems that functions passed string literals, despite appearing to then pass that string literal into a variable, can't manipulate it appropriately. Edit: Don't know if this discussion already exists. If it does, I don't recall it.
I've known about it too for some time. I circumvented it by
DEF F(_A$) DIM A$ = _A$ 'the code uses A$ ENDwhich seems to do the trick without any repercussions later. Not 100% sure, but I'm pretty sure that A$ does not reference _A$, or else it would be referencing the read-only type and erroring all the same. Edit: actually, this would make sense. If you consider _A$ as a placeholder for "Z", then DIM A$ = _A$ is the same as DIM A$ = "Z", and thus it doesn't reference.
If the function doesn't end with (), then a value set will always be reverted unless if the value is inside an arrayAnything set inside a function that doesn't output stuff revert to the previous value when the function is ended unless it's an array value. I thought this was common knowledge for SB coders...I don't follow.
Okay.If the function doesn't end with (), then a value set will always be reverted unless if the value is inside an arrayThe function does end with () though. Edit: The dilemma isn't one about reverted values, it's about how SB handles string literals as a function parameter.
in mind
What the heck is a string literal or a function parameterHere's another annoying thing
DEF F(A$[]) PUSH A$, "A" RETURN A$ END DIM TEST$[0] COPY TEST$, F(TEST$) ?LEN(TEST$) > 1 ?LEN(TEST$[0]) > 0 ?TEST$[0] > {empty string}Now, look at this
'same DEF function DIM TEST$[0] ?LEN(F(TEST$)) > 1 ?LEN(F(TEST$)[0]) > 1 ?F(TEST$)[0] > AFunctions don't like returning one of their input variables. Like the other issue of this post's namesake, this is solved by
DEF F(_A$[]) DIM A$[0] COPY A$, _A$ 'the code uses A$ ENDMore specifically, it doesn't like returning one of its input variables into the original input variable, but it does return the correct array if you read from the function directly.