By registering with us, you'll be able to discuss, share and exchange private messages with other members of our community.

SignUp Now!

Done Multi-line in-memory functions

Copied from an off-topic comment regarding adding a library command.

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


#7 Joe Caverly, Yesterday at 6:07 AM
4Start/TCStart cannot have multiple-line functions. For example, in my PowerShell Profile I have;

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;

Get-ProgID VBScript

#9 Joe Caverly, Yesterday at 11:16 AM
I see two separate issues:

1) TCC subroutines can return a value, so they can perform as functions.

A function could be defined that calls a multi-line subroutine in a .btm and returns the value returned by that subroutine.

2) That still requires repeatedly accessing a routine on disk.

Keeping a multi-line function in memory would basically be equivalent to keeping a subroutine or an entire .btm in memory.
If BASH and PowerShell can define multi-line functions in their startup files, and then keep them in memory, this should be possible with TCC.

Rule of thumb:
Your decision to load something as a function is also going to depend on how often you use it. If you use a small shell script infrequently, leave it as a shell script. If you use it often, turn it into a function.

Ref: Functions, Aliases, and the Environment

It certainly could be done. The question is whether Rex wants to add it. I get the impression it would require some major reworking.

Another consideration is the increasing use of SSD's. I realize that TCC tends to be used on servers and those tend to still use hard disks. Also, although SSD's can have read/write speeds in the range of 500MB/s, memory access (e.g., ramdisk) can easily be 4-6GB/s. And my understanding is that on its own Windows will cache in memory relatively small files that are accessed frequently.

But I think in most cases people would be fine with "repeated disk acccess" at 500MB/s. So a question is whether Rex wants to make a major change that will probably be almost moot in a few years.

Similar threads