File, variable, array, split

Jan Schenkel janschenkel at yahoo.com
Wed Sep 25 00:30:01 EDT 2002


Hi Toma,

What you're describing could be handled in more than
one manner: 
- by splitting up the data into 2 separate custom
property sets tTranslations and tForms, 
- by tinkering the "key" element so that it has the
form of "<word>+<translation|form>"
- by reading the data from a field into a
2-dimensional array at startup.

If you look at the split command in the Transcript
documentation, you see that it has the form
  split tVariable using return and tab
What this actually does internally, is go over the
contents of the variable and filling up an array.

You could simulate the above "split" operation with
the next piece of code.
  set the itemDelimiter to tab
  put tVariable into tOrigVariable
  repeat for each line tLine in tOrigVariable
    put item 1 of tLine into tMainKey
    put 0 into tSubKey
    repeat for each item tItem of tLine
      add 1 to tSubKey
      put tItem into tVariable[tMainKey, tSubKey]
    end repeat
  end repeat

Now MetaCard/RunRev actually doesn't have _real_
two-dimensional arrays ; it simulates them by
collating the main and sub key.
You can see this easiest by having a look at the keys
of a two-dimensional array variable ; do the above
split with a few simple lines of data and then
  put the keys of tVariable into field "theKeys"

As you will see, the keys look like:
  main1,1
  main1,2
  main1,3
  main2,1
  main2,2
  main2,3
...
This whole explanation is of course a bit simplified,
as it needs to build in safeguards so that there are
no commas in the main key ; but you get the idea.

To return to your particular goal: the easiest
solution is to have two separate custom property sets,
but this brings its own headaches because you have to
maintain two separate sets of data.
Another convenient solution is to let MC/RR handle the
two-dimensional bit by reading the data from a field
and have the engine 'split' it.
Or you can combine the knowledge of how a 'split'
works with keeping everything into a single custom
property set, in which case you will do the collating
of the main and sub key yourself.

Your one-dimensional keys would then look like
  word1+translation
  word1+form
  word2+translation
  word2+form
...
And in this form it can still be tightly packed and
conveniently edited into a single custom property set,
and you can retrieve the information you want with a
simple call like
  put the tWordInfo[(the clickText & "+form")] of \
  this stack into tFormInfo

One final piece of information before I end this
lengthy post: you can have only one custom property
set "active" at one time, but you can still access the
data in other custom property sets at any given time.
  put the someCustomProp of this stack
is internally handled by
  put the customPropertySet into tActiveSet
  put the tActiveSet[someCustomProp] of this stack

All the information in custom properties is neatly
stored away in arrays with the name of the set, and
the name of the property as the key.
You can always access the data of another custom
property set with
  put the uAnInactiveSet[someCustomPropInThatSet] of \
  this stack
And this works, regardless of what is the active set
at that point.

I am well aware that this was a long post with a lot
of information, but I do hope this helped clear a few
things up.
If there are points that aren't clear, I'm sure we can
help you out.

Best regards,

Jan Schenkel.

"As we grow older, we grow both wiser and more foolish
at the same time."  (De Rochefoucald)

--- Toma Tasovac <ttasovac at Princeton.EDU> wrote:
> As I learn from you guys, I get more and more
> ambitious.  Academic career is
> sooooo boring in comparison to this! :)
> 
> Along the same lines of what we've been doing here
> with reading files into
> variables or custom properties and then turning them
> into arrays, what if I
> wanted to have two words associated with each
> clickedWord: i.e. If it's a
> verb, I want to have the clickeWord retunr both its
> infinitive AND the
> translation.
> 
> Arrays can have only one element and one key, as far
> as I get it.  Is the
> only way to do this to create two files (verb +
> infinitive) and
> (verb+translation) and then have two sets of arrays
> (tTranslations, and
> tForms)? 
> 
> Also, if I chose to do it with custom properties --
> I've read somewhere that
> only one set of cutom properties can be active at a
> time...
> 
> I'm stuck again.
> 
> Thanks a lot for you patience with me.
> 
> Toma
> 

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com



More information about the use-livecode mailing list