Alphabeticising a word list?

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

SparkOut
Posts: 2969
Joined: Sun Sep 23, 2007 4:58 pm

Re: Alphabeticising a word list?

Post by SparkOut » Fri Nov 21, 2025 11:18 pm

I suspect that it's going to be something Richmond is trying to generalise for multiple alphabets.

sort international might work for many situations but it uses the system locale

I dare say his system locale is set for a western alphabet, but given that he works with a variety of other writing systems, that isn't necessarily going to be applicable when changing between them in terms of keyboard input and field display.

So *maybe* that's the problem. Maybe there's a solution. I don't even know if (eg) Devanagari has an ordered alphabet.

I guess it must if Richmond is seeking to alphabetically sort it.

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

Re: Alphabeticising a word list?

Post by bn » Sat Nov 22, 2025 10:13 am

SparkOut wrote:
Fri Nov 21, 2025 11:18 pm
I suspect that it's going to be something Richmond is trying to generalise for multiple alphabets.
sort international might work for many situations but it uses the system locale
Devanagari was just an example. The point I was trying to make is that it says that "text" type of sort (implicitely the default) sorts
• text: sorts using a codepoint by codepoint comparison
Maybe a simple sort is enough? But what do I know about higher planes of unicode.

Kind regards
Bernd

scott_morrow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 41
Joined: Tue Jun 27, 2006 8:35 pm
Contact:

Re: Alphabeticising a word list?

Post by scott_morrow » Sat Nov 22, 2025 10:47 am

I'm not entirely certain what Richmond is after but long ago (in SuperCard) before I understood that there was a sort() function, I wrote an alphabetizing handler that worked out the order for any list of arbitrarily long words. It was a short exercise (the long exercise was finding the code from nearly 30 years ago) to add the ability to sort a *custom* alphabet. (It expects to be given text that has one word per line, which I don't believe is what the OP suggested. I will leave chunking out words as an exercise for the reader.) It does require knowing the relative sort order of each char but will work in odd situations like mixing characters from different languages or even using emojis as numbers and letters. WHY anyone would want to do this is the answer to a different question.
Attachments
Alphabetize.livecode.zip
(6.05 KiB) Downloaded 12 times
Elementary Software
...now with 20% less chalk dust!

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

Re: Alphabeticising a word list?

Post by richmond62 » Sat Nov 22, 2025 11:52 am

Thank you very much: I shall give it a 'whirl' shortly.

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

Re: Alphabeticising a word list?

Post by richmond62 » Sat Nov 22, 2025 7:06 pm

Code: Select all

on mouseUp
   sort lines of field 2 ascending text 
end mouseUp

on mouseUp
   put field 2 into tText
   sort tText
   put tText into field 2
end mouseUp
Very funny!

Yes, it does sort the words into some order that is NOT the order of the Devanagari abugida.

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

Re: Alphabeticising a word list?

Post by richmond62 » Sun Nov 23, 2025 4:00 pm

I worked out a comparatively sensible way of doing this without using 'sort' at all and have posted it elsewhere.

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

Re: Alphabeticising a word list?

Post by stam » Sun Nov 23, 2025 7:08 pm

richmond62 wrote:
Sun Nov 23, 2025 4:00 pm
I worked out a comparatively sensible way of doing this without using 'sort' at all and have posted it elsewhere.
OK… but why not post here as well to complete the question you raised here?

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

Re: Alphabeticising a word list?

Post by richmond62 » Sun Nov 23, 2025 7:47 pm

Because the solution was sui generis.

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

Re: Alphabeticising a word list?

Post by stam » Sun Nov 23, 2025 7:55 pm

A unique, non-generalisable sorting algorithm?????

And you thought that others may not benefit from this - because I guess no one has the ability extrapolate to from your unique invention to other situations…

Because we only post generalisable code here of course… right, gotcha…

This is genuinely the last time I’ll ever respond to a post of yours Richmond.

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

Re: Alphabeticising a word list?

Post by richmond62 » Mon Nov 24, 2025 12:49 pm

A unique, non-generalisable sorting algorithm?????
Probably not: but what I worked out in the bath.
Attachments
OBG sorter.livecode.zip
Stack.
(1.91 KiB) Downloaded 6 times

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

Re: Alphabeticising a word list?

Post by dunbarx » Mon Nov 24, 2025 5:29 pm

Richmond.

I rarely see how you approach things. And has this topic morphed into something entirely different?

Anyway, I think I see what you are doing, that is, based on the line ordering of letters in fld "ordure"(I do like how you named that) you are sorting the words in a field of text according that order. But know this needs work. If you change the starting text to "Now is time the for all good men", the two special "T" words are not themselves sorted, but rather appear in the order of the baseline text, which is wrong.

Craig

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

Re: Alphabeticising a word list?

Post by richmond62 » Mon Nov 24, 2025 6:06 pm

the two special "T" words are not themselves sorted
Indeed: you are correct.

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

Re: Alphabeticising a word list?

Post by dunbarx » Mon Nov 24, 2025 8:03 pm

Richmond.

Here is a stack that does (I think) what you want, but with a readable script. :D

And anyway I disliked having to rely on double space as a delimiter, since that way lies madness).

The controlling order of chars ("ST" and then the rest of the alphabet), as per your post (currently "STABCDE...") can be anything if you adjust the contents of fld "Sort Key".

So much fun.

Craig

SortByListContent.livecode.zip
(1.27 KiB) Downloaded 6 times

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

Re: Alphabeticising a word list?

Post by richmond62 » Tue Nov 25, 2025 9:26 am

That is very clever, Thank you.

But:
-
SShot 2025-11-25 at 10.24.33.png
-
What I do NOT understand is when I insert a sort key 'YD' words starting with D are listed before words starting with Y.

Aha: I understand what the problem is:
-
SShot 2025-11-25 at 10.27.21.png
-
When I enter 'TS' I get what I get with 'ST' so it is still imposing English alphabetical order.

That is problematic BOTH for:

1. Sorting English language words in a non-standard order,

and:
-
order.jpg
-
2. For another alphabet [this one is the Old Bulgarian alphabet]; especially as those letters (occurring in both Upper and Lower case forms) do NOT appear sequentially in Unicode.

So, to restate what I am aiming at:

A way to take a list of word in any alphabetic writing system and sort that list in that alphabetic writing system's order.

This does seem to be a tougher call than I had expected.

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

Re: Alphabeticising a word list?

Post by richmond62 » Tue Nov 25, 2025 2:18 pm

I suspect that after I have recovered from a rather nasty bout of 'flu I will return to my stack and try some sort of cyclical stuff to reorder words that start with the same letter also according to my list.

Post Reply