Page 1 of 3
OK. I give up (Word delimiting)
Posted: Wed Aug 22, 2018 12:05 am
by dunbarx
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
Re: OK. I give up
Posted: Wed Aug 22, 2018 1:00 am
by FourthWorld
HyperCard's definition of "word" does that.
LC now also offers a chunk type better suited for working with quoted text, trueWord.
Re: OK. I give up
Posted: Wed Aug 22, 2018 4:11 am
by dunbarx
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
Re: OK. I give up
Posted: Wed Aug 22, 2018 5:14 am
by FourthWorld
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?
Re: OK. I give up
Posted: Wed Aug 22, 2018 1:21 pm
by MaxV
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
Re: OK. I give up
Posted: Wed Aug 22, 2018 1:56 pm
by bogs
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.
Re: OK. I give up
Posted: Wed Aug 22, 2018 2:01 pm
by FourthWorld
"Enclosed by double quotes" suggests there must be a trailing double quote character. The example here does not have one.
Re: OK. I give up
Posted: Wed Aug 22, 2018 2:26 pm
by MaxV
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.
Re: OK. I give up
Posted: Wed Aug 22, 2018 2:48 pm
by FourthWorld
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?
Re: OK. I give up
Posted: Wed Aug 22, 2018 3:42 pm
by bogs
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

) If you can tell me what to look for and where to find it, I'd be happy to help

Re: OK. I give up
Posted: Wed Aug 22, 2018 4:42 pm
by bogs
Alternately, you can go to Archive.org and run the machine there -
https://archive.org/details/HyperCardBootSystem7
Re: OK. I give up
Posted: Wed Aug 22, 2018 5:04 pm
by FourthWorld
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

) If you can tell me what to look for and where to find it, I'd be happy to help
The recipe provided in the first post would be there best start.
Re: OK. I give up
Posted: Wed Aug 22, 2018 5:17 pm
by dunbarx
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
Re: OK. I give up
Posted: Wed Aug 22, 2018 5:38 pm
by FourthWorld
How does HC's language guide describe that?
Re: OK. I give up
Posted: Wed Aug 22, 2018 5:41 pm
by FourthWorld
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.