9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] rc break
@ 2009-05-12  1:52 erik quanstrom
  2009-05-12  5:08 ` Uriel
  0 siblings, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2009-05-12  1:52 UTC (permalink / raw)
  To: 9fans

i put a freshed copy of rc with a break
statement up on sources.  it also has
history and allows newlines within lists
like so
x=(a
	b
	c
	)
there's also a printenv function.  which
does not print the environment, but rather
rc's picture of the environment in the
same format as whatis.  this doesn't seem
as useful as it once did.

/n/sources/contrib/quanstro/src/futharc

- erik



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

* Re: [9fans] rc break
  2009-05-12  1:52 [9fans] rc break erik quanstrom
@ 2009-05-12  5:08 ` Uriel
  0 siblings, 0 replies; 9+ messages in thread
From: Uriel @ 2009-05-12  5:08 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Ah, very cool, break is one of the few things I have missed in rc some times.

What do you think of adding return? I have wanted it a few times and
Rob seems to think it makes sense to add it:
http://9fans.net/archive/2003/03/44

Thanks!

uriel

On Tue, May 12, 2009 at 3:52 AM, erik quanstrom <quanstro@quanstro.net> wrote:
> i put a freshed copy of rc with a break
> statement up on sources.  it also has
> history and allows newlines within lists
> like so
> x=(a
>        b
>        c
>        )
> there's also a printenv function.  which
> does not print the environment, but rather
> rc's picture of the environment in the
> same format as whatis.  this doesn't seem
> as useful as it once did.
>
> /n/sources/contrib/quanstro/src/futharc
>
> - erik
>
>



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

* Re: [9fans] rc break
  2006-08-06  0:50         ` geoff
@ 2006-08-06  6:04           ` erik quanstrom
  0 siblings, 0 replies; 9+ messages in thread
From: erik quanstrom @ 2006-08-06  6:04 UTC (permalink / raw)
  To: 9fans

sure.  but that's a bit counterintutitive, isn't it?  the loop continues
looping without doing anything.  but i should talk,
i'm using c to count scheme-style. ☺

is break really that broken?  because of the lack of break,
you see some rc code that looks like it was written for a class with an
expansive no-goto edict. ;-)

- erik

