rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: wishlist
@ 1993-05-26 16:59 Tom Culliton x2278
  0 siblings, 0 replies; 18+ messages in thread
From: Tom Culliton x2278 @ 1993-05-26 16:59 UTC (permalink / raw)
  To: alan, rc

Alan finds a reason why he doesn't need read:

> So, there I was, walking home after work, muttering under my breath,
> and mulling over the analogy between rc having to exec to read a line
> and C having to perform a system call to read a char.  I though I had
> the clincher in this argument.  Then it dawned on me -- we can use
> buffered IO in rc (read many lines with one exec) exactly as we do in C
> (read many chars with one system call).

Strangely enough it was thoughts along this line that that convinced me
that read might be a good idea!  My first thought was that if execing
for each line was too slow why not just do something like this:

	buf = ``($nl) { cat }

And then just step through the list in any of the usual ways.  Of course
the problem is that even rc may not be able to stuff the whole file into
the environment, other programs could choke big time, and it would slow
down forking.  The next step is to get clever and use sed to grab
chunks:

	eof=()
	buf = ``($nl) { sed 20q }
	if (~ $#buf 0) eof = 1;

Of course this is also going to bloat the environment, albeit to a
lesser extent, with the buffer, code to fetch from the buffer and
transparently refill it when it empties, not to mention code to reset
the buffer, etc.  (I may write this up and post it later.)

In shell scripts read is used for two different purposes, getting one
line from a user, or chewing through a theoretically infinite input
stream one line at a time.  In the first case efficiency is usually not
a concern, but in the second case it obviously is.  The fact that the
same generalized facility would serve both cases well, and that these
are fairly common things to do, seem like a good argument for adding
read. (or something like it)

Tom


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-26 17:49 Tom Culliton x2278
  0 siblings, 0 replies; 18+ messages in thread
From: Tom Culliton x2278 @ 1993-05-26 17:49 UTC (permalink / raw)
  To: alan; +Cc: rc

> You can't use sed, as you don't know how much it buffers stuff up internally.
> Same with awk.
> 
> You cannot use ifs = $nl { foo = `{ cat } }, as you lose blank lines
> and cannot tell if the final line ends in a $nl or not.  I had enough
> of that kind of stuff 

You're absolutely right.  My first draft actually started out saying
that sed wouldn't work for pipes because you couldn't rescan the input
and provided an external command called "lines" (a generalization of
"line").  Unfortunately when I came back from lunch the reason for this
had slipped my mind, so it got cut.  (How embarassing!)  All the more
reason to add read.

Tom


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-26 17:29 Alan Watson
  0 siblings, 0 replies; 18+ messages in thread
From: Alan Watson @ 1993-05-26 17:29 UTC (permalink / raw)
  To: rc

I didn't intend to cc that last message to the list.  The C code is
awfully embarrassing.


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-26 17:26 Alan Watson
  0 siblings, 0 replies; 18+ messages in thread
From: Alan Watson @ 1993-05-26 17:26 UTC (permalink / raw)
  To: Tom Culliton x2278; +Cc: rc

You can't use sed, as you don't know how much it buffers stuff up internally.
Same with awk.

You cannot use ifs = $nl { foo = `{ cat } }, as you lose blank lines
and cannot tell if the final line ends in a $nl or not.  I had enough
of that kind of stuff 

I coded this up in about 10 minutes last night -- it works as a
technology demonstrator, but (a) the C code needs re-writing to read N
chars first and then one char at a time until the end of the line, and
(b) it all needs some better error checking.

bufread reads a line at a time into the variable, including any
trailing newline, and sets the variable to () at EOF.

Hope this helps you get a start,

Alan.

fn copy {
   @ {
      exec <$1 >$2
      while ( bufread line ibuf && ! ~ $#line 0 ) 
	 bufwrite line obuf
      bufflush obuf
   }
}

fn bufread {
   _var = $1 _buf = $2 {
      if ( ~ $#$_buf 0 ) {
	 ifs = () { eval '*' '=' `{ ./buffill } }
      } else {
	 * = $$_buf
      }
      $_var = $1
      if ( ! ~ $#* 0 )
	 shift
      $_buf = $*
   }
}

fn bufwrite {
   _var = $1 _buf = $2 {
      if ( ~ $#$_buf 4 ) {
	 bufflush $_buf
	 $_buf = ()
      }
      $_buf = ( $$_buf $$_var )
   }
}

fn bufflush {
   _buf = $1 _text = () {
      * = $$_buf
      while ( ! ~ $#* 0 ) {
	 _text = $text^$1
	 shift
      }
      echo -n $text
   }
}

buffill.c:


#include <unistd.h>

#define N 256

#define writestr(fd,s) (write ((fd),(s), sizeof (s) - 1))

int main ()
{
   char c;
   char lastc;
   int n;

   writestr (1, "( ");

   n = 0;
   while (n < N || c != '\n') {
      if (read (0, &c, 1) != 1)
	 break;
      if (n == 0 || lastc == '\n')
	 writestr (1, "'");
      if (c == '\'')
	 writestr (1, "''");
      else if (c == '\n')
	 writestr (1, "\n' ");
      else
	 write (1, &c, 1);
      lastc = c;
      n++;
   }

   if (n != 0 && c != '\n')
      writestr (1, "' ");

   writestr (1, ")");

   return 0;
}


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-26  6:57 Bengt KLEBERG
  1993-05-26 17:51 ` wishlist Chris Siebenmann
  1993-05-26 19:04 ` wishlist mycroft
  0 siblings, 2 replies; 18+ messages in thread
From: Bengt KLEBERG @ 1993-05-26  6:57 UTC (permalink / raw)
  To: rc


> From rc-owner@hawkwind.utcs.toronto.edu Wed May 26 05:07:39 1993
> Date: 	Tue, 25 May 1993 23:02:18 -0400
> From: netapp!byron@netcom.com (Byron Rakitzis)
> To: culliton@srg.af.mil, rc@hawkwind.utcs.toronto.edu
> Subject: Re: wishlist
> Content-Length: 329
> 
> I think it is a little too late to change $^ to $", but maybe that's
> just me. I know it was a drag for me when I switched from if not to
> else, and that was when there were just a few rc users. Now I put the
> install base at 3 figures, possibly 4. I would have to have an extremely
> good reason to break existing scripts right now.
> 
The question is perhaps more rightly put as: How many uses $^ ( and
would need to change to $" ). I must admit that I don't and therefore
I am in favor for getting $" in. It might make me lookup what it is :-)

I also think 'if not' was cute and would happily fix the (very) few
'else' that I have if I got it back.

Bengt


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-26  3:08 Alan Watson
  0 siblings, 0 replies; 18+ messages in thread
From: Alan Watson @ 1993-05-26  3:08 UTC (permalink / raw)
  To: rc

So, there I was, walking home after work, muttering under my breath,
and mulling over the analogy between rc having to exec to read a line
and C having to perform a system call to read a char.  I though I had
the clincher in this argument.  Then it dawned on me -- we can use
buffered IO in rc (read many lines with one exec) exactly as we do in C
(read many chars with one system call).

The interface might be a little tricky, and one would want to be
careful of having so much stuff in the environment, but it may well be
possible.  

Therefore, I withdraw my request for a built-in read, withdraw my
sugestion that echo should be a de jure built-in, and consequently
withdraw my suggestion that herestrings be removed.  To celebrate I may
even go and compile up rc without echo.

Sorry to have wasted your time with this one,

Alan.


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-26  3:02 Byron Rakitzis
  1993-05-26  3:06 ` wishlist Scott Schwartz
  0 siblings, 1 reply; 18+ messages in thread
From: Byron Rakitzis @ 1993-05-26  3:02 UTC (permalink / raw)
  To: culliton, rc

I think it is a little too late to change $^ to $", but maybe that's
just me. I know it was a drag for me when I switched from if not to
else, and that was when there were just a few rc users. Now I put the
install base at 3 figures, possibly 4. I would have to have an extremely
good reason to break existing scripts right now.


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-25 23:58 Tom Culliton x2278
  0 siblings, 0 replies; 18+ messages in thread
From: Tom Culliton x2278 @ 1993-05-25 23:58 UTC (permalink / raw)
  To: rc

(Damn!  How do I manage to get such vigorous "discussions" going?)

Re: what to take out (Alan Watson)

This was not my intent but I do have a favorite candidate, which never
made sense to me: `` which is just syntactic sugar for ifs=(...) {...}
Everything else seems like it really belongs.

Re: empowering features/simplifications (Erik Quanstrom)

I think rc has already done pretty well here, and can't think of any
proposed addition that really seems like a big win to me.  Possibly read
so you can chew up text files (awk is probably a better choice), or flag
so you can manipulate the behaviour.  Nothing else seems like it gives
you the kind of big win that lack of rescanning, variables as lists,
clean quoting, or even builtin ~ does.

Re: Conformance with Plan 9 rc (John Mackin)

John correctly points out that you'll probably never be able to port a
Unix rc script to Plan 9 or vice-versa just because the environments are
so different, and that Byron has made some major improvements and fixed
a number of the bugs listed in the Plan 9 man page.  I still think it
would be nice to keep the two as close as possible, especially for
arbitrary differences like $" vs. $^.  This makes the various Plan 9
docs and papers more useful and otherwise broadens our experience base.

Tom


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-25 21:29 Alan Watson
  0 siblings, 0 replies; 18+ messages in thread
From: Alan Watson @ 1993-05-25 21:29 UTC (permalink / raw)
  To: rc

John writes:

> Why are people looking for features to throw out of rc, anyway?

I'm English, so I like whining; an Australian should understand that.

> There are still some of us -- probably everyone on this list -- who believe
> that software bloat is bad, and that smaller, faster code is better.

Yes, but man page bloat is worse.

So, let me defend some of my statements:

(a) Here strings.

If echo is a built-in, here strings are redundant with echo and pipes
(more on why I think echo should be a built-in later).  Will anyone
argue with me that a redundant feature WHICH USERS NEVER USE DIRECTLY
should leave the language?

The only caveat is if the code to re-write functions in terms of echo
and pipes is more likely to be a problem to maintain than the current
code, and if Byron feels he has better things to do with his time (and
he almost certainly does).

(b) ``

> Its convenience certainly justifies its redundancy many times
> over.  It must stay.

I will accept an argument of convenience if you calculate the factional
occurance of `` in your history file, and if that faction is larger
than, say, 0.5%.  Typing convenience just doesn't wash in scripts.

Two ways to do one thing is bad, bad, bad.  Really sinful.  We should
either junk `` or ifs, and since the later comes handed down from the
heavens, the former must go.

(c) newpgrp

Perhaps I'm speaking from ignorance here, but what about a stand-alone
binary along the lines of nice, nohup, et al?  If people really want it
built-in, then they can hack addon.h.

(d) $^foo

Oops, Malte shows me up.  Same arguments as (b).

As I've mentioned in private email to Byron, I'm not going to stop
using rc just because these feature remain.  But my honest opinion is
that if the time Byron had to devote to rc was limitless, they should
be purged.  I'm sure he has better things to do, though.

Now, the big one, why should echo (and read) be built-in?

If all a shell does is fork and exec commands, they need not be there.
However, I would like to be able to use rc in the same manner as `awk'
-- read some data, match on it using ~, mess with it with some external
programs, and spit it out the other end.  awk is great for some stuff,
but it has it's limitations.  For example, I want be be able to parse
mail folders in rc.  To do this efficiently in rc, I need echo and read
to be built-in.  (This was never done very much in sh because quoting
becomes a nightmare.)

Perhaps this is misguided, but it seems a modest investment (two
primitives, both with historical precedent) for a vast increase in rc's
potential.

If echo becomes a de jure built-in, rather than remaining de facto, you
can still use "fn echo { /bin/echo $* }".


^ permalink raw reply	[flat|nested] 18+ messages in thread
[parent not found: <alan@oldp.astro.wisc.edu>]
* Re: wishlist
@ 1993-05-25  1:43 Alan Watson
  0 siblings, 0 replies; 18+ messages in thread
From: Alan Watson @ 1993-05-25  1:43 UTC (permalink / raw)
  To: rc-owner

So what should go?

(a) Here strings: use "echo 'foo' | bar" instead of "bar <<< 'foo'".
For more complex cases, like "bar <<<[0]'foo0' <<<[1]'foo1'" use "echo
'foo0' |[1=0] { echo 'foo1' |[1=1] bar }"

(b) The flattening operator: use a function instead

   fn flatten {
      if ( ~ $#* 0 ) {
	 echo >[2=1] 'usage: flatten list ...'
	 return 1
      }
      list = $1 {
	 shift
	 $list = $1
	 while ( ! ~ $#* 0 1 ) {
	    shift
	    $list = $list^' '^$1
	 }
      }
   }

(c) `` backquote substitution: use

   ifs = ( foo ) { bar = `{ baz } }

(d) newpgrp: use a wrapper around rc.

(e) cdpath: do it with a function.


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-24 16:13 Erik Quanstrom
  0 siblings, 0 replies; 18+ messages in thread
From: Erik Quanstrom @ 1993-05-24 16:13 UTC (permalink / raw)
  To: rc

Suppose we considered changes to rc which might promote small & 
simple.


^ permalink raw reply	[flat|nested] 18+ messages in thread
* Re: wishlist
@ 1993-05-24 15:17 Tom Culliton x2278
  0 siblings, 0 replies; 18+ messages in thread
From: Tom Culliton x2278 @ 1993-05-24 15:17 UTC (permalink / raw)
  To: rc, schwartz

WHOA!  My earlier message seems to have been misinterpreted.

> From: Scott Schwartz <schwartz@groucho.cs.psu.edu>
----------------------
> My biggest wish:
> 
> I'd like 
> 	fn / { echo do stuff }
> to work.

> From: Emin Gun Sirer <egsirer@phoenix.princeton.edu>
----------------------
> P.S. Someone forgot to add the controversy about hash not introducing a
> comment if it is not preceded by white space (e.g. lpr -#2), my personal
> pet peeve, to the wish list.

My intent WAS NOT to publish a wish list of things which should be
changed in or added to rc.  Instead it was to show some of the things
that people had asked for and hopefully point out that if we did all
these things we would end up with a ugly bloated mess.  I was urging
restraint rather than soliciting more crazed featurism.  In case I'm
still not making myself clear, some reasonable ideas have been discussed
along with some REALLY bad ones, I don't think most of them belong in
rc.  It is supposed to be small and simple, IT IS small and simple, LETS
KEEP IT THAT WAY!

Tom


^ permalink raw reply	[flat|nested] 18+ messages in thread
* wishlist
@ 1993-05-22  0:43 Scott Schwartz
  0 siblings, 0 replies; 18+ messages in thread
From: Scott Schwartz @ 1993-05-22  0:43 UTC (permalink / raw)
  To: rc

My biggest wish:

I'd like 
	fn / { echo do stuff }
to work.


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

end of thread, other threads:[~1993-05-26 19:05 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1993-05-26 16:59 wishlist Tom Culliton x2278
  -- strict thread matches above, loose matches on Subject: below --
1993-05-26 17:49 wishlist Tom Culliton x2278
1993-05-26 17:29 wishlist Alan Watson
1993-05-26 17:26 wishlist Alan Watson
1993-05-26  6:57 wishlist Bengt KLEBERG
1993-05-26 17:51 ` wishlist Chris Siebenmann
1993-05-26 19:04 ` wishlist mycroft
1993-05-26  3:08 wishlist Alan Watson
1993-05-26  3:02 wishlist Byron Rakitzis
1993-05-26  3:06 ` wishlist Scott Schwartz
1993-05-25 23:58 wishlist Tom Culliton x2278
1993-05-25 21:29 wishlist Alan Watson
     [not found] <alan@oldp.astro.wisc.edu>
1993-05-25  6:55 ` wishlist malte
1993-05-25  9:16   ` wishlist John Mackin
1993-05-25  1:43 wishlist Alan Watson
1993-05-24 16:13 wishlist Erik Quanstrom
1993-05-24 15:17 wishlist Tom Culliton x2278
1993-05-22  0:43 wishlist Scott Schwartz

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