Subject: ANN: curry.tcl - curried commands and lambdas in pure Tcl - DN [1]


Alexandre Ferrieux <alexandre.ferrieux@cnet.francetelecom.fr> - 05 May 1999 - comp.lang.tcl

 Here: http://place.net/~af/tcl/curry.tcl is my first attempt at very
 tiny code that allows to use 'curried commands' and lambda expressions
 in pure Tcl (see description below).

  I am posting it here at a very early stage for two reasons:

     - to collect feedback/ideas, as usual

     - to let people see by themselves to what extent it is harmless
       ('cause it does break scripts with space in procnames); if it
       proves so, the idea is to turn it into a core patch, with an
       established record of side-effects.

 # Principle:

 #  Uses  the   'unknown'  default   command   handling  mechanism   to
 # recursively  split the first word of  command names,  so that  names
 # with spaces are  interpreted as  so called *curried* commands,  i.e.
 # incomplete commands where the remaining  tokens are prepended to the
 # actual arglist:
 #
 #    % set x "puts stderr"
 #    % $x Hello
 #    Hello

 # An  example application  is complex  callable constructs which don't
 # pollute the 'proc' naming space, like lambda expressions:

 #    % set square [lambda x {expr {$x*$x}}]
 #    % $square 3
 #    9

 # A more elaborate one is this functional lambda:

 #    % set compose [lambda {f g} {lambda x "$f \[$g \$x\]"}]
 #    % set quad [$compose $square $square]
 #    % $quad 3
 #    81

 -Alex

Last modified
1999-09-27

(195.108.246.50)

Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated