OK. I give up (Word delimiting)

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

OK. I give up (Word delimiting)

Post by dunbarx » Wed Aug 22, 2018 12:05 am

Ah, the beginners section. My favorite.

Consider the following string:
") [L: 250 Lm/ft @ 1.8 W/ft , U: 500 Lm/ft @ 3.6 W/ft] $CKT 1,14,0,156,150,0,81^N,N,N,N%CKT
If I ask for the charToNum of, say, char 3, (or even char 7, or others) of that string, I get "32". A space. There are many such spaces in that string.

If I ask for the number of words in that string. I get "1".

If I prepend, AT THE BEGINNING of the string, something like:
A B C
Where those are ASCII 32 spaces between those chars. I get 4 words. But if I add those chars and spaces in the middle, I get "1".

Why is that?

Craig
Last edited by dunbarx on Thu Aug 23, 2018 9:16 pm, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: OK. I give up

Post by FourthWorld » Wed Aug 22, 2018 1:00 am

HyperCard's definition of "word" does that.

LC now also offers a chunk type better suited for working with quoted text, trueWord.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: OK. I give up

Post by dunbarx » Wed Aug 22, 2018 4:11 am

Richard.

Thanks for the reply.

But my point, which you sort of discovered, was that only one quote is required for LC to consider the (enclosed? following?) string to be "in quotes"

This is one word:
"One quote at the beginning of this string
I thought it had to be:
"Two quotes bracketing this string"
Is this just something I never knew, but everyone else did? I had the devil of a time trying to figure out why a handler was not working; the string I was parsing had but a single quote embedded, and all the "words" that followed were but a single word.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: OK. I give up

Post by FourthWorld » Wed Aug 22, 2018 5:14 am

I was on my phone earlier and didn't notice that it has no closing quote.

I just tested here and I get "2" for the number of words.

But if I move the quote to any position after the first it says "21".

Maybe file a bug report?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: OK. I give up

Post by MaxV » Wed Aug 22, 2018 1:21 pm

It's documented: https://livecode.wikia.com/wiki/Word
A word is delimited by one or more spaces, tabs, or returns, or enclosed by double quotes. A single word can contain multiple characters and multiple items, but not multiple lines.

Words are delimited by double quotes ("), but not by curved (curly) quotes (“ ”). LiveCode does not treat curved quotes as quotes.
I tested this:

Code: Select all

put quote & ") [L: 250 Lm/ft @ 1.8 W/ft , U: 500 Lm/ft @ 3.6 W/ft] $CKT 1,14,0,156,150,0,81^N,N,N,N%CKT"  into temp
put the number of words of temp
And I get 1 on Linux
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: OK. I give up

Post by bogs » Wed Aug 22, 2018 1:56 pm

dunbarx wrote:
Wed Aug 22, 2018 4:11 am
Is this just something I never knew, but everyone else did?
Well, I didn't know either, thanks for bringing it up.
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: OK. I give up

Post by FourthWorld » Wed Aug 22, 2018 2:01 pm

"Enclosed by double quotes" suggests there must be a trailing double quote character. The example here does not have one.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: OK. I give up

Post by MaxV » Wed Aug 22, 2018 2:26 pm

FourthWorld wrote:
Wed Aug 22, 2018 2:01 pm
"Enclosed by double quotes" suggests there must be a trailing double quote character. The example here does not have one.

Code: Select all

put quote & "Hello world" & quote & " I'm Max" into temp
put the number of words of temp
= 3

Code: Select all

put quote & "Hello world" & quote & quote & " I'm Max" & quote into temp
put the number of words of temp
=2

Code: Select all

put quote & "Hello world" & " I'm Max"  into temp
put the number of words of temp
=1

Code: Select all

put quote & "Hello world" & return & " I'm Max"  into temp
put the number of words of temp
=3

The word counter doesn't count words until a quote is closed by a quote or a new line.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: OK. I give up

Post by FourthWorld » Wed Aug 22, 2018 2:48 pm

There seems to be no dispute about what it does. The question is whether it makes sense.

Anyone have a functioning HyperCard install to see what the Mother Tongue did with a string that begins with a double quote but has no closing quote?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: OK. I give up

Post by bogs » Wed Aug 22, 2018 3:42 pm

FourthWorld wrote:
Wed Aug 22, 2018 2:48 pm
There seems to be no dispute about what it does. The question is whether it makes sense.

Anyone have a functioning HyperCard install to see what the Mother Tongue did with a string that begins with a double quote but has no closing quote?
I have one (what a surprise, I know :P ) If you can tell me what to look for and where to find it, I'd be happy to help :mrgreen:
Image

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: OK. I give up

Post by bogs » Wed Aug 22, 2018 4:42 pm

Alternately, you can go to Archive.org and run the machine there - https://archive.org/details/HyperCardBootSystem7
Image

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: OK. I give up

Post by FourthWorld » Wed Aug 22, 2018 5:04 pm

bogs wrote:
Wed Aug 22, 2018 3:42 pm
FourthWorld wrote:
Wed Aug 22, 2018 2:48 pm
There seems to be no dispute about what it does. The question is whether it makes sense.

Anyone have a functioning HyperCard install to see what the Mother Tongue did with a string that begins with a double quote but has no closing quote?
I have one (what a surprise, I know :P ) If you can tell me what to look for and where to find it, I'd be happy to help :mrgreen:
The recipe provided in the first post would be there best start.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9662
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: OK. I give up

Post by dunbarx » Wed Aug 22, 2018 5:17 pm

HC does the same thing.

Nobody noticed this since 1987.

I Had this come up because I needed to display a number and a quote, to give a length in inches. So a single standAlone quote does have its uses. But when I tried to parse the string that contained that oddity, I was completely defeated until I drilled down to the character level.

At least the dictionary ought to be modified.

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: OK. I give up

Post by FourthWorld » Wed Aug 22, 2018 5:38 pm

How does HC's language guide describe that?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9836
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: OK. I give up

Post by FourthWorld » Wed Aug 22, 2018 5:41 pm

dunbarx wrote:
Wed Aug 22, 2018 5:17 pm
I Had this come up because I needed to display a number and a quote, to give a length in inches. So a single standAlone quote does have its uses. But when I tried to parse the string that contained that oddity, I was completely defeated until I drilled down to the character level.
If you're parsing words you shouldn't need to work that hard. The addition of Unicode brought with it some great natural language savvy giving rise to the new LC chunk type, trueWord.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”