[Tcsh] Functions based on aliases

Matheus tateusg at protonmail.com
Sun Sep 6 13:21:32 EDT 2026


https://github.com/Krush206/etcsh/pull/3
Hello. After implementing one-line control structure parsing, I reimplemented functions (again). The idea is after the realization that aliases may serve one-line functions. The idea worked well. I disliked the work on functions based on pipes, and decided one-line procedures fit well for functions.

The dofunction() function shall construct an alias. The function is similar to search(), in that it shall search for a delimiting block (return). The following is an example on the syntax.

function myfunc
  @ calc = \!^
  while $calc
    @ calc--
    echo $calc
  end
return

This shall create an alias. An one-line procedure is constructed. Then, the declaration may be called as an alias.

myfunc 5

I've played with this work for a bit. The only drawback is that functions have their own context. In other words, setting a variable in a function doesn't apply to outer functions. Note, for now, goto doesn't apply to one-line procedures.


More information about the Tcsh mailing list