Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #39646

Re: input/output parameters

Path csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.javascript
Subject Re: input/output parameters
Date Sun, 14 Mar 2021 22:32:23 +0000
Organization A noiseless patient Spider
Lines 41
Message-ID <875z1t9xjc.fsf@bsb.me.uk> (permalink)
References <20210313153232.40fa0c8b0adf07d7e807084d@gmail.com> <slrns4plpr.4fd.jon+usenet@raven.unequivocal.eu> <20210314185124.0bcbab76d172caf076ac3839@gmail.com>
Mime-Version 1.0
Content-Type text/plain
Injection-Info reader02.eternal-september.org; posting-host="02fe85859b0d2b0628d9e09a00ef638e"; logging-data="21579"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0Ri+8oloL4meUKXftXfX0kikZWNPNjME="
Cancel-Lock sha1:xEn3VrHFl33D6NGGUXvcJoNFeUo= sha1:Cfqa/eZYpVuk53EEhW8iOWxfj4o=
X-BSB-Auth 1.3bca827e37a486c4938c.20210314223223GMT.875z1t9xjc.fsf@bsb.me.uk
Xref csiph.com comp.lang.javascript:39646

Show key headers only | View raw


Anton Shepelev <anton.txt@gmail.com> writes:

> The whole point of those and similar functions is their
> usefulness as the condition of `if' and `while' statements,
> e.g.:
>
>    while( read_next( stream, out element )
>    {    // process the element
>    }
>
> What alternative(s) does JavaScript propose?

I suppose it depends on your style preferences.  One could make a
parsing object with the stream as a member and have the various parsing
functions set an 'element' member.  Then one would write

  let parser = { stream: data_source };
  while (parser.read_next()) {
      // process parser.element
  }

or you could indicate failure by returning a value that is never the
result of a successful parse, for example null, undefined or false.
Then you'd write

  while ((element = parser.read_next(stream)) !== null) {
      // process element
  }

Or maybe you'd prefer the functions returned two values so you could use
"destructuring" to refer to them:

  while ([element, status] = read_next(stream), status) {
      // process element
  }

Then again, some people might prefer to use exceptions.  There are many,
many options.

-- 
Ben.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-13 15:32 +0300
  Re: input/output parameters Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-03-13 15:16 +0000
    Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-14 18:51 +0300
      Re: input/output parameters Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-03-14 16:15 +0000
        Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-03-14 18:31 +0000
          Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-14 22:27 +0300
            Re: input/output parameters Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-03-14 23:44 +0000
            Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-15 06:41 -0700
        Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-14 22:17 +0300
          Re: input/output parameters Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-03-14 23:28 +0000
          Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-15 06:39 -0700
      Re: input/output parameters Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-03-14 22:32 +0000
      Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-15 06:36 -0700
        Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-20 14:49 +0300
          Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-20 11:59 -0700
            Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-20 13:07 -0700
          Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-03-20 19:29 +0000
            Re: input/output parameters Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-03-20 20:35 +0000
  Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-15 00:27 +0300
    Re: input/output parameters Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-03-14 23:51 +0000
      Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-20 14:56 +0300
        Re: input/output parameters Jon Ribbens <jon+usenet@unequivocal.eu> - 2021-03-20 15:08 +0000
          Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-21 15:16 +0300
            Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-21 08:46 -0700
              Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-04-10 14:54 +0300
        Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-20 12:05 -0700
          Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-21 15:58 +0300
    Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-15 06:43 -0700
    Re: input/output parameters Silvio <silvio@internet.com> - 2021-03-15 18:01 +0100
      Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-03-16 18:06 +0000
        Re: input/output parameters Silvio <silvio@internet.com> - 2021-03-16 23:58 +0100
          Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-03-17 19:14 +0000
            Re: input/output parameters Silvio <silvio@internet.com> - 2021-03-17 23:46 +0100
              Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-03-18 18:04 +0000
                Re: input/output parameters Silvio <silvio@internet.com> - 2021-03-22 00:39 +0100
                Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-03-23 10:44 +0000
                Re: input/output parameters Silvio <silvio@internet.com> - 2021-03-30 00:33 +0200
                Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-03-31 19:53 +0100
                Re: input/output parameters Silvio <silvio@internet.com> - 2021-04-01 01:17 +0200
                Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-04-01 18:02 +0100
      Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-20 15:50 +0300
        Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-03-20 18:52 +0000
          Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-21 17:35 +0300
            Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-21 08:50 -0700
              Re: input/output parameters Anton Shepelev <anton.txt@gmail.com> - 2021-03-21 19:31 +0300
            Re: input/output parameters John G Harris <niam@jghnorth.org.uk.invalid> - 2021-03-21 19:27 +0000
        Re: input/output parameters "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2021-03-20 13:02 -0700
  Re: input/output parameters Postiljon Petskin <yyyyyyyyyyyywwwww@zohomail.eu> - 2023-04-22 08:47 -0700

csiph-web