Arrays: new and old keys, i

David Bovill david at vaudevillecourt.tv
Sun Sep 14 12:52:14 EDT 2008


2008/9/14 Richard Gaskin <ambassador at fourthworld.com>

>
>  put tMyData[5] into tMySnippetA
>  put tMySnippetA["title"]
>  put tMySnippetA["body"]
>
> Are there cases where putting your arrays inside of ordinal wrapper arrays
> would be problematic?


Most of the time I don't want the complexity - the order I like best is an
implicit one, that's what's great about writing Transcript like:

repeat for each item title in "Summary,Description,See Also,References"
  -- do something to that section
end repeat

I don't want to remember or deal with the fact that "Description" is the
second header. When I want the content I want to:

put documentArray ["Description"] into someUtf16

and when I want to update the content:

put the unidicodetext of fld "Description" into  documentArray
["Description"]

I don't want to have to remember and write stuff like:

 put documentArray [2]["Description"] into someUtf16

Now taking Colins example:

put "books,dvds,cds,records,cassettes,xbox games,playstation games,wi
games,cd-roms" into titles
repeat for each item title in titles
     get documentArray [title]
     if it is not empty then
         -- do something like present the data
         addParaToDisplay title, it

         -- or process it and put it into another array
         put makeSuggestions(title, documentArray) into geniusArray [title]
     end if
end repeat

-- present new document
display_Document geniusArray


Now in the entire script I do not have to refer to anything except by its
"common sense reference" - the title. The order is implicit in the fact that
you are processing the list or document in a logical order - the order of
presentation of the data. Now this script fails at the moment when I want to
display the new document, because I can't get the order of the titles out of
"geniusArray" - so I'd have to also pass the ordered list "titles".

This is all great - I can use whatever I want for the titles - more or less
- even html - I can have imaes and unicode as content if I want, and
refering to section in a document by the actual title is great for fast
intuitive coding. OK for more abstract and robust things where you worry
about repeat sectons and translated titles it may be good to refer to things
by some sort of indexed key - but most of the time you can avoid it, and
just deal with clean simple intuitive syntax of titles. Adding any form of
numeric indexing is just not needed.



More information about the use-livecode mailing list