if 0 {[Richard Suchenwirth] 2003-08-08 - You can write an algorithm elegantly (e.g. in few lines of code, using few or no local variables, etc.), or performantly (i.e. not wasteful in time or memory). Ideally, these two come together, but in reality, elegant algorithms may show bad performance. Consider this elegant way of computing the sum of a list of numbers:} proc sum1 list {expr [join $list +]} if 0 {and the more conventional way, which uses 2 local variables:} proc sum2 list { set sum 0 foreach i $list { set sum [expr {$sum+$i}] } set sum } #--- The only difference here is that the [expr] arguments are not braced: proc sum3 list { set sum 0 foreach i $list {set sum [expr $sum+$i]} set sum } if 0 {Here is a little testframe to illustrate the respective performances, and draw them as curves on a canvas. It shows that sum1 (red) takes exponential time as lists grow longer, while sum2 (blue) remains pretty linear. sum3 (green) is initially worse than sum 1, but from the break-even point on it's better: [http://mini.net/files/elegance.jpg] } pack [canvas .c -bg white -width 600 -height 500] -expand 1 .c create line 0 500 0 500 -fill red -tag sum1 .c create line 0 500 0 500 -fill blue -tag sum2 for {set i 1} {$i<600} {incr i} { set list [lrange [string repeat "1 " [expr {$i*2}]] 0 end] set t1 [lindex [time {sum1 $list}] 0] .c coords sum1 [concat [.c coords sum1] $i [expr {500-$t1/40}]] set t2 [lindex [time {sum2 $list}] 0] .c coords sum2 [concat [.c coords sum2] $i [expr {500-$t2/40}]] update } if 0 {I was a bit surprised by the big difference. I will continue to start with elegant code, and tune it to performant when necessary, but deep in my heart I dream of a language that can performantly evaluate elegant expressions... } ---- [SS]: [LISP] seems the nearest today, there are compiled versions of CL and Scheme performing nearly half of native code speed. Also the [SUN] [Self] implementation was only 4/5 times slower then optimized C. [RS]: In Lisp, it would go like this (tested on Emacs Lisp): (defun sum0 (list) (eval (cons '+ list)))