Version 5 of Quoting and function arguments

Updated 2014-04-03 02:46:19 by RLE

started by TV

I'm making a interactive command composer, and happened to be wondering about general useability, so that preferably it wouldn't choke on special cases such as quoted names/arguments, and still generate command lines which can be part of a nested eval.

In bwise, which contains a lot of nested eval stuff probably rightfully not being popular for decent, readable, commercially documented (...) code, though to me is quite reasonabe and does a lot of stuff which some day probably will be better understood as lisp like funtional progamming (I learned lisp on the acorn electron, a bbc computer derivative, from an old book I stumbled on in the electrical engineering library, having picked up the programming language's properties somewhere), much does work as intended, and I promise I'll somehow get to the point of explaining the functional decomposition stuff graphically. Which to me is like decent bookkeeping, but it is an efficient, mathematically sound, way of talking to a computer about a certain problem, worthy of consideration ... Straying from the topic.

A procedure definition all tclers know:

  proc {{arg1 default_1} {arg2 default_2} ....} {
     body
     return $ret_value
  }

This is like most structured programming languages with argument passing.

In tcl, not just everything is a string but most likely everything is a list, which to my mind has a submeaning that everything can be dealt with at that level, symbolically, so we can automatically generate procedure definitions.

What can easily get in the way, and is usually a drag and at least break of programming language consistency (read: start getting the pointers and the hexdumps), is allowing general definitions and quoting to phrase them in practical use. Here, just that subject, preferably staying out of quoting hell, suppose we want to use function arguments with non-trivial names or defaults.

Examples:

 (Theo) 9 % proc test {{{a\ a} content\ a}} {puts ${a\ a}}
 (Theo) 10 % test
 content a
 (Theo) 11 % proc test {{{a\ a} {content\ a}}} {puts ${a\ a}}
 (Theo) 12 % test
 content\ a
 (Theo) 13 % proc test {{{a\\a} {content\ a}}} {puts ${a\\a}}
 (Theo) 14 % test
 content\ a
 (Theo) 15 %

Let's not forget:

THE BASIC MODEL (courtesy of John O.)

Almost all problems can be explained with three simple rules:

  1. Exactly one level of substitution and/or evaluation occurs in each pass through the Tcl interpreter, no more and no less.
  2. Each character is scanned exactly once in each pass through the interpreter.
  3. Any well-formed list is also a well-formed command; if evaluated, each element of the list will become exactly one word of the command with no further substitutions.

...