Loading ...
Sorry, an error occurred while loading the content.
 

Re: [Clip] variable variable names and such

Expand Messages
  • David Elliott
    Another neat thing you can do with variables is for array processing. If you have an array of, for example, HTML page names that you may have picked up from a
    Message 1 of 11 , May 8 7:01 AM
      Another neat thing you can do with variables is for array processing.

      If you have an array of, for example, HTML page names that you may
      have picked up from a directory as an array, you could then process
      them one at a time in a loop.

      ;Set delimiter
      ^!SetListDelimiter "|"
      ;Read HTML files
      ^!SetArray %Page%=^$GetFiles(c:\web;*.htm)$
      ;How many files? Variablename0 has the number of elements in the
      array.
      ^%Set %End%=^%Page0%
      :PageLoop
      ^!Set %i%=1
      ^$ChangeFileExt("^%Page^%i%%";"html")$
      ^!Inc %i%
      ^!If ^%i% > ^%End% End
      ^!GoTo PageLoop
      :End

      This technique can be useful for building picklists for dialogue
      boxes as well.

      Better still, you can create 2-dimensional arrays and would then
      access individual "cells" with something like ^%table^%i%^%j%%. It
      can be very powerful and lead to very compact code.

      Have fun experimenting!

      DE
    • Roger Neyman
      ... history and example ... discussion about Perl Three levels or more! Try: ^!Set %z%= z ^!Set %yz%= yz ^!Set
      Message 2 of 11 , May 10 12:21 PM
        --- In ntb-clips@yahoogroups.com, "Alan C." <acumming@c...> wrote:
        > On Thu, 08 May 2003 13:21:33 +1200, Ray Tomes wrote:

        <rpn:snip>history and example</rpn:snip>

        > I tried your clip. NoteTab does do the two levels like as you
        > reported. That got me thinking (if could go to a 3rd level--but no
        > I don't think so due to the third variable's name would lost or no
        > way to retain if wrapped in three instead of wrapped in two like
        > your example.

        <rpn:snip>discussion about Perl</rpn:snip>

        Three levels or more! Try:

        ^!Set %z%="z"
        ^!Set %yz%="yz"
        ^!Set %xyz%="xyz"
        ^!Set %wxyz%="wxyz"
        ^!Set %vwxyz%="->VWXYZ<-"

        ^!Info ^%v^%w^%x^%y^%z%%%%%
      • Alan C.
        ... I tried it. So far I just see a different way to extract (in reference to your info line). Each of the 5 set variables since each is uniquely named via a
        Message 3 of 11 , May 10 7:07 PM
          On Sat, 10 May 2003 19:21:08 -0000, Roger Neyman wrote:
          >--- In ntb-clips@yahoogroups.com, "Alan C." <acumming@c...> wrote:
          >>On Thu, 08 May 2003 13:21:33 +1200, Ray Tomes wrote:
          >
          ><rpn:snip>history and example</rpn:snip>
          >
          >>I tried your clip.  NoteTab does do the two levels like as you
          >>reported.  That got me thinking (if could go to a 3rd level--but no
          >>
          >>I don't think so due to the third variable's name would lost or no
          >>way to retain if wrapped in three instead of wrapped in two like
          >>your example.
          >
          ><rpn:snip>discussion about Perl</rpn:snip>
          >
          >Three levels or more! Try:
          >
          >^!Set %z%="z"
          >^!Set %yz%="yz"
          >^!Set %xyz%="xyz"
          >^!Set %wxyz%="wxyz"
          >^!Set %vwxyz%="->VWXYZ<-"
          >
          >^!Info ^%v^%w^%x^%y^%z%%%%%

          I tried it. So far I just see a different way to extract (in reference to your info line). Each of the 5 set variables since each is uniquely named via a different name for each of the 5, appears to me to be each a different variable.

          ; ^!Info ^%z^%y^%x^%w^%v%%%%%
          ^!Info ^%z%^%yz%^%xyz%

          that displays 3 of the 5 variables.

          Please provide an example or two what can be done with this and/or what purpose ie I need more--I don't yet understand why anyone would want to do that.

          Thanks.

          --
          Alan.
        • Ray Tomes
          ... It is a bit more flexible than using an array as it may cause the use of different arrays or variables under different circumstances, e.g. The following
          Message 4 of 11 , May 10 9:35 PM
            Alan wrote:
            > Please provide an example or two what can be done with this and/or
            > what purpose ie I need more--I don't yet understand why anyone would
            > want to do that.

            It is a bit more flexible than using an array as it may cause the use of
            different arrays or variables under different circumstances, e.g.

            The following calculates the premium for your car insurance based on
            three variables Sex, Age and previous claims. The last line is really
            juicy - I have overdone it! - but it finishes with 4"%" characters. And
            it is reasonably realistic in its calculation.

            The last line uses prev and age to look up either the ac0 or ac1 array
            and combines that result with sex to look up either the female or male
            array and finally that result is an index into the rates array.

            The first 3 lines are the input, the next 5 are the tables and the last
            one does the entire lookup and calculation.

            H="CarIns"
            ^!Set %sex%=^?[Sex==male|female]
            ^!Set %age%=^?[Age==16-24^=1|25-64^=2|65+^=3]
            ^!Set %prev%=^?[Have you had any claims in last 3 years?==no^=0|yes^=1]
            ^!SetArray %ac0%=2;1;2
            ^!SetArray %ac1%=3;2;3
            ^!SetArray %female%=1;2;4
            ^!SetArray %male%=2;3;5
            ^!SetArray %rates%=$300;$400;$600;$850;$950
            ^!InsertText ^%rates^%^%sex%^%ac^%prev%^%age%%%%^p
          • Roger Neyman
            ... no ... I think you have misinterpreted the code... it is as if the successive substitutions are made: ^!Info ^%v^%w^%x^%y^%z%%%%% - ^!Info
            Message 5 of 11 , May 10 10:32 PM
              --- In ntb-clips@yahoogroups.com, "Alan C." <acumming@c...> wrote:
              > On Sat, 10 May 2003 19:21:08 -0000, Roger Neyman wrote:
              > >--- In ntb-clips@yahoogroups.com, "Alan C." <acumming@c...> wrote:
              > >>On Thu, 08 May 2003 13:21:33 +1200, Ray Tomes wrote:
              > >
              > ><rpn:snip>history and example</rpn:snip>
              > >
              > >>I tried your clip.  NoteTab does do the two levels like as you
              > >>reported.  That got me thinking (if could go to a 3rd level--but
              no
              > >>
              > >>I don't think so due to the third variable's name would lost or no
              > >>way to retain if wrapped in three instead of wrapped in two like
              > >>your example.
              > >
              > ><rpn:snip>discussion about Perl</rpn:snip>
              > >
              > >Three levels or more! Try:
              > >
              > >^!Set %z%="z"
              > >^!Set %yz%="yz"
              > >^!Set %xyz%="xyz"
              > >^!Set %wxyz%="wxyz"
              > >^!Set %vwxyz%="->VWXYZ<-"
              > >
              > >^!Info ^%v^%w^%x^%y^%z%%%%%
              >
              > I tried it. So far I just see a different way to extract
              > (in reference to your info line). Each of the 5 set
              > variables since each is uniquely named via a different name
              > for each of the 5, appears to me to be each a different variable.
              >
              > ; ^!Info ^%z^%y^%x^%w^%v%%%%%
              > ^!Info ^%z%^%yz%^%xyz%
              >
              > that displays 3 of the 5 variables.
              >
              I think you have misinterpreted the code... it is as if the
              successive substitutions are made:

              ^!Info ^%v^%w^%x^%y^%z%%%%%
              ->^!Info ^%v^%w^%x^%yz%%%%
              ->^!Info ^%v^%w^%xyz%%%
              ->^!Info ^%v^%wxyz%%
              ->^!Info ^%vwxyz%
              ->^!Info ->VWXYZ<-

              Each of these variables is parsed in turn:
              %z% %yz% %xyz% %wxyz% %vwxyz%

              > Please provide an example or two what can be done with this
              > and/or what purpose ie I need more--I don't yet understand
              > why anyone would want to do that.

              Yes, this is an artifical case constructed just to make the point
              that multiple levels of indirect variable names can be acheived. In
              practice I don't think more than three levels will often be useful,
              but here is an example extracted and simpified from some code I wrote
              today:

              ^!SetArray %rpnJ_key% "Root";"Jexe";"classpath";"cSw";"rSw";"Pkg"
              ;
              ; sometime later, after at least some of the variables
              ; rpnJ_Root, rpnJ_Jexe, etc. have probably been initialized.
              ;
              ^!Set %n%=1
              ^!Set %text%=""
              :ShowLoop
              ^!IfTrue ^$IsEmpty(^%rpnJ_^%rpnJ_key^%n%%%)$ Skip_3
              ^!IfTrue ^$IsEmpty(^%text%)$ Skip
              ^!Set %text%="^%text%^P^P"
              ^!Set %text%="^%text%^%rpnJ_key^%n%% = ^%rpnJ_^%rpnJ_key^%n%%%"
              ^!Inc %n%
              ^!If ^%n%<=^%rpnJ_key0% ShowLoop
              ;
              ^!IfFalse ^$IsEmpty(^%text%)$ Skip
              ^!Set %text%="Uninitialized"
              ^!Info [L]^%text%

              The effect of the code is to put out a line in the ^Info box showing
              the variable name, minus the rpnJ_ prefix, and the value for every
              one of those variables that has been initialized. If none have been,
              just "Uninitialized" is displayed.

              In the second ^!Set command within the loop, first two levels of
              indirection, then three are used, to append something like this to
              the string %text%:

              Jexe = bin\java

              where "bin\java" is the value of %rpnJ_Jexe%

              Hope this clarifies matters.
            • Alan C.
              Hi and thanks Roger and Ray, ok. At least I get the underlying mechanics. Once parsed, what it resolves to is what makes it pick a certain array index. The
              Message 6 of 11 , May 11 2:47 AM
                Hi and thanks Roger and Ray,

                ok. At least I get the underlying mechanics. Once parsed, what it resolves to is what makes it pick a certain array index. The first resolved sets the stage for what's to come. The second resolved is dependent upon the outcome obtained from the first. The third resolved is dependent upon the outcome obtained from the second. A sort of case statement I suppose ie "while moving up the tree, whichever branch I take along the way is dependent upon which of several potential CASES happened at each junction along the way"

                But my brain keeps wanting to short circuit when attempting to set up the needed cases. (I'm VERY visual, nearly gotta somehow see it with my eyes as far as planning, sequencing, etc. little visual puzzle pieces that can shuffle until matched fit or similar)

                Hopefully this is a simpler example. Are there any strategies or method you use to map it out or achieve the cases (control circuitry) that will make it work?

                I need to get it so that from six potential vv (voice value) according to what's chosen, the appropriate one message is printed into a doc

                How do you approach to finish off this clip? Any help appreciated. Thanks.

                H="acplusvar_test"
                ^!Set %arg1%=^?[career==software engineer^=1|writer^=2|ski instructor^=3]
                ^!Set %arg2%=^?[where you live?==lakeside villa^=4|mountain chalet^=5]
                ; ^!SetArray %access1%=

                ^!SetArray %access%=1;3
                ^!SetArray %voice%=vv1;vv2;vv3;vv4;vv5;vv6
                ^!Goto ^%voice^%access^%arg2%^%arg1%%%

                :vv1
                code foreach expands libraries while water skiing
                ^!Goto end
                :vv2
                snow boots and code while or until -gt
                ^!Goto end
                :vv3
                lakeside area writer's penmanship dialog
                ^!Goto end
                :vv4
                ink fresh from upon mountain heights
                ^!Goto end
                :vv5
                6 foot high moguls R fun 2 dream of by the lake
                ^!Goto end
                :vv6
                Mountain Heights Ski instruction presents:^p
                rythm, downhill, carve it, set those edges, keep em parallel
                ;---<end of clip

                --
                Alan.
              • Bob Gorman
                ... Here are 2 examples, I definitely want to build since I use them very often, and want to transfer them from assembler, VB, Logo, etc. into Clip Language.
                Message 7 of 11 , May 11 7:19 AM
                  At 10:07 PM 5/10/2003, you wrote:

                  >Please provide an example or two what can be done with this and/or what
                  >purpose ie I need more--I don't yet understand why anyone would want to do
                  >that.

                  Here are 2 examples, I definitely want to build since I use them very
                  often, and want to transfer them from assembler, VB, Logo, etc. into Clip
                  Language.

                  1. Histogram or character frequency counts:
                  This is similar to the built in statistics function, but counts
                  all characters, even those above 128 Ascii, and below 32, and could
                  eventually be used on binary files. When I'm done I want to put the results
                  into a new document "Results" in one of 2 ways, either sorted in order by
                  Ascii code or sorted by frequency of occurrence.

                  2. Named Multi-dimensional Arrays:
                  I keep many notes in text files in a modified Entity, Attribute,
                  Value format, for example:

                  Function:
                  Name:
                  Purpose:
                  Limits:
                  Syntax:
                  Notes:
                  or
                  Person1:
                  Name: Bob
                  Age: 61
                  Sex: Male
                  Address: ???
                  Phones: ???
                  Home: ???
                  Work: ???
                  Lives in: New Hampshire

                  I want to be able to print out say an address or phone book.
                  e.g. using the age of the 1st person in my knowledge base.
                  ^%Person^%Counter&^%Age%%
                  or
                  ^%Person^%Counter%^%Phone^%Home%%%

                  Since Clip arrays seem to need Numbers rather than Names for indexes, I
                  believe I'll be able to do this by:
                  ^!Set %Name%=1; %Age%=2; %Sex%=3 etc.

                  As I get more comfortable with the Clip commands, functions, and syntax,
                  I'll post my efforts.

                  Bob

                  "To create New Answers; you must ask New Questions."
                  - Bob Gorman
                  http://www.kncell.org

                  [Non-text portions of this message have been removed]
                • Bob Gorman
                  At 05:47 AM 5/11/2003, Alan wrote: ... Me too. I use frequent debug statements during the debugging stage of code development, and later use the same
                  Message 8 of 11 , May 11 8:03 AM
                    At 05:47 AM 5/11/2003, Alan wrote:
                    <snip>
                    >But my brain keeps wanting to short circuit when attempting to set up the
                    >needed cases. (I'm VERY visual, nearly gotta somehow see it with my eyes
                    >as far as planning, sequencing, etc. little visual puzzle pieces that can
                    >shuffle until matched fit or similar)

                    Me too.
                    I use frequent debug statements during the debugging stage of code
                    development, and later use the same statements for a Visual Tutorial to
                    show what's going on as the code runs. These are the kind of Debug & Trace
                    Capabilities that most other languages have built in, and I hope I will be
                    able to create as a Clip Library here in NTP. This is Debugging, Tutoring,
                    and Visualization all happening for the price of one :-)

                    >Hopefully this is a simpler example. Are there any strategies or method
                    >you use to map it out or achieve the cases (control circuitry) that will
                    >make it work?

                    >I need to get it so that from six potential vv (voice value) according to
                    >what's chosen, the appropriate one message is printed into a doc

                    I'm not up to speed enough yet to follow and/or debug your code, but the
                    attached clip shows where I'm at in the learning/debugging stage.

                    >How do you approach to finish off this clip?

                    Short answer:
                    Insert lots of Debug/Tutorial statements!

                    Longer answer:
                    What I'd like to do here is:
                    Start with the Dual Window Display,
                    on the Left - the Target Document - the one I want to analyze,
                    modify, etc.
                    on the Right - a Debug/Tutorial window

                    Both Horizontal & Vertical tiling of the windows would be nice here! :-)

                    Create a function
                    DTPrint
                    ;Stands for Debug/Tutor Print
                    Accepts the rest of the line as input, Like PRINT in BASIC.
                    Switches focus to the end of the Debug Window
                    Inserts the various values.
                    Returns focus to the Target Window

                    Examples:
                    DTPrint Document Name = ^$GetDocName$
                    DTPrint # of lines = ^$GetLineCount$

                    Bob
                    P.S.
                    How does one create a function such as DTPrint?
                    I've tried to make it a separate clip, but couldn't get it to work

                    Then I tried:
                    ^!Set %DTPrint%=^p***^p

                    and call it with
                    ^%DTPrint% ^$GetDocName$

                    but that outputs:
                    ^p***^p NoName01.txt


                    "To create New Answers; you must ask New Questions."
                    - Bob Gorman
                    http://www.kncell.org

                    [Non-text portions of this message have been removed]
                  • Roger Neyman
                    ... You re welcome. background and ruminations ... Here is a clip that does what you re aiming to do, based largely on what you coded:
                    Message 9 of 11 , May 11 8:41 AM
                      --- In ntb-clips@yahoogroups.com, "Alan C." <acumming@c...> wrote:
                      > Hi and thanks Roger and Ray,

                      You're welcome.

                      <RPN:/snip>background and ruminations</RPN:snip>

                      > How do you approach to finish off this clip?

                      Here is a clip that does what you're aiming to do, based largely on
                      what you coded:

                      H="acplusvar_test1"

                      ^!Set %arg1%=^?[career==software engineer^=0|writer^=1|ski
                      instructor^=2]
                      ^!Set %arg2%=^?[where you live?==lakeside villa^=0|mountain chalet^=1]
                      ; ^!SetArray %access1%=
                      ^!Set %n%=^$Calc(((^%arg1%*2+^%arg2%)+1))$
                      ^!SetArray %access%=1;3
                      ^!SetArray %voice%="vv1";"vv2";"vv3";"vv4";"vv5";"vv6"
                      ^!Goto ^%voice^%n%%

                      :vv1
                      code foreach expands libraries while water skiing
                      ^!Goto end
                      :vv2
                      snow boots and code while or until -gt
                      ^!Goto end
                      :vv3
                      lakeside area writer's penmanship dialog
                      ^!Goto end
                      :vv4
                      ink fresh from upon mountain heights
                      ^!Goto end
                      :vv5
                      6 foot high moguls R fun 2 dream of by the lake
                      ^!Goto end
                      :vv6
                      Mountain Heights Ski instruction presents:^p
                      rythm, downhill, carve it, set those edges, keep em parallel
                      ;---<end of clip

                      The code in the ^!Calc() expression is the way to compute the index
                      in a two dimensional NoteTab array, such as you have set up in your
                      voice array. Note that to make this possible the returned indexes are
                      zero indexed within each array dimension.

                      But you've done a number of things that make your life as a coder
                      harder than it needs to be. Using array element values that end in
                      numbers is less readable than more meaningful and descriptive
                      strings. If you do use numbers, they should reflect the position in
                      the two dimensional array, such as v11, v23, etc. But beyond the
                      naming array for indirection isn't even necessary in this case.

                      It would be if, instead of labels, you put all the text you wanted to
                      output into one way-too-big-to-be-practical two-dimensional array,
                      and just used ^%textArray^%index%% to introduce it into the target
                      document. This wouldn't be easy for multi-line inserts, nor would it
                      be very maintainable.

                      What you want to do could be accomplished more cleanly without arrays
                      as follows:

                      H="acplusvar_test2"
                      ^!Set %c%=^?[career==software engineer^=E|writer^=W|ski instructor^=S]
                      ^!Set %r%=^?[where you live?==lakeside villa^=L|mountain chalet^=M]
                      ^!Goto v^%c%^%r%

                      :vEL
                      code foreach expands libraries while water skiing
                      ^!Goto end
                      :vEM
                      snow boots and code while or until -gt
                      ^!Goto end
                      :vWL
                      lakeside area writer's penmanship dialog
                      ^!Goto end
                      :vWM
                      ink fresh from upon mountain heights
                      ^!Goto end
                      :vSL
                      6 foot high moguls R fun 2 dream of by the lake
                      ^!Goto end
                      :vSM
                      Mountain Heights Ski instruction presents:^p
                      rythm, downhill, carve it, set those edges, keep em parallel
                      ;---<end of clip
                    Your message has been successfully submitted and would be delivered to recipients shortly.