Creating Array - Auto Numeric

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating Array - Auto Numeric

Stephen MacLean via use-livecode
My head always breaks on complex array functions. I can't head around
this algorithm

Given a "quote"  in a field

"Cut the apple. Cut the banana"

We get to location for each word (that is easy)

I want to analyse the quote by going through each word.

*----------*

*repeat* withx = 1tothenumberofwordsoffld"_quote"

    # get the location of the word, put it into variable tWordLocation

    put tWordLocation to the WordLocationA[x][??][tWordLocation]

end repeat

-------

that we end with

WordLocationA["Cut"][1][100,320]
WordLocationA["Cut"][2][300,320]
WordLocationA["the"][1][200,320]
WordLocationA["the"][2][400,320]
WordLocationA["apple"][2][500,320]
WordLocationA["banana"][2][500,320]

the "part" where incrementing the numeric key inside the repeat loop,
"inside" the key,  I can't get.

BR







_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
Hi.

Is this what you want?

on mouseUp
   repeat with y = 1 to the number of words of fld 1
      select word y of fld 1
      put the selectedLoc into wordLocationA[y][word y of fld 1]
   end repeat
end mouseUp

I suspect not. Is it that you want the output to be:

WordLocationA["Cut"][100,320]
WordLocationA["the"][1][200,320]
WordLocationA["apple"][500,320]
WordLocationA["Cut"][300,320]
WordLocationA["the"][400,320]
WordLocationA["banana"][500,320]

If so, why use an array? Just:

on mouseUp
   repeat with y = 1 to the number of words of fld 1
      select word y of fld 1
      put word y of fld 1 &","& the selectedLoc & return after locList
   end repeat
end mouseUp

Craig Newman




--
Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
In reply to this post by Stephen MacLean via use-livecode
Also, be careful. The string:

"Cut the apple. Cut the banana"

contains only one word.

Craig



--
Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
Hi Craig,

> Am 18.09.2018 um 18:47 schrieb dunbarxx via use-livecode <[hidden email]>:
>
> Also, be careful. The string:
> "Cut the apple. Cut the banana"
> contains only one word.

true, but also contains 6 TRUEWORDS! :-)

> Craig

Best

Klaus

--
Klaus Major
http://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
In reply to this post by Stephen MacLean via use-livecode
You can not put the incrementing numeric key inside an associative array the way you want. The key of any array must be unique, and you can not have several instances of a key in an array. Think of the keys of the array it as the primary keys of a database table. It serves as a unique identifier.

Best regards
Tore Nilsen





> 18. sep. 2018 kl. 17:41 skrev Sannyasin Brahmanathaswami via use-livecode <[hidden email]>:
>
> My head always breaks on complex array functions. I can't head around
> this algorithm
>
> Given a "quote"  in a field
>
> "Cut the apple. Cut the banana"
>
> We get to location for each word (that is easy)
>
> I want to analyse the quote by going through each word.
>
> *----------*
>
> *repeat* withx = 1tothenumberofwordsoffld"_quote"
>
>    # get the location of the word, put it into variable tWordLocation
>
>    put tWordLocation to the WordLocationA[x][??][tWordLocation]
>
> end repeat
>
> -------
>
> that we end with
>
> WordLocationA["Cut"][1][100,320]
> WordLocationA["Cut"][2][300,320]
> WordLocationA["the"][1][200,320]
> WordLocationA["the"][2][400,320]
> WordLocationA["apple"][2][500,320]
> WordLocationA["banana"][2][500,320]
>
> the "part" where incrementing the numeric key inside the repeat loop,
> "inside" the key,  I can't get.
>
> BR
>
>
>
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
On 9/18/18 7:15 AM, Tore Nilsen via use-livecode wrote:
> You can not put the incrementing numeric key inside an associative array the way you want. The key of any array must be unique, and you can not have several instances of a key in an array. Think of the keys of the array it as the primary keys of a database table. It serves as a unique identifier.
>
> Best regards
> Tore Nilsen



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
In reply to this post by Stephen MacLean via use-livecode
On 9/18/18 10:41 AM, Sannyasin Brahmanathaswami via use-livecode wrote:

> I want to analyse the quote by going through each word.
>
> *----------*
>
> *repeat*  withx = 1tothenumberofwordsoffld"_quote"
>
>      # get the location of the word, put it into variable tWordLocation
>
>      put tWordLocation to the WordLocationA[x][??][tWordLocation]
>
> end repeat
>
> -------
>
> that we end with
>
> WordLocationA["Cut"][1][100,320]
> WordLocationA["Cut"][2][300,320]
> WordLocationA["the"][1][200,320]
> WordLocationA["the"][2][400,320]
> WordLocationA["apple"][2][500,320]
> WordLocationA["banana"][2][500,320]

