tpsh, recent commit

 commit 6eda7f33de6bb7505fc64986a5bd31211d68acc5
Author: Terry ... ... <...@,,,>
Date: Fri Mar 13 05:36:45 2009 +0000

initial implementation of the function and macro built-ins

'function name() definition' creates an alias named 'name' with evaluation
'definition'

'macro name( definition )' creates an alias named 'name' with evaluation
'definition'

Eventually macro will probably define the alias wrapped in a (grouping),
once (command groupings) are implemented. function will allow {
groupings } when that is also implemented; but will not make the
implicit.

Currently variables and quotes are pre-expanded by the line processing
code, before function/macro receive the text to store in a macro. While
this is the desired behavour for the alias built in, it is not desired
for other methods of defining a command macro! It is however possible to
escape variables and things, e.g.$ macro e( echo hi '$USER' ); so that
the expansion occurs when 'e' is executed, as opposed to when 'e' is
recorded. This will hopefully be fixed in the future.

The manual page is in continual development, and will reflect the
desired "end state" for macro behavour.

Basically tpsh has no real concept of an alias or function per say; only a simple macro recording facility.

  # bourne style alias
alias x=y
# csh style alias
alias x y

# bourne again style named function
function x() y

# tpsh specific syntax
macro x( y )

# each make x expand to y (with appropriate context grouping to be added later)

Generally where things differ enough between sh and csh, to warrant a check of the fine manual, like alias and the export/setenv thing; tpsh endeavors to be more permissive about muscle memory.

Internally there is no real difference between an alias and a function, it’s just a macro with a name. sh doesn’t use the function keyword, but bash does (which zsh also permits, hehe). It’s much less bugger to implement functions with the keyword then not at the moment, and it’s really the macro keyword I’m interested in. The macro built in is meant for simple commands, where as the bash function syntax is meant for compatibility and to make using a complex command as the definition readable. The sub shell and same shell command grouping syntax used in sh, of ( commands ) and { commands } I am expecting will be treated like an anonymous macro.

Eventually I’ll probably alter sh_eval() to “relax” its evaluations of a function definition so that environment variables and quotes (etc) are expanded when used, instead of stored. Atm the only “don’t screw with this” case in sh_eval, is not performing alias expansion when one executes the unalias built-in, since you can’t specify the macro to delete if it gets expanded first ^_^.

Personally, I like ‘macro foo( bar )’ more then ‘alias foo=bar’ or ‘alias foo bar’, feels more natural. tpsh after all is meant to reflect MY preferences rather then being purely sh compatible, lol. Even though there is little difference in tpsh (yet) between ‘alias la=ls -a’ and “alias la=”ls -a”‘, the implicit grouping inside the () is just more to taste:

$ macro la( ls -a )
$ macro ll( la -l )
$ alias
'la' => 'ls -a'
'll' => 'ls -a -l'
$

most Bourne inspired shells that support alias display them as `la=’ls -a'”, but the alias command is fairly new in sh, and I prefer ‘la’ => ‘ls -a’, thus that is what tpsh uses.