Re: Syntax, expressiveness and the beauty of Tcl



Eckhard Lehmann wrote:

That all looks very weird and complex. What about a simple and strict
polish notation, like in LISP:

proc + {a b} {expr {$a + $b}}
proc - {a b} {expr {$a - $b}}
proc * {a b} {expr {$a * $b}}
proc / {a b} {expr {$a / $b}}

If you are used to LISP like languages, this is very straight forward, but
IMHO it has the disadvantage that you need to define a proc for every
operation you want to use. My first approach (which of course is far away
from being perfect as noted by others here and which is useless if you want
polish notation...) can simply use [expr], which gives you already a full
and effective expression parser, just with a very small extension to its
semantics. Maybe, this extension should be really part of [expr], so we can
write

expr {x=some_expr}

instead of

set x [expr {some_expr}]

Which IMHO would look very normal to many people, should be easy to
implement and saves you the [set]. OTOH "set..." has the advantage that you
easily can see, there is an assignment, which is what I generally like in
Tcl: WHAT is done come first. But "expr {x=some_expr}"... hm, I kind of
like that.

Stephan
.



Relevant Pages

  • Re: CL failure stories?
    ... >> See me fighting for Lisp in education on slashdot ... > | Plus of expr * expr ... > | Var String ... Use generic function to make pattern matching clearer. ...
    (comp.lang.lisp)
  • Re: Why stay with lisp when there are python and perl?
    ... Lisp compilers are much more advanced, ... The sum type that you define typically includes a ... | Add of expr * expr ... In OCaml, you can rely on the compiler inferring the sum type for you ...
    (comp.lang.functional)
  • Re: operators similar to functions?
    ... I don't know how to give the other root, I don't know enough LISP to know what the negation operator is! ... My point was that not all languages work hard to imitate ... The only problem with Reverse Polish notation is that it doesn't allow Lisp-style variadic functions, though it does allow C-style ones. ...
    (comp.lang.c)
  • Re: Relative merits of Lisp-1 vs. Lisp-2?
    ... orthogonal to a language being a Lisp-1 or Lisp-2. ... Common Lisp ... (eval-or-compile (cons 'funcall expr)) ... (error "~S is not a symbol or lambda expression" expr)) ...
    (comp.lang.lisp)
  • Re: How does this work?
    ... which neither the shell nor expr will do. ... Bash4 does not do decimal fractions: ... # interpret command line as a lisp expression ...
    (comp.unix.shell)