Posted to tcl by emiliano at Thu Jun 08 23:35:04 GMT 2023view raw

  1. package require Tcl 8.6 ; # uses [lmap]
  2.  
  3. # or [setx], bring your paint
  4. proc let {varname expr} {
  5. upvar 1 $varname var
  6. set var [uplevel 1 [list expr $expr]]
  7. }
  8.  
  9. # or [exprm]
  10. proc lexpr {args} {
  11. lmap expr $args {
  12. uplevel 1 [list expr $expr]
  13. }
  14. }
  15.  
  16. % let a {acos(-1)}
  17. 3.141592653589793
  18. % let b {sqrt(5)}
  19. 2.23606797749979
  20. % let c {$a + $b}
  21. 5.377660631089583
  22. % lexpr {$a -1} {$b**2} {$c * $a}
  23. 2.141592653589793 5.000000000000001 16.894419132130086
  24.