9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] How can I shift a variable other than ?
@ 2007-03-10  4:46 erik quanstrom
  2007-03-10  5:14 ` Kris Maglione
  0 siblings, 1 reply; 39+ messages in thread
From: erik quanstrom @ 2007-03-10  4:46 UTC (permalink / raw)
  To: 9fans

why wouldn't it be backwardly compatable?
"(a b) = $*" is currently an error in rc. and i don't
believe i've ever seen an rc script that depends on
this error. 

- erik

On Fri Mar  9 13:30:57 EST 2007, rog@vitanuova.com wrote:
> i doubt this would be too much trouble to implement in rc.
> (but who wants backwardly incompatible shell scripts?!)


^ permalink raw reply	[flat|nested] 39+ messages in thread
* Re: [9fans] How can I shift a variable other than ?
@ 2007-03-10 12:32 erik quanstrom
  2007-03-10 17:30 ` Kris Maglione
  0 siblings, 1 reply; 39+ messages in thread
From: erik quanstrom @ 2007-03-10 12:32 UTC (permalink / raw)
  To: 9fans

On Sat Mar 10 00:17:12 EST 2007, bsdaemon@comcast.net wrote:

> On Fri, Mar 09, 2007 at 11:46:46PM -0500, erik quanstrom wrote:
> >why wouldn't it be backwardly compatable?
> >"(a b) = $*" is currently an error in rc. and i don't
> >believe i've ever seen an rc script that depends on
> >this error. 
> 
> The problem is that then new scrips wouldn't be portable.

ya. right.  is this this the same reason i should check my c code
with the johnson c compiler (being very careful to not use function
prototypes) to make sure it works everwhere?

of course my code will probablly still be broken with the c73
compiler.  hope nobody's still running that.

and now that we've thought of it, we can't fix any rc bugs.  since
scripts that rely on fixed bugs won't run everwhere.

c'mon.  what kind of dusty-deck thinking is this?

> but in that case, you may as well just use Inferno's sh

doesn't run on plan 9.  it's written in limbo and depends on
features of inferno that are not part of plan 9.

> or port es(1)

es hasn't been maintained in a dozen years.  there is a reason
for this.

while es has some great ideas and paul haahr did a really
nice job with it.  it seems to me that let and bindings make
the shell harder to use.  es implements a lot of functonality
in es (and still breaks 10kloc of c).  here's the definition of cd.

	es% whatis cd
	@ dir{if {~ <={%count $dir} 1} {$&cd $dir} {~ <={%count $dir} 0} {%seq {if {%not {~ <={%count $home} 1}} {throw error cd <={if {~ <={%count $home} 0} {result 'cd: no home directory'} {result 'cd: home directory must be one word'}}}} {$&cd $home}} {throw error cd 'usage: cd [directory]'}}


- erik


^ permalink raw reply	[flat|nested] 39+ messages in thread
* Re: [9fans] How can I shift a variable other than ?
@ 2007-03-09  4:38 erik quanstrom
  2007-03-09  4:48 ` erik quanstrom
  2007-03-09  4:57 ` lucio
  0 siblings, 2 replies; 39+ messages in thread
From: erik quanstrom @ 2007-03-09  4:38 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 458 bytes --]

... or the deleterious effects of insomnia.

i decided to see how hard this is.  after considering "shift var", 
and hd and tl, i added ranges to rc, as in

	cpu% 8.out
	broken! a=(1 2 3 4)
	broken! echo $a(1 4)
	1 4
	broken! echo $a(2-3)
	2 3
	broken! echo $a(2-)
	2 3 4
	broken! fn myshift{echo $*; '*' = $*(2-) ; echo $*}
	broken! myshift 1 2 3 4 5
	1 2 3 4 5

less than 20 lines of code.  (attached so you can avert your eyes.)

- erik

[-- Attachment #2: snippit --]
[-- Type: text/plain, Size: 640 bytes --]

word*
copynwords(word *a, word *tail, int n)
{
	word *v = 0, **end;
	for(end=&v;a && n-- != 0;a = a->next,end=&(*end)->next)
		*end = newword(a->word, 0);
	*end = tail;
	return v;
}

word*
subwords(word *val, int len, word *sub, word *a)
{
	int n, m;
	char *s;
	if(!sub)
		return a;
	s = sub->word;
	deglob(s);
	a = subwords(val, len, sub->next, a);
	n = 0; m = 0;
	while('0'<=*s && *s<='9') n = n*10+ *s++ -'0';
	if(*s++ == '-'){
		if(*s)	while('0'<=*s && *s<='9') m = m*10+ *s++ -'0';
		else	m = len;
		m -= n;
	}
	if(n<1 || len<n)
		return a;
	while(--n) val = val->next;
	return copynwords(val, a, m+1);
}

^ permalink raw reply	[flat|nested] 39+ messages in thread
* [9fans] How can I shift a variable other than ?
@ 2007-03-08  8:00 YAMANASHI Takeshi
  2007-03-08  8:41 ` Russ Cox
  2007-03-09 18:23 ` rog
  0 siblings, 2 replies; 39+ messages in thread
From: YAMANASHI Takeshi @ 2007-03-08  8:00 UTC (permalink / raw)
  To: 9fans

shift in rc only shifts the command line argument ($*).
How can I shift other variable in rc?
I would like to do something like this:

	a=(a b c)
	shift a 2
	echo $a

and the echo should yield "b c".

TIA,
-- 



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

end of thread, other threads:[~2007-03-13 20:39 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-10  4:46 [9fans] How can I shift a variable other than ? erik quanstrom
2007-03-10  5:14 ` Kris Maglione
  -- strict thread matches above, loose matches on Subject: below --
2007-03-10 12:32 erik quanstrom
2007-03-10 17:30 ` Kris Maglione
2007-03-10 21:20   ` Dan Cross
2007-03-10 21:53     ` Kris Maglione
2007-03-10 22:20       ` Dan Cross
2007-03-11 12:12       ` matt
2007-03-11 20:23         ` Kris Maglione
2007-03-11 22:11           ` erik quanstrom
2007-03-11 23:14             ` Martin Neubauer
2007-03-12  8:50               ` Kris Maglione
2007-03-12 12:26                 ` erik quanstrom
2007-03-12 13:37                   ` Anthony Sorace
2007-03-12 13:39           ` Dan Cross
2007-03-12 15:22             ` Russ Cox
2007-03-12 17:05               ` Dan Cross
2007-03-12 18:41                 ` Kris Maglione
2007-03-13 14:59           ` rog
2007-03-13 15:22             ` erik quanstrom
2007-03-13 15:40             ` C H Forsyth
2007-03-13 17:45               ` Anthony Sorace
2007-03-13 20:39                 ` Paweł Lasek
2007-03-13 17:32             ` Anthony Sorace
2007-03-09  4:38 erik quanstrom
2007-03-09  4:48 ` erik quanstrom
2007-03-09  5:27   ` Federico G. Benavento
2007-03-09  5:31     ` erik quanstrom
2007-03-09  7:00       ` Kris Maglione
2007-03-09 13:55         ` erik quanstrom
2007-03-09 14:09           ` Kris Maglione
2007-03-09 14:33             ` erik quanstrom
2007-03-09 14:37             ` erik quanstrom
2007-03-09  4:57 ` lucio
2007-03-09 14:41   ` erik quanstrom
2007-03-08  8:00 YAMANASHI Takeshi
2007-03-08  8:41 ` Russ Cox
2007-03-09 18:23 ` rog
2007-03-09 19:25   ` Kris Maglione

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