rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
From: Tom Culliton <culliton@clark.net>
To: rc@hawkwind.utcs.toronto.edu
Subject: Speaking of counting...
Date: Thu, 1 May 1997 17:40:10 -0400	[thread overview]
Message-ID: <199705012140.RAA07113@clark.net> (raw)

Does anyone have a nice little generic range function for rc?  The
type of thing that lets generate a list something like the indices
from a fortran or basic for statement.  (I'm actually modelling this
after the one in python.)

1 argument means	for (i = 0; i < $1; i += 1)
2 arguments mean	for (i = $1; i < $2; i += 1)
3 arguments mean	for (i = $1;
			     ($3 > 0 && i < $2) || ($3 > 0 && i > $2;
			     i += $3)

For example...

	# echo 99 down to but not including 0
	for (i in `{range 99 0 -1}) echo $i
	# echo 0 up to but not including 10
	for (i in `{range 0 10}) echo $i
	# echo 0 up to but not including 10 stepping 2
	for (i in `{range 0 10 2}) echo $i
	# echo 0 up to but not including 10
	for (i in `{range 10}) echo $i

I could whip something up using awk, but someone must already have one!

Tom


             reply	other threads:[~1997-05-02  1:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-05-01 21:40 Tom Culliton [this message]
1997-05-02  1:26 ` Scott Schwartz
1997-05-02  2:44 ` Charles M. Hannum
1997-05-02  5:52   ` Scott Schwartz
1997-05-02  3:30 Rich Salz
1997-05-02 14:51 ` John Robert LoVerso
1997-05-02 22:09 Tom Culliton
1997-05-03  7:57 Byron Rakitzis
1997-05-03 12:43 rsc

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=199705012140.RAA07113@clark.net \
    --to=culliton@clark.net \
    --cc=rc@hawkwind.utcs.toronto.edu \
    /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.
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).