I think this will get you close:

   put fld 1 into tQuote
   repeat with x = 1 to the number of truewords in tQuote
     put tWordLocation into tWordLocationA[trueword x of
tQuote][x][tWordLocation]
   end repeat

You could count word instances incrementally with more scripting, but
this short way gives you something similar. It stores the word position
to get this:

tWordLocationA["Cut"][1][100,320]
tWordLocationA["Cut"][4][300,320]
tWordLocationA["the"][2][200,320]
tWordLocationA["the"][5][400,320]
tWordLocationA["apple"][3][500,320]
tWordLocationA["banana"][6][500,320]

If you do want an incremental word count, check the number of elements
in each array key and add 1 to it instead of using "x" as the counter
when filling the array.

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
In reply to this post by Stephen MacLean via use-livecode
Tore, must be talking about different things.

fld "tQuote" =

Cut the apple. Cut the banana.


I CAN manually create what we need

*on*mouseup

*    put*"100,320"intoWordLocationsA["Cut"][1]

*    put*"300,320"intoWordLocationsA["Cut"][2]

*    put*"200,320"intoWordLocationsA["the"][1]

*    put*"400,320"intoWordLocationsA["the"][2]

*    put*"500,320"intoWordLocationsA["apple"][1]

*    put*"700,320"intoWordLocationsA["banana"][1]

*    put*thekeysofWordLocationsA

*end*mouseup


Craig has almost got it


*on*mouseUp

*    repeat* withy = 1tothenumberofwordsoffld"tQuote"

*        put*wordy offld"tQuote"intotWord

*        select*wordy offldtQuote

*        put*theselectedLocintowordLocationA[tWord][x]

*    end* *repeat*

*end*mouseUp

# how to get "x" to increment? but only by each key in the array?

*on*mouseup

*    repeat* withy = 1tothenumberofwordsoffld"tQuote"

*        select*wordy offld"tQuote"

*        put*wordy offld"tQuote"&"|"& theselectedLoc& crafterwordLocationsA

*    end* *repeat*

*    delete*char-1 ofwordLocationsA

*    split*wordLocationsA bycrand"|"

*    put*thekeysofwordLocationsA intofld"result"

*end*mouseUp

#only on location is saved (of course)







On 9/18/18 7:15 AM, Tore Nilsen via use-livecode wrote:

> You can not put the incrementing numeric key inside an associative array the way you want. The key of any array must be unique, and you can not have several instances of a key in an array. Think of the keys of the array it as the primary keys of a database table. It serves as a unique identifier.
>
> Best regards
> Tore Nilsen
>
>
>
>
>
>> 18. sep. 2018 kl. 17:41 skrev Sannyasin Brahmanathaswami via use-livecode <[hidden email]>:
>>
>> My head always breaks on complex array functions. I can't head around
>> this algorithm
>>
>> Given a "quote"  in a field
>>
>> "Cut the apple. Cut the banana"
>>
>> We get to location for each word (that is easy)
>>
>> I want to analyse the quote by going through each word.
>>
>> *----------*
>>
>> *repeat* withx = 1tothenumberofwordsoffld"_quote"
>>
>>    # get the location of the word, put it into variable tWordLocation
>>
>>    put tWordLocation to the WordLocationA[x][??][tWordLocation]
>>
>> end repeat
>>
>> -------
>>
>> that we end with
>>
>> WordLocationA["Cut"][1][100,320]
>> WordLocationA["Cut"][2][300,320]
>> WordLocationA["the"][1][200,320]
>> WordLocationA["the"][2][400,320]
>> WordLocationA["apple"][2][500,320]
>> WordLocationA["banana"][2][500,320]
>>
>> the "part" where incrementing the numeric key inside the repeat loop,
>> "inside" the key,  I can't get.
>>
>> BR
>>
>>
>>
>>
>>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode

We are not talking about different things, but the same thing from different angles. I misinterpreted what you wanted to do from your example. What you do manually is creating an associative array with a numeric array as the values for each key in the associative array, which should work well. I should learn to read before I write, just as I should learn to listen for the questions before I give the answers. My students have told me as much, more than once! :-)


Best Regards
Tore







> 19. sep. 2018 kl. 00:01 skrev Sannyasin Brahmanathaswami via use-livecode <[hidden email]>:
>
> Tore, must be talking about different things.
>
> fld "tQuote" =
>
> Cut the apple. Cut the banana.
>
>
> I CAN manually create what we need
>
> *on*mouseup
>
> *    put*"100,320"intoWordLocationsA["Cut"][1]
>
> *    put*"300,320"intoWordLocationsA["Cut"][2]
>
> *    put*"200,320"intoWordLocationsA["the"][1]
>
> *    put*"400,320"intoWordLocationsA["the"][2]
>
> *    put*"500,320"intoWordLocationsA["apple"][1]
>
> *    put*"700,320"intoWordLocationsA["banana"][1]
>
> *    put*thekeysofWordLocationsA
>
> *end*mouseup
>
>
> Craig has almost got it
>
>
> *on*mouseUp
>
> *    repeat* withy = 1tothenumberofwordsoffld"tQuote"
>
> *        put*wordy offld"tQuote"intotWord
>
> *        select*wordy offldtQuote
>
> *        put*theselectedLocintowordLocationA[tWord][x]
>
> *    end* *repeat*
>
> *end*mouseUp
>
> # how to get "x" to increment? but only by each key in the array?
>
> *on*mouseup
>
> *    repeat* withy = 1tothenumberofwordsoffld"tQuote"
>
> *        select*wordy offld"tQuote"
>
> *        put*wordy offld"tQuote"&"|"& theselectedLoc& crafterwordLocationsA
>
> *    end* *repeat*
>
> *    delete*char-1 ofwordLocationsA
>
> *    split*wordLocationsA bycrand"|"
>
> *    put*thekeysofwordLocationsA intofld"result"
>
> *end*mouseUp
>
> #only on location is saved (of course)
>
>
>
>
>
>
>
> On 9/18/18 7:15 AM, Tore Nilsen via use-livecode wrote:
>> You can not put the incrementing numeric key inside an associative array the way you want. The key of any array must be unique, and you can not have several instances of a key in an array. Think of the keys of the array it as the primary keys of a database table. It serves as a unique identifier.
>>
>> Best regards
>> Tore Nilsen
>>
>>
>>
>>
>>
>>> 18. sep. 2018 kl. 17:41 skrev Sannyasin Brahmanathaswami via use-livecode <[hidden email]>:
>>>
>>> My head always breaks on complex array functions. I can't head around
>>> this algorithm
>>>
>>> Given a "quote"  in a field
>>>
>>> "Cut the apple. Cut the banana"
>>>
>>> We get to location for each word (that is easy)
>>>
>>> I want to analyse the quote by going through each word.
>>>
>>> *----------*
>>>
>>> *repeat* withx = 1tothenumberofwordsoffld"_quote"
>>>
>>>   # get the location of the word, put it into variable tWordLocation
>>>
>>>   put tWordLocation to the WordLocationA[x][??][tWordLocation]
>>>
>>> end repeat
>>>
>>> -------
>>>
>>> that we end with
>>>
>>> WordLocationA["Cut"][1][100,320]
>>> WordLocationA["Cut"][2][300,320]
>>> WordLocationA["the"][1][200,320]
>>> WordLocationA["the"][2][400,320]
>>> WordLocationA["apple"][2][500,320]
>>> WordLocationA["banana"][2][500,320]
>>>
>>> the "part" where incrementing the numeric key inside the repeat loop,
>>> "inside" the key,  I can't get.
>>>
>>> BR
>>>
>>>
>>>
>>>
>>>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
In reply to this post by Stephen MacLean via use-livecode
On 9/18/18 5:01 PM, Sannyasin Brahmanathaswami via use-livecode wrote:
> # how to get "x" to increment? but only by each key in the array?

Okay, try this:

   put fld 1 into tQuote
   repeat with x = 1 to the number of truewords in tQuote
     put the number of lines in keys(tWordLocationA[trueword x of
tQuote])+1 into tNum
     put tWordLocation into tWordLocationA[trueword x of
tQuote][tNum][tWordLocation]
   end repeat

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
or,


    repeat for each trueword X in tQuote
       put (item 2 of the extents of tWordLocationA[X]) + 1 into t1
       put tWordLocation into tWordLocationA[X][t1]
    end repeat

Alex


On 18/09/2018 23:57, J. Landman Gay via use-livecode wrote:

> On 9/18/18 5:01 PM, Sannyasin Brahmanathaswami via use-livecode wrote:
>> # how to get "x" to increment? but only by each key in the array?
>
> Okay, try this:
>
>   put fld 1 into tQuote
>   repeat with x = 1 to the number of truewords in tQuote
>     put the number of lines in keys(tWordLocationA[trueword x of
> tQuote])+1 into tNum
>     put tWordLocation into tWordLocationA[trueword x of
> tQuote][tNum][tWordLocation]
>   end repeat
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
In reply to this post by Stephen MacLean via use-livecode
When solving a problem with a given data structure makes your head hurt,
that may be an indication that your head's fine and the problem is with
the data structure. :)

Can you tell us a bit more about your goal with this?

In your example output, if we look at this line:

    WordLocationA["Cut"][1][100,320]

What do these numbers signify?

And what will you be doing with this index once you have it?

