Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Function or Alias - Does it matter?



On Nov 18,  7:13pm, TJ Luoma wrote:
}
} Is there any practical difference between making an alias or a
} function if they do the same thing?

This depends on how precisely you mean "the same thing".

An alias is a textual replacement.  It works like that setting in your
phone SMS app that your friends use to prank you by having "LOL" expand
to a rude phrase if you leave the phone unlocked where they can find it.

A function is a semantic construct that encapsulates a series of other
semantic constructs so you can easily/repeatedly execute that series,
even if it's a series of only one item.

} Is there any reason to prefer one or the other?

An alias can change the semantics of the construct in which it appears
by changing the text and syntax before parsing is done.  A function
can manage a local environment (parameters, options, etc.) without
altering the environment of its caller.  Which one to prefer depends
on what you want to accomplish.



Messages sorted by: Reverse Date, Date, Thread, Author