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

Re: [Clip] Notetab Logic Function Clips

Expand Messages
  • Ian NTnerd
    Art, Nice work on the thinking and math to get these working. I m impressed with its power and the math involved. Thanks for the reference in the ^$farfunc.
    Message 1 of 3 , Sep 16, 2013
    • 0 Attachment
      Art,

      Nice work on the thinking and math to get these working. I'm impressed with its power and the math involved.

      Thanks for the reference in the ^$farfunc. :-)          Glad it was useful.

      Ian

      On 16/09/2013 7:05 AM, Art Kocsis wrote:
       

      Here are some of the promised clips implementing the mentioned logic operations:

      Function & Usage      Operation             Clip Function Code
      ===================   ============          ======================
      ^$NOT(A)$               NOT A        <==>   (A + 1) MOD 2
      ^$XOR(A;B)$           A AND B        <==>   A * B
      ^$OR(A;B[;C...])$     A OR  B        <==>   MAX (A, B)
      ^$AND(A;B[;C...])$    A XOR B        <==>   (A + B) MOD 2
      ^$NXOR(A;B)$          NOT A AND B    <==>   (MIN (A, B) + 1) MOD 2
      ^$NOR(A;B)$           NOT A OR  B    <==>   (MAX (A, B) + 1) MOD 2
      ^$NAND(A;B)$          NOT A XOR B    <==>   (A + B + 1) MOD 2

      The output of these functions is guaranteed to be zero or one {0,1}.
      However, I removed that restriction from the inputs.

      Notetab defines True as  1, TRUE, YES, Y, or ON (case insensitive)
                  and False as 0, FALSE, NO, N, or OFF (case insensitive)
      The True/False state for all other values is unspecified.
      However, it does seem that Notetab treats most (if not all), other values
      as false. To maintain consistency with Notetab logic these clips define
      True ONLY as {1, TRUE, YES, Y, ON}, all other values are deemed false.

      Although the functions are self referencing, the value of a custom
      function in Notetab is also available in the global variable %result%.

      Except for the NOT operator, these logic operations are normally
      binary operations. For the sake of convenience, I have removed that
      restriction for the AND and OR functions. Their number of arguments
      is limited only by Notetab string size limits which, IIRC, is in the
      thousands. Probably enough for most applications.

      Natively, these functions will only work from a local clipbook as
      Notetab does not support far functions. However, based on a post
      by Ian Ntnerd last August, the included ^!FarFunc clip enables one
      to transcend that limitation. For example, if these functions were
      placed in the LogicFunc.clb clip library, then the command

         ^$FarFunc("LogicFunc:AND;^%A%;^%B%;^%C%")$

      would return the logical result of ^%A% AND ^%B% AND ^%C%

      Unfortunately, due to the way Notetab handles memory, custom
      functions cannot be reliably used from the clipbar. There may be a
      way around that as well but I don't have time to thoroughly test it.

      Although not as convenient as functions, these function clips may
      alternately be used as regular clips. Using the above example:

         ^$FarClip "LogicFunc:AND" "^%A%;^%B%;^%C%"

      The clip/function value is contained in the %result% global variable.

      Using clips vs functions requires at least double the number of lines
      of code and is a lot messier, but it would get around the no clipbar
      restriction.

      <rant>And since it works in the clipbar as a clip and uses the same
      global variable as in the function mode, why in hell won't Notetab be
      fixed so that we can use functions from the clipbar?</rant>

      I have uploaded the complete set of functions and the FarFunc clip
      along with some discussion and tutorial material, tests and suggested
      icons (if and whenever) to the forum file repository as a zip file.
      You can download it from here:
      http://tech.groups.yahoo.com/group/ntb-clips/files/Art Kocsis' Files/

      Note: I updated my first upload of this file to correct some spelling
      errors. Yahoo may have sent out an announcement for the first one. Go
      to the above files page for current downloads.

      ;############################# Start of Clip Code ###################
      H="OR"

      ;This Function performs a logical inclusive OR operation on two or more arguments
      ;
      ;   A OR B <==> MAX (A,B)
      ;
      ;Usage:  ^$XOR(A;B[;C;D;E...])$  where A, B, C... are logical values/variables
      ;                       The result is returned both as the function value
      ;                          and in the global variable: %result%
      ;
      ;Rev history
      ;09-13-13 Created Clip Function for Notetab Clip Forum post
      ;
      ;^!SetDebug On
      ^!SetListDelimiter ;
      ^!SetArray %Arglst%=^&
      ^!If ^%Arglst0%<2 ^!GoTo Error
      ^!Set %NArgs%=^%Arglst0%
      ;
      ^!Set %result%=0
      ^!Set %I%=1
      :Loop
      ^!Set %Vi%=0
      ^!IfTrue ^%Arglst^%I%% ^!Set %Vi%=1
      ^!Set %result%=^$Calc(Max(^%result%; ^%Vi%))$
      ^!Inc %I%
      ^!If ^%I%<=^%NArgs% Loop
      ^!GoTo End

      :Error
      ^!Set %result%=^%Empty%
      ^!Continue Syntax error in call to OR (two or more arguments required)


      H="NOR"

      ;This Function performs a logical NOT OR operation on two arguments
      ;
      ;   NOT A OR B   <==> (MAX (A, B) + 1) MOD 2
      ;
      ;Usage:  ^$NOR(A;B)$  where A & B are logical values/variables
      ;                       The result is returned both as the function value
      ;                          and in the global variable: %result%
      ;
      ;Rev history
      ;09-13-13 Created Clip Function for Notetab Clip Forum post
      ;
      ;^!SetDebug On
      ^!SetListDelimiter ;
      ^!SetArray %Arglst%=^&
      ^!If ^%Arglst0%<2 ^!GoTo Error
      ^!Set %V1%=0
      ^!IfTrue ^%Arglst1% ^!Set %V1%=1
      ^!Set %V2%=0
      ^!IfTrue ^%Arglst2% ^!Set %V2%=1
      ;^!Result
      ^!Set %result%=^$Calc((MAX(^%V1%; ^%V2%)+1) MOD 2)$
      ^!GoTo End

      :Error
      ^!Set %result%=^%Empty%
      ^!Continue Syntax error in call to NOR (two arguments required)

      H="FarFunc"

      ;Rev History
      ;10-06-12 Create clip
      ;
      ;FarFunc calls "far" functions as clips in a "far" clipbook
      ;   This clip is a work around of NTB's failure to support far functions
      ;
      ;Usage: ^$FarFunc("<FarFuncClipBook>:<FarFuncName>;<FarFuncArgs>")$
      ;        Do NOT enclose individual args with double quotes
      ;
      ;Ref Ian Ntnerd's post in Notetab Clips on 08-02-2012 PDT
      ;   http://tech.groups.yahoo.com/group/ntb-clips/message/23071
      ;
      ;Note: NTB function results are stored in, and passed by,  the predefined
      ;      variable, %result% which has already been defined by the far function
      ;         [See ArkFunc Tutorial notes]
      ;
      ;Implementation recommendation:
      ; • Replicate the FarFunc clip in each user clipLib
      ; • Put all far functions in a unique dedicated cliplib

      ;^!SetDebug On
      ^!SetListDelimiter ;
      ^!SetArray %FarFunInput%=^&
      ^!Set %FarCallArgs%=^$StrReplace("^%FarFunInput1%;";"";"^%FarFunInput%";0;0)$
      ^!FarClip "^%FarFunInput1%" "^%FarCallArgs%"
      ;############################# End of Clip Code ###################


    • Art Kocsis
      ... Well, I believe in giving credit when credit is due and in acknowledging posts that are useful. I try to always annotate my code with the sources that I
      Message 2 of 3 , Sep 16, 2013
      • 0 Attachment
        At 9/16/2013 12:23 PM, you wrote:
        >Art,
        >Nice work on the thinking and math to get these working. I'm impressed with its power and the math involved.
        >
        >Thanks for the reference in the ^$farfunc. :-) Glad it was useful.
        >Ian
        >
        >On 16/09/2013 7:05 AM, Art Kocsis wrote:
        >>Here are some of the promised clips implementing the mentioned logic operations:

        Well, I believe in giving credit when credit is due and in acknowledging posts that are useful. I try to always annotate my code with the sources that I use to help me remember. I spend far more time answering a posted question than in posting a question itself. I suspect that is true for most others posting answers and needs to be appreciated. Too often help is solicited and answers posted with nary a word of feedback or thanks. That is not a motivator for continuing to offer help.

        Art

        BTW, did you notice the table retained its formatting? Finally!
        My email client (Eudora), defaults to Courier New which is a fixed
        pitch typeface but Yahoo treats as proportional. I used the Consolas
        typeface for the table and it got by the Yahoo "improvement".
        Now to remember that.
      Your message has been successfully submitted and would be delivered to recipients shortly.