Thinairarts icon (fan-shaped) Go to Main Page
Thinairarts logo (like a Scheme program...)

nxproc: open source software

Mon 19 Feb 2024 15:13:26 PST

nxproc is a Tcl extension providing named arguments, and much more, for any user-defined command. The nxproc package works with TclOO classes and objects. nxconstructor and nxmethod share innovative features with nxproc—they're all "drop-in" replacements for the built-in commands.

Tcl programmers often encounter procs having numerous arguments—including with optional values, for example, when needing to enter configuration parameters. Such commands benefit the most from nxproc. Consider this proc:

proc mytest { a b c {dn 0} {ez cat} {fz mouse}} { ... }

Calling mytest could go something like:

set y [mytest 24 {Sam Jones} {July 24, 2022} 0 cat rat]

As the number of arguments increase it gets harder to keep track of the order of inputs, and it gets tedious having to restate defaults when entering the last optional values. Much better to be able to do this:

set y [mytest -num 24 -name {Sam Jones} -dt {July 24, 2022} -fz rat -food legumes]

Note that values for dn and ez don't need to be repeated—defaults are applied automatically. Furthermore, the order of options entered on the command-line doesn't matter, variables will still be set correctly.

Easy to use

nxproc is invoked as follows:

nxproc mytest {-num 10 -dn 0 -name {} -dt {} -ex cat -fz mouse -flag1 b 0 -switch2 b 1 -food e {veggie fruit meat legumes}} {     #     # mytest -num 24 -name "Sam Jones" -dt 2022-7-24     # -fz rat -food legumes     #     # num = 24, name = Sam Jones, dt = 2022-7-24     # dn = 0, ex = cat, fz = rat, food = legumes     ... }

Named args have a type, set when the argument list is defined. There are four types: boolean, numeric, string or enumerated. (Enumerated means input values are restricted to predetermined values included in the enum list.). In the case of bool and enum, type designators are mandatory. The characters b, e, n, s are abbreviations for types. Values are type-checked against the argument's type on command creation and at runtime. This provides a very useful sanity check on input values, reducing errors and possibly improving performance.

The project documentation has detailed information about nxproc. Be sure to check it out!

The oowebtools project uses nxproc interface extensively.

Information and download

Binaries and source code are available here: Fossil repository

Direct link to the download page: Downloads

Installing and full documentation: Documentation

Comments