🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #988

Re: Math routines (was bourne shell query)

#988
From: Scott Yelich
Date: Sun, 02 Sep 1990 18:14
73 lines
2367 bytes

>#include <stdio.h>
>int argc; char *argv[];
>while (i <= j)
> printf(" %d",i++);

Hmmm.. that's the STRANGEST sh program I have ever seen...
It must be that CSH that I keep hearing about!  :-)

This next routine isn't supposed to be sophisticated... but it works--
just give it two SMALL NUMBERS. 

ADDITION ()
 {
  NUM1="$1"
  NUM2="$2"
  shift $#
  while test $# -lt $NUM1
  do
    set - x $@
  done
  NUM1="$@"
  shift $#
  while test $# -lt $NUM2
  do
    set - x $@
  done
  NUM2="$@"
  set - $NUM1 $NUM2
  TOTAL=$#
 }

I am working on a sort of LIBRARY of SHroutines where all I have to do is
include the clode  ``. COUNT'' for the next... and use the code.

COUNT ()
 {
  test $# = 0 &&\
   {
    echo "$0: Usage: $0 value [...]"
    exit 1
   } ||\
    {
     for i
      {
       set ""
       while :
       do
         set $* " x"
         echo $#
         if test $# = $i; then
           break
         fi
       done
     }
    }
 }

Of course, ``COUNT x'' is a great counter!  :-)

The main problem with the two loops is the ``set " $*"'' command.
This is what takes so much time when the argument list grows.

--
Signature follows. [Skip now]

 -----------------------------------------------------------------------------
 Scott D. Yelich                         scott@[xanth.]cs.odu.edu [128.82.8.1]
 After he pushed me off the cliff, he asked me, as I fell, ``Why'd you jump?''
 Administrator of:    Game-Design requests to <game-design-request@cs.odu.edu>
 ODU/UNIX/BSD/X/C/ROOT/XANTH/CS/VSVN/
 -----------------------------------------------------------------------------
Technical Details
Message-ID: <SCOTT.90Sep2141426@tab00.larc.nasa.gov>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!abcfd20.larc.nasa.gov!tab00.larc.nasa.gov!scott
References: <26DC6447.15922@maccs.dcss.mcmaster.ca> <8446@orca.wv.tek.com> <SCOTT.90Aug30124930@tab00.larc.nasa.gov> <75@iconsys> <2494@uc.msc.umn.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!abcfd20.larc.nasa.gov!tab00.larc.nasa.gov!scott
From: scott@tab00.larc.nasa.gov (Scott Yelich)
Newsgroups: comp.unix.shell
Subject: Re: Math routines (was  bourne shell query)
Message-ID: <SCOTT.90Sep2141426@tab00.larc.nasa.gov>
Date: 2 Sep 90 18:14:26 GMT
References: <26DC6447.15922@maccs.dcss.mcmaster.ca> <8446@orca.wv.tek.com>
 <SCOTT.90Aug30124930@tab00.larc.nasa.gov> <75@iconsys>
 <2494@uc.msc.umn.edu>
Sender: news@abcfd20.larc.nasa.gov (USENET File Owner)
Organization: NASA Langley Research Center, Hampton, Va. 23665
Lines: 73
In-Reply-To: glex@uh.msc.umn.edu's message of 2 Sep 90 14:16:01 GMT