rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* a word about shift
@ 1991-09-11 17:10 malte
  1991-09-11 17:29 ` Chris Siebenmann
  0 siblings, 1 reply; 2+ messages in thread
From: malte @ 1991-09-11 17:10 UTC (permalink / raw)
  To: rc

I'd like to raise a discussion about shift's behaviour.
There are two things I am not too content with:

    1) shift doesn't work on any other variables than *
    What about an extended shift, say shift var number,
    or shift number, where the latter assumes * is to be shifted.
    This preserves compatibility.

    2) When $#var is lower than the number of shifts, shift prints an
    error message and does nothing. I'd prefer shift would optionally
    a) just print an error message, 
    b) print an error and set var to (),
    c) be silent and set var to (),
    d) do nothing

What about this? Anyone experienced out there?


_______________________________________________________________________________
malte@techfak.uni-bielefeld.de

send mail to:	Universitaet Bielefeld, Technische Fakultaet
		z. Hd. Malte Uhl
		Postfach 8640
		4800 Bielefeld 1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: a word about shift
  1991-09-11 17:10 a word about shift malte
@ 1991-09-11 17:29 ` Chris Siebenmann
  0 siblings, 0 replies; 2+ messages in thread
From: Chris Siebenmann @ 1991-09-11 17:29 UTC (permalink / raw)
  To: rc

 One can write a shift function that shifts an arbitrary list (except '*')
by whatever you want; in fact, I've attached my version at the end of this
message. Given that, I don't think we need to augment shift.

 I like shift giving you an error when you try to shift to far; people
who want other behaviors can write wrappers for it. I particularly dislike
options for what shift does; it should do *one* thing, always. See previous
arguments in the mailing list over options.

	- cks

# 'supershift' function for rc.
# usage:
#	sshift varname
#	sshift varname number
# shifts the list varname by number (default 1) positions.
fn sshift { if (~ $#* 1 ) { _sshift $1 1 $$1 } else { _sshift $1 $2 $$1 } }

# this function does most of the work.
# _sshift NAME COUNT LISTELEMS
# shift LISTELEMS COUNT items left, and assign the result to NAME.
fn _sshift { _vn=() { _vn=$1; shift; shift $1; shift; $_vn=$* } }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1991-09-11 17:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-09-11 17:10 a word about shift malte
1991-09-11 17:29 ` Chris Siebenmann

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).