Using expressions with "<" and ">"

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

Fermin
Posts: 149
Joined: Fri Jun 05, 2015 10:44 pm

Using expressions with "<" and ">"

Post by Fermin » Sat Apr 29, 2023 8:53 am

Does anyone know how to force LiveCode to return a string instead of calculating the result when using "<" and ">" and "</" ?
With the PUT command there is no problem, but I need it with ANSWER or RETURN to deliver a result within a routine.

For example:

answer "<" & aaa & ">" & 555 & "</" & aaa & ">"

returns 555, but I want it to return:

<aaa>555</aaa>

Thank you very much.

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Using expressions with "<" and ">"

Post by Klaus » Sat Apr 29, 2023 10:29 am

Hola Fermin,

I'm afraid you can't!
Because this is a "feature" of the answer dialog, if a string starts with < and ends with >
LC will see this as HTML tags and if LC does not know the actual tag(s), it only supports a
very basic set of HTML tags, it will just neglect them.

You could do:
1. Report an enhancement request so we can switch this behavior (interpreting as HTML) on and off
and/or
2. Create your own custom dialog -> a little modal stack with a "OK" button to close the stack.

Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: Using expressions with "<" and ">"

Post by bn » Sat Apr 29, 2023 10:57 am

Hi Fermin,

if you just want to check the syntax you could put it into the message box:

Code: Select all

put "<" & "aaa" & ">" & "555" & "</" & "aaa" & ">" && the long time
(&& the long time added to make sure it is a current message in the message box)

or into a separate field for development

Code: Select all

put "<" & "aaa" & ">" & "555" & "</" & "aaa" & ">" into field "myField"
Kind regards
Bernd

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10078
Joined: Fri Feb 19, 2010 10:17 am

Re: Using expressions with "<" and ">"

Post by richmond62 » Sat Apr 29, 2023 11:26 am

Fake It!
-
SShot 2023-04-29 at 13.25.17.png
Attachments
FAKE IT.livecode.zip
Stack.
(1.07 KiB) Downloaded 207 times

Fermin
Posts: 149
Joined: Fri Jun 05, 2015 10:44 pm

Re: Using expressions with "<" and ">"

Post by Fermin » Sat Apr 29, 2023 4:02 pm

Thank you for your answers. I understand the problem now and will try to find another way to fix it.

As a curiosity:
I presented the problem to ChatGPT and it's clear that it doesn't have any complexes. It may not have any idea what it's saying, but at least it says it with a lot of confidence. :D
Although none of them are useful, here are some of the proposals it has made:

answer quote & "<" & aaa & ">" & 555 & "</" & aaa & ">" & quote
--
answer quote("<" & aaa & ">" & 555 & "</" & aaa & ">")
--
answer "\<" & aaa & "\>" & 555 & "\</" & aaa & "\>"
--
put "<aaa>" & 555 & "</aaa>" into myString
put replaceText(myString, "<", "&lt;") into myString
put replaceText(myString, ">", "&gt;") into myString
answer myString
--

jiml
Posts: 339
Joined: Sat Dec 09, 2006 1:27 am

Re: Using expressions with "<" and ">"

Post by jiml » Sat Apr 29, 2023 5:03 pm

Code: Select all

put "jim" into aaa
put  "<" & aaa & ">" & 555 & "</" & aaa & ">" into fld 1
answer the htmltext of fld 1

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Using expressions with "<" and ">"

Post by dunbarx » Sat Apr 29, 2023 5:31 pm

This is my kind of action.

And if one is going to fake it, at least try to keep it in the ballpark. :wink:

Jimi nailed it, mostly.

Playing around a bit, anyone tell me why:

Code: Select all

   put  "<" & "aaa" & ">" & 555 & "</" & "aaa" & ">" into fld 1
   answer the htmlText of fld 1
works, but this, which seems to me pretty much the same, does not:

Code: Select all

 put  "<" & "aaa" & ">" & 555 & "</" & "aaa" & ">" into temp
   answer the htmlText of temp
Both a field and a variable are a container. So a field must have "properties" that a variable does not, especially when dealing with text, or in this case, htmlText. This is my kind of action because this is an instance where I see that "container" is not all-inclusive. That is, there are two kinds of container.

I thought that a "do" construction might work on the variable version, but it does not seem to. There is something besides inadequate levels of evaluation that a field does with text that a variable does not.

Craig

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

Re: Using expressions with "<" and ">"

Post by mwieder » Sat Apr 29, 2023 5:38 pm

Craig-

Variables don't have "properties", so "the htmlText of" a variable doesn't exist.
You can set and retrieve the htmlText of a field because it's a property you can manipulate.
A variable is just a container for a value, nothing more or less.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Using expressions with "<" and ">"

Post by dunbarx » Sat Apr 29, 2023 5:42 pm

I had little hope for this, but had to try:

Code: Select all

put  "<" & "aaa" & ">" & 555 & "</" & "aaa" & ">" into fld 1
   put fld 1 into temp
   answer the htmlText of temp
Nope.

So placing the text string into a field and then into a variable did not "format" the string in any way, or at least whatever "advantages" or "differences" the string had by virtue of living in a field were lost when transferring to a variable.

What is different when extracting "the htmlText" from a field rather than from a variable?

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Using expressions with "<" and ">"

Post by dunbarx » Sat Apr 29, 2023 5:48 pm

Mark.

What threw me was I read the construction of the string itself as "containing" the htmlText information intrinsically. Not so.

I guess that makes sense. So conceptually, for me always a challenge, the string "inherits" the htmlText property from a field. The string is always just a string.There are indeed more than one "kind" of container, in that there are different properties among containers. Variables have a text properly, as does a field, but not an htmlText property.

Just thinking out loud...

OK, I feel better. Thanks.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Using expressions with "<" and ">"

Post by jacque » Sun Apr 30, 2023 6:30 am

The original didn't work for me, but there was a syntax error in the html. I removed the slash from "</" just before the second instance of "aaa". This works for me:

answer "<" & aaa & ">" & 555 & "<" & aaa & ">"
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Using expressions with "<" and ">"

Post by dunbarx » Sun Apr 30, 2023 3:12 pm

Jacque.

Good find. I don't use HTML so I never would have known it was wrong.

But Klaus, how does this play into what you said, about "answer" dialogs being very particular about html-formatted strings?

Craig

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Using expressions with "<" and ">"

Post by Klaus » Sun Apr 30, 2023 4:34 pm

Maybe i was not very precise in what I said:
... if a string starts with < and ends with >
should read ... and ends with a HTML end tag -> </xxx> (remember that LC first resolves the complete string)
then:
LC will see this as HTML tags and if LC does not know the actual tag(s), it only supports a
very basic set of HTML tags, it will just neglect them.
Or just treat it like a pair of <p> and </p>, at least LC presumes this to be HTML, no matter if
you "don't use HTML". :-D

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7389
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Using expressions with "<" and ">"

Post by jacque » Sun Apr 30, 2023 6:22 pm

I wouldn't have caught the error either if I hadn't got an error message when testing it using "do" which also didn't work. The dictionary says:
The prompt can be either formatted text (in the htmlText property's format) or plain text. If the prompt contains <p> or a start/end tag pair, the answer command assumes the text is in the same format as the htmlText property. Otherwise, the answer command assumes the text is plain text.
The </ was used as a tag opener, which is wrong, it's an end designator. So I assume that was the error. But that doesn't explain why LC didn't see the prompt as html after the fix, because after the fix it still is.

I know that concatenation turns text into plain strings, but then why did the original example not stay as a string? It did have a legitimate tag ooen/close pair. Curious.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Using expressions with "<" and ">"

Post by FourthWorld » Sun Apr 30, 2023 8:30 pm

IIRC the original rule for LC to treat Ask and Answer prompts as htmlText was to require what all htmlText has: "<p>" at the beginning and "</p>" at the end.

Resuming that rule would allow other uses.

If the rule has not formally changed perhaps this is a bug.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply