• partial function application

    From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Fri Feb 13 08:20:21 2026
    From Newsgroup: comp.lang.tcl

    When using the same command with some of the same arguments multiple times
    it is sometimes convenient to have a shorter form.

    One solution is to create a wrapper proc. Another is to use interp alias.

    For example, if I want a command to replace all spaces in a string I could either do this:

    proc replace_spc args { regsub -all { } {*}$args }

    or this:

    interp alias {} replace_spc {} regsub -all { }

    Both these work fine because their subsequent arguments _follow_ the first
    two arguments that are fixed (-all and { }).

    But sometimes I want to fix arguments that come _after_ the per-call
    arguments.

    For example, suppose I have many calls like this:

    puts [textutil::adjust::adjust $lines -length 60 -justify center]

    I can easily create a proc to provide the common options, e.g.,

    proc adjust {lines args} {
    textutil::adjust::adjust $lines -length 60 -justify center {*}$args
    }

    But is is possible to create an _alias_ which can incorporate fixed
    arguments that aren't only at the beginning?
    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Schelte@nospam@wanadoo.nl to comp.lang.tcl on Fri Feb 13 10:05:58 2026
    From Newsgroup: comp.lang.tcl

    On 13/02/2026 09:20, Mark Summerfield wrote:
    But is is possible to create an _alias_ which can incorporate fixed
    arguments that aren't only at the beginning?

    You can, using apply:
    interp alias {} adjust {} apply {{lines args} {
    textutil::adjust::adjust $lines -length 60 -justify center {*}$args}
    }

    However, I don't see any advantage of doing this over creating a proc.


    Schelte.

    --- Synchronet 3.21b-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Fri Feb 13 09:20:39 2026
    From Newsgroup: comp.lang.tcl

    On Fri, 13 Feb 2026 10:05:58 +0100, Schelte wrote:

    On 13/02/2026 09:20, Mark Summerfield wrote:
    But is is possible to create an _alias_ which can incorporate fixed
    arguments that aren't only at the beginning?

    You can, using apply:
    interp alias {} adjust {} apply {{lines args} {
    textutil::adjust::adjust $lines -length 60 -justify center {*}$args}
    }

    However, I don't see any advantage of doing this over creating a proc.


    Schelte.

    OK, thanks, I'll stick with using procs.
    --- Synchronet 3.21b-Linux NewsLink 1.2