murex Shell Docs

Command Reference: private

Define a private function block

Description

private defines a function who's scope is limited to that module or source file.

Privates cannot be called from one module to another (unless they're wrapped around a global function) and nor can they be called from the interactive command line. The purpose of a private is to reduce repeated code inside a module or source file without cluttering up the global namespace.

Usage

private: name { code-block }

Examples

# The following cannot be entered via the command line. You need to write
# it to a file and execute it from there.

private hw {
    out "Hello, World!"
}

function tom {
    hw
    out "My name is Tom."
}

function dick {
    hw
    out "My name is Dick."
}

function harry {
    hw
    out "My name is Harry."
}

Detail

Allowed characters

Private names can only include any characters apart from dollar ($). This is to prevent functions from overwriting variables (see the order of preference below).

Undefining a private

Because private functions are fixed to the source file that declares them, there isn't much point in undefining them. Thus at this point in time, it is not possible to do so.

Order of preference

There is an order of preference for which commands are looked up: 1. test and pipe functions because they alter the behavior of the compiler 2. Aliases - defined via alias. All aliases are global 3. murex functions - defined via function. All functions are global 4. private functions - defined via private. Private's cannot be global and are scoped only to the module or source that defined them. For example, You cannot call a private function from the interactive command line 5. variables (dollar prefixed) - declared via set or let 6. auto-globbing prefix: @g 7. murex builtins 8. external executable files

See Also

This site is rebuilt weekly, the content is automatically generated from murex's source code. Last built on Mon Sep 21 06:11:30 UTC 2020 against commit 2557f7c2557f7cc7535c452c21d89164bd38ed8996f02fd. Downloadable murex binaries are also built weekly. Current version is 0.52.2000 BETA which has been verified against tests.