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

14981Re: Understanding Writing Subroutines

Expand Messages
  • rpdooling
    Apr 15, 2006
    • 0 Attachment
      All I'm saying is, why not have NoteTab run a single Python script
      that fits on two lines:

      t = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
      for color in t: print color[0],

      >>r o y g b i v

      Instead of having NoteTab run two clips worth of code:

      H="first letter"
      ;set variables to be passed as parameters
      ^!SetArray %items%=red;orange;yellow;green;blue;indigo;violet
      ;call "subroutine"
      ^!Clip "grabfirstletters"
      ^!SetArray %items%=Mediocrity;Ego;Limits;Vanity;Incompetence;Name-calling
      ;call "subroutine"
      ^!Clip "grabfirstletters"

      H="_grabfirstletters"
      ^!Set %count%=1;%string%=""
      :Loop
      ^!Set %string%=^%string%^$StrCopyLeft("^%items^%count%%";1)$
      ^!Inc %count%
      ^!If ^%count% <= ^%items0% Loop
      ^!InsertText ^%string% = ^%items%^P

      And the remark in your last post about portability was off the mark.
      If you write a script in Perl or Python you can run it in NoteTab on
      Windows, in Emacs on Linux, in BBedit on Mac, and so on. That's what's
      commonly called "portability." A clip can only be run in NoteTab.

      Hey, I love NoteTab, too, but it's main attraction is that it's
      extensible far beyond clip code.

      rd


      --- In ntb-clips@yahoogroups.com, "Don - htmlfixit.com" <don@...> wrote:
      >
      > Bob McAllister wrote:
      > > I guess that you could argue it to be "bad form" in some abstract
      > > computer science sense, but it does happen to be how Eric wrote
      > > NoteTab. Have a look at the Custom Functions page in Clip Help where
      > > it is described as "an approach similar to the ^!Clip command".
      > >
      > I didn't realize that this was a custom function. I guess you are
      > correct and that won't go away. I also see what you say about
      passing a
      > parameter.
      >
      > It appears that the only way to pass a parameter is the highlight the
      > "parameter" so the parameter must be in your text document? I remember
      > trying to understand these a while back and thinking that it wasn't
      > worth the effort. Here is how I have taken to using "subroutines" and
      > as you see I am using an array to pass the parameters.
      >
      > H="first letter"
      > ;set variables to be passed as parameters
      > ^!SetArray %items%=red;orange;yellow;green;blue;indigo;violet
      > ;call "subroutine"
      > ^!Clip "grabfirstletters"
      > ^!SetArray
      %items%=Mediocrity;Ego;Limits;Vanity;Incompetence;Name-calling
      > ;call "subroutine"
      > ^!Clip "grabfirstletters"
      >
      >
      > H="_grabfirstletters"
      > ^!Set %count%=1;%string%=""
      > :Loop
      > ^!Set %string%=^%string%^$StrCopyLeft("^%items^%count%%";1)$
      > ^!Inc %count%
      > ^!If ^%count% <= ^%items0% Loop
      > ^!InsertText ^%string% = ^%items%^P
      >
    • Show all 11 messages in this topic