zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh-Users List <zsh-users@zsh.org>
Subject: Re: Function or Alias - Does it matter?
Date: Tue, 18 Nov 2014 18:51:24 -0800	[thread overview]
Message-ID: <141118185124.ZM5238@torch.brasslantern.com> (raw)
In-Reply-To: <CADjGqHuZpMyRCvEMivTZhW63Dk0wgSR8K+q0Whd_MhW57qB0Ag@mail.gmail.com>

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.


  parent reply	other threads:[~2014-11-19  2:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-19  0:13 TJ Luoma
2014-11-19  0:45 ` James Pearson
2014-11-19  2:51 ` Bart Schaefer [this message]
2014-11-19  8:59 ` Oliver Kiddle
2014-11-23 22:35 ` zzapper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=141118185124.ZM5238@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).