On Sat Aug  5 19:51:13 CDT 2006, geoff@plan9.bell-labs.com wrote:
> One could rewrite the example script as
> 
> 	# figure out what day we have by subtraction
> 	j = (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
> 	c = ()
> 	mon = ()
> 	for (i in 31 $feb 31 30 31 30 31 31 30 31 30 31)
> 		if (~ $#mon 0) {
> 			c = ($c 1)
> 			if (expr $i '>' $d >/dev/null)
> 				mon = $#c
> 			if not
> 				d = `{expr $d - $i}
> 		}
> 
> The lack of break may require recasting the form of a script.


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

* Re: [9fans] rc break
  2006-08-05 23:42     ` geoff
@ 2006-08-06  5:18       ` erik quanstrom
  2006-08-06  0:50         ` geoff
  0 siblings, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2006-08-06  5:18 UTC (permalink / raw)
  To: 9fans

it looks like there are a number of cases in /rc/bin.  try "grep -n while".
most of them are argument parsing.  but then again, argument parsing
is a large part of what scripts do.  

the lack of a break also limits one from doing anything like this:
(snippit from an ancient byron's rc script for calculating the date
n days in the future.)

	# figure out what day we have by subtraction
	j = (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
	c = ()
	for (i in 31 $feb 31 30 31 30 31 31 30 31 30 31) {
		c = ($c 1)
		if ( expr $i '>' $d >/dev/null) {
			break
		}
		d = `{expr $d - $i}
	}

perhaps something like 

	catch(done){
		for(i) switch($i){
		case -x
			xflag = 1;
		case -y
			yflag = 1;
		case *
			raise done
	}

would be better to implement.

- erik

On Sat Aug  5 18:43:19 CDT 2006, geoff@plan9.bell-labs.com wrote:
> I think this will work (modified from an rc script of mine):
> 
> while (! ~ $#* 0 && ~ $1 -* && ! ~ $1 --) {
> 	switch ($1) {
> 	case -a;	destsonly=yes
> 	case -b;	copies=($copies $2) ; shift
> 	case -c;	copies=($copies $user)
> 	case -v;	verbose=yes
> 	case -*
> 		echo usage: $0 '[-acv] [-b bcc] [file]...' >[1=2]
> 		exit usage
> 	}
> 	shift
> }
> # process $*, which now lacks options ...
> 
> I think this is the only situation in which I used to wish for `break'
> in rc, but it no longer seems worthwhile.


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

* Re: [9fans] rc break
  2006-08-05 20:59 ` "Nils O. Selåsdal"
@ 2006-08-06  4:25   ` erik quanstrom
  2006-08-05 23:42     ` geoff
  0 siblings, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2006-08-06  4:25 UTC (permalink / raw)
  To: 9fans

well, td knows more than i, but doesn't this code look ugly without the
benefit of a break statement?

fn parseargs { endarg = '' {
	while(! ~ $#argv 0){
		switch($argv(1)^$endarg){
		case -r
			earf r usage
		case -f
			earf f usage
		case *
			endarg = y
			cmd = ($cmd $argv(1))
			Shift argv
		}
	}
}}

wouldn't this be better

fn parseargs {
	while(! ~ $#argv 0){
		switch($argv(1)){
		case -r
			earf r usage
		case -f
			earf f usage
		case *
			break;
		}
	}
	cmd = $argv;
}

On Sat Aug  5 16:01:54 CDT 2006, noselasd@asgaard.homelinux.org wrote:
> erik quanstrom wrote:
> > is there some reason that rc has no "break" statement?
> The rc paper has some notes on this :
> 
> "... I deleted the builtins export, readonly, break, continue, read,
> return, set, times and unset because they seem redundant or only 
> marginally useful."
> 
> > for example:
> > 
> > 	for(i in $fu){
> > 		...
> > 		if(endcond)
> > 			break;
> > 	}
> > 
> > - erik
> 


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

* Re: [9fans] rc break
  2006-08-06  5:18       ` erik quanstrom
@ 2006-08-06  0:50         ` geoff
  2006-08-06  6:04           ` erik quanstrom
  0 siblings, 1 reply; 9+ messages in thread
From: geoff @ 2006-08-06  0:50 UTC (permalink / raw)
  To: 9fans

One could rewrite the example script as

	# figure out what day we have by subtraction
	j = (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
	c = ()
	mon = ()
	for (i in 31 $feb 31 30 31 30 31 31 30 31 30 31)
		if (~ $#mon 0) {
			c = ($c 1)
			if (expr $i '>' $d >/dev/null)
				mon = $#c
			if not
				d = `{expr $d - $i}
		}

The lack of break may require recasting the form of a script.



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

* Re: [9fans] rc break
  2006-08-06  4:25   ` erik quanstrom
@ 2006-08-05 23:42     ` geoff
  2006-08-06  5:18       ` erik quanstrom
  0 siblings, 1 reply; 9+ messages in thread
From: geoff @ 2006-08-05 23:42 UTC (permalink / raw)
  To: 9fans

I think this will work (modified from an rc script of mine):

while (! ~ $#* 0 && ~ $1 -* && ! ~ $1 --) {
	switch ($1) {
	case -a;	destsonly=yes
	case -b;	copies=($copies $2) ; shift
	case -c;	copies=($copies $user)
	case -v;	verbose=yes
	case -*
		echo usage: $0 '[-acv] [-b bcc] [file]...' >[1=2]
		exit usage
	}
	shift
}
# process $*, which now lacks options ...

I think this is the only situation in which I used to wish for `break'
in rc, but it no longer seems worthwhile.



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

* Re: [9fans] rc break
  2006-08-05 15:39 erik quanstrom
@ 2006-08-05 20:59 ` "Nils O. Selåsdal"
  2006-08-06  4:25   ` erik quanstrom
  0 siblings, 1 reply; 9+ messages in thread
From: "Nils O. Selåsdal" @ 2006-08-05 20:59 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

erik quanstrom wrote:
> is there some reason that rc has no "break" statement?
The rc paper has some notes on this :

"... I deleted the builtins export, readonly, break, continue, read,
return, set, times and unset because they seem redundant or only 
marginally useful."

> for example:
> 
> 	for(i in $fu){
> 		...
> 		if(endcond)
> 			break;
> 	}
> 
> - erik



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

* [9fans] rc break
@ 2006-08-05 15:39 erik quanstrom
  2006-08-05 20:59 ` "Nils O. Selåsdal"
  0 siblings, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2006-08-05 15:39 UTC (permalink / raw)
  To: 9fans

is there some reason that rc has no "break" statement?
for example:

	for(i in $fu){
		...
		if(endcond)
			break;
	}

- erik


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

end of thread, other threads:[~2009-05-12  5:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-12  1:52 [9fans] rc break erik quanstrom
2009-05-12  5:08 ` Uriel
  -- strict thread matches above, loose matches on Subject: below --
2006-08-05 15:39 erik quanstrom
2006-08-05 20:59 ` "Nils O. Selåsdal"
2006-08-06  4:25   ` erik quanstrom
2006-08-05 23:42     ` geoff
2006-08-06  5:18       ` erik quanstrom
2006-08-06  0:50         ` geoff
2006-08-06  6:04           ` erik quanstrom

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