[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Some more primitives which can be removed



$&split and $&flatten are arguably unnecessary, except possibly for
performance reasons (though I haven't noticed much of a difference in the
average case).  %split and %flatten can be implemented as follows:

    fn %split   separator args \
    { 
      if { ~ $#args 0 } { throw error $0 usage: $0 separator [args ...] }
      let (result =)
        {
          for (elt = <={ %fsplit $separator $args }) 
            if { ! ~ $elt '' } { result = $result $elt }
          result $result
        }
    }


    fn %flatten   separator args \
    {
      if { ~ $#args 0 } { throw error $0 usage: $0 separator [args ...] }
      let (result =)
        {
          result = $args(1)
          for (elt = $args(2 ...))
            result = $result^$separator^$elt

          # This might be unnecessary someday, if `=' ever starts returning
          # the RHS of the assignment. 
          result $result
        }
    }

These could go in initial.es instead of using C primitives.


Another thought: Unless the \n, etc. hackery is removed from the shell
(which I think I favor doing), get rid of the -n option to echo, and make
echo not supply a terminating newline by default.  Lines which require a
newline can do so explicitly.