Quotes in constants - tell me I'm wrong …

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Fjord
Posts: 145
Joined: Sat Dec 06, 2008 6:18 pm

Quotes in constants - tell me I'm wrong …

Post by Fjord » Sat Dec 31, 2022 1:02 pm

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.
--
François

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

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

Post by mwieder » Sun Jan 01, 2023 5:26 am

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

Fjord
Posts: 145
Joined: Sat Dec 06, 2008 6:18 pm

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

Post by Fjord » Sun Jan 01, 2023 11:34 am

… I was wondering if I missed something ; thanks for confirming I did not
:-(
Happy new year to all!! :-D
--
François

stam
Posts: 3069
Joined: Sun Jun 04, 2006 9:39 pm

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

Post by stam » Mon Jan 02, 2023 2:24 pm

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.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

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

Post by mwieder » Thu Jan 05, 2023 9:18 pm

I see constant expression evaluation should be in the next release

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

Post Reply