Page 1 of 1

Quotes in constants - tell me I'm wrong …

Posted: Sat Dec 31, 2022 1:02 pm
by Fjord
Hi,
I'm parsing HTML and I've got several strings that act as patterns, like

Code: Select all

put "</table" into laCleFinTable
of course this could be a constant; actually, it should be a constant:

Code: Select all

constant laCleFinTable =  "</table"
But I have also

Code: Select all

put "<table class="&quote&"table table2"&quote&" id="&quote&"partants_table_" into laCleDebutTable
and this can't be a constant because it embeds quotes. I couldn't find a way to embed a quote within a string without using the & operator. And constants can't embed any operator.
Did I get it correctly? or is there a way to write a string constant containing quotes?

BTW, some languages allow you to write constants like:

Code: Select all

constant laCleDebutTable = "<table class=\"table table2\" id=\"partants_table_" -- see example above
constant ten = 2*5 -- kind of silly, of course
constant pi = arcCos(-1) -- not as silly as it seems
a constant being just something that is evaluated only once, probably by the compiler, or at the beginning of the handler or sub.

Re: Quotes in constants - tell me I'm wrong …

Posted: Sun Jan 01, 2023 5:26 am
by mwieder
Yes, it's unfortunately a LiveCode limitation.
There's a long-standing bug report/enhancement request to allow single quotes, which would help alleviate this problem.
Constants will soon (fingers crossed) more flexible in what they allow as expressions.

For now I create fake constants

Code: Select all

local kFakeConstant

put "<table class="&quote&"table table2"&quote&" id="&quote&"partants_table_" into kFakeConstant

# and then use the fake constant afterwards as if it were a real constant.
put kFakeConstant into laCleDebutTable
Another solution is to use custom properties of a stack or control

Code: Select all

set the fakeConstant of this stack to "<table class="&quote&"table table2"&quote&" id="&quote&"partants_table_"
put the fakeConstant of this stack into laCleDebutTable

Re: Quotes in constants - tell me I'm wrong …

Posted: Sun Jan 01, 2023 11:34 am
by Fjord
… I was wondering if I missed something ; thanks for confirming I did not
:-(
Happy new year to all!! :-D

Re: Quotes in constants - tell me I'm wrong …

Posted: Mon Jan 02, 2023 2:24 pm
by stam
Fjord wrote:
Sat Dec 31, 2022 1:02 pm
and this can't be a constant because it embeds quotes.
It's nothing to do with quotes specifically - it's that you can only have string literals (and no function such as something that returns a double quote) in a constant declaration.
Longstanding limitation and if I'm not mistaken one LC said they would change with upcoming releases to allow functions/operators in constant declarations... Something I'd expect to be changed quite soon...

S.

Re: Quotes in constants - tell me I'm wrong …

Posted: Thu Jan 05, 2023 9:18 pm
by mwieder
I see constant expression evaluation should be in the next release

https://quality.livecode.com/show_bug.cgi?id=12802