--
  Richard Gaskin
  Fourth World Systems


Sannyasin Brahmanathaswami wrote:

 > My head always breaks on complex array functions. I can't head around
 > this algorithm
 >
 > Given a "quote"  in a field
 >
 > "Cut the apple. Cut the banana"
 >
 > We get to location for each word (that is easy)
 >
 > I want to analyse the quote by going through each word.
 >
 > *----------*
 >
 > *repeat* withx = 1tothenumberofwordsoffld"_quote"
 >
 >     # get the location of the word, put it into variable tWordLocation
 >
 >     put tWordLocation to the WordLocationA[x][??][tWordLocation]
 >
 > end repeat
 >
 > -------
 >
 > that we end with
 >
 > WordLocationA["Cut"][1][100,320]
 > WordLocationA["Cut"][2][300,320]
 > WordLocationA["the"][1][200,320]
 > WordLocationA["the"][2][400,320]
 > WordLocationA["apple"][2][500,320]
 > WordLocationA["banana"][2][500,320]
 >
 > the "part" where incrementing the numeric key inside the repeat loop,
 > "inside" the key,  I can't get.



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
Well Alex won with "extents"

in fact while he wrote that, I was in the User look at extents.'



Jacque does that some thing..

  put the number of lines in keys

USE CASE

Jacque and created a puzzle together, it take quotes of various lengths,
creates image tiles of the words. Each tile has a customprop "uHomeLoc"
that has the location where it wants to be placed. It uHome is set to false.
 The user drags the tile.
Close to home it snaps into place and its "uHome" is set true. It cannot move anter that.  

That problem is a sentence having say "and" three times.
 
Each "and" can only "go home" in one location.
This is frustrating to users.

Say we need to tell this tile  "and" that "any one of these location will serve as home"
 
I may end up switch to jacque model, which is to make "tile" be little fields,
 one of each word.

But I use can the code for  "images as tile"  for to another game,
which is putting picture together.

BR


On 9/18/18 3:49 PM, Richard Gaskin via use-livecode wrote:

> When solving a problem with a given data structure makes your head hurt,
> that may be an indication that your head's fine and the problem is with
> the data structure. :)
>
> Can you tell us a bit more about your goal with this?
>
> In your example output, if we look at this line:
>
>     WordLocationA["Cut"][1][100,320]
>
> What do these numbers signify?
>
> And what will you be doing with this index once you have it?


--
Svasti Astu, Be Well!
Brahmanathaswami
 
Get the SivaSiva app, it's free:
https://www.himalayanacademy.com/apps/sivasiva


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
I always forget about "extents". I like concise code, Alex wins. :)


--
Jacqueline Landman Gay | [hidden email]
HyperActive Software | http://www.hyperactivesw.com
On September 18, 2018 9:25:02 PM Sannyasin Brahmanathaswami via
use-livecode <[hidden email]> wrote:

> Well Alex won with "extents"



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
In reply to this post by Stephen MacLean via use-livecode
I was going to say something similar, but thought better of it. Sometimes you need to step back and ask yourself, "What exactly am I trying to do here", or a better question is, "How do I get from where I am to where I want to be (in terms of the data) with the least amount of fuss?"

Bob S


> On Sep 18, 2018, at 18:48 , Richard Gaskin via use-livecode <[hidden email]> wrote:
>
> When solving a problem with a given data structure makes your head hurt, that may be an indication that your head's fine and the problem is with the data structure. :)


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Creating Array - Auto Numeric

Stephen MacLean via use-livecode
It my case it was "ignorance about arrays" that may my head hurt.

It would nice if the dictionary's "associations" include every keyword
related.

For example, search on array"

One find zero reference to

extents

But I found them the user guide
1) Chapter on Arrays
2) Section on Processing Text and Data
    -- using arrays we can find out about:

combine
intersects
add
delete variable
divide
keys
element
matrix multiply
split
sum
tranpose
union

to keep it simple those could "Related" under

Associative Array.

( If there lesson on how to contribute to the dictionary?)

On 9/19/18 1:15 PM, Bob Sneidar via use-livecode wrote:
> I was going to say something similar, but thought better of it. Sometimes you need to step back and ask yourself, "What exactly am I trying to do here", or a better question is, "How do I get from where I am to where I want to be (in terms of the data) with the least amount of fuss?"
>
> Bob S
>
>
>> On Sep 18, 2018, at 18:48 , Richard Gaskin via use-livecode <[hidden email]> wrote:
>>
>> When solving a problem with a given data structure makes your head hurt, that may be an indication that your head's fine and the problem is with the data structure. :)


--
Svasti Astu, Be Well!
Brahmanathaswami
 
Get the SivaSiva app, it's free:
https://www.himalayanacademy.com/apps/sivasiva


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode