1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Add a .btm LIBRARY system

Discussion in 'Suggestions' started by Rick Reinckens, May 18, 2017.

  1. Rick Reinckens

    Joined:
    Oct 18, 2009
    Messages:
    102
    Likes Received:
    4
    Add something similar to being able to load functions, but instead for accessing subroutine libraries:

    Specify which libraries will be accessed.
    LIB_NAME "Library Name" "Full path to library file, no wildcards"

    Ex:
    LIB_NAME "Date Routines" "C:\Program Files\JPSoft\TCC\Date_Routines_Lib.btm"
    LIB_NAME "Name Routines" "C:\Program Files\JPSoft\TCC\Name_Formatting_Routines_Lib.btm"

    Specify which routines in the library are available to this btm
    LIB_DEF /"Library Name declared in a LIB_NAME" "Routine #1", "Routine #2", "Routine #5"

    Ex:
    LIB_DEF /"Date Routines" "CCYYMMDD_to_ISODATE", "ISODATE_to_YYMMDD"
    LIB_DEF /"Name Routines" "Last_comma_First", "First_Mid_Last"

    Call the pre-identified routine from the .btm
    LIBRARY "Routine name" parm 1, parm 2

    Ex:
    LIBRARY Last_comma_First "Harry", "Johnson"
    LIBRARY MMDDYY_to_ISODATE 111807

    Error: Library Routine MMDDYY_to_ISODATE undefined
    (Even if the "Date Routines" library does have that subrou, because it wasn't identified in LIB_DEF)
    You would probably want a different term than "undefined".
     
    #1 Rick Reinckens, May 18, 2017
    Last edited: May 18, 2017
  2. Rick Reinckens

    Joined:
    Oct 18, 2009
    Messages:
    102
    Likes Received:
    4
    Reasons for LIB_DEF are so if you have the same routine name in more than one library file there won't be confusion.
    Also, having such a "declaration" up front will help the programmer see what is actually accessible.
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,203
    Likes Received:
    11
    Try these ALIASES and see how they work for you:
    Code:
    alias LIB_NAME=`set %@unquote[%1]=%2`
    alias LIB_DEF=`set %@unquote[%2]=%[%@unquote[%1]] %@unquote[%3]`
    alias LIBRARY=`if %[%1].==. (echoerr Library Routine %1 undefined) else (gosub %[%1] %*)`
    
    [R:\] LIB_NAME "Date Routines" "C:\Program Files\JPSoft\TCC\Date_Routines_Lib.btm"
    [R:\] set Date*
    Date Routines="C:\Program Files\JPSoft\TCC\Date_Routines_Lib.btm"
    [R:\] LIB_DEF "Date Routines" "CCYYMMDD_to_ISODATE", "ISODATE_to_YYMMDD"
    [R:\] set CCYY*
    CCYYMMDD_to_ISODATE="C:\Program Files\JPSoft\TCC\Date_Routines_Lib.btm" ISODATE_to_YYMMDD
    [R:\] library CCYYMMDD_to_ISODATE 1 2 3 4
    gosub "C:\Program Files\JPSoft\TCC\Date_Routines_Lib.btm" ISODATE_to_YYMMDD  1 2 3 4
    
    [R:\] library MMDD_to_ISODATE 1 2 3 4
    Library Routine MMDD_to_ISODATE undefined
    
    In my example, I did an echo gosub instead of an actual gosub, since gosub is only valid inside a batch script.
     
  4. Rick Reinckens

    Joined:
    Oct 18, 2009
    Messages:
    102
    Likes Received:
    4
    I'm not looking to do it with aliases. I previously pointed out that an alias can be set up that LIBRARY is used as a substitute for GOSUB.

    Modern programming languages routinely include some form of command such as IMPORT that makes the contents of some other file available, usually a routine library. I'm basically asking to include that type of functionality, like functions and aliases can be imported. I think it's best not to just block import an entire library file because it could get confusing to the person referencing the file and create conflicts. Requiring individual routines to be "declared" (e.g., LIB_DEF) would reduce confusion and avoid situations where multiple library files have a routine with the same name.

    That's one reason I didn't include LIB_DEF /All as an option.
     
  5. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,203
    Likes Received:
    11
    Since the aliases I created define environment variables, you could save them and restore them using SET /R. You could prepend "LIB_" or something similar to distinguish them from other variables. My point of the ALIAS's is that you can achieve what you wanted rather simply without the need for an entire management system.
     
  6. Rick Reinckens

    Joined:
    Oct 18, 2009
    Messages:
    102
    Likes Received:
    4
    I'm suggesting an added feature to the language, that will make the language more in line with other modern languages, not a custom work-around.

    The problem with any custom work-around is different people set them up differently and there's no reference, which severely limits availability and usefulness of other people's code and libraries. The only way to encourage a standard approach is to have it as a language feature.
     
  7. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    730
    Likes Received:
    8
    I would like to see something like BASH has, that is, the .bashrc file is loaded upon startup. The .bashrc file can contain multi-line functions, which would stay in memory like TCC plugins do.

    Or, like the Powershell Microsoft.PowerShell_profile.ps1 file, which does the same thing as .bashrc does.

    Ref: BASH Startup Scripts

    Joe
     
  8. JohnQSmith

    Joined:
    Jan 19, 2011
    Messages:
    559
    Likes Received:
    7
    Like TCSTART ?
     
  9. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    730
    Likes Received:
    8
    4Start/TCStart cannot have multiple-line functions. For example, in my PowerShell Profile I have;

    Code:
    function Get-ProgID
    {
      param ($filter = '.')
     
      $ClsIdPath = "REGISTRY::HKey_Classes_root\clsid\*\progid"
      dir $ClsIdPath |
        foreach {if ($_.name -match '\\ProgID$') { $_.GetValue("") }} |
          where {$_ -match $filter}
    }
    
    Get-ProgID is now a function that I can call from the command line. Example;

    Code:
    Get-ProgID VBScript
    Joe
     
  10. Rick Reinckens

    Joined:
    Oct 18, 2009
    Messages:
    102
    Likes Received:
    4
    Joe,

    I set this up as a new suggestion, since it's completely unrelated to a library addition.

    It's set up as "MULTI-LINE IN-MEMORY FUNCTIONS", since that's really the request. It really wouldn't matter whether it's a start-up option or later. The same code that would be needed for multi-line in-memory functions later would be needed for them at startup.
     
    #10 Rick Reinckens, May 19, 2017
    Last edited: May 21, 2017
  11. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    10,091
    Likes Received:
    85
  12. Rick Reinckens

    Joined:
    Oct 18, 2009
    Messages:
    102
    Likes Received:
    4
    The command description on page 410 of the manual should mention that TCC has a command-line switch that will prevent loading the default libraries.
     

Share This Page