Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

All your files have been destroyed (sorry). Paul.


devel / comp.lang.javascript / Re: input/output parameters

SubjectAuthor
o Re: input/output parametersPostiljon Petskin

1
Re: input/output parameters

<f1233f7f-04df-474f-8b4d-3f7b6ecc5659n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=18126&group=comp.lang.javascript#18126

  copy link   Newsgroups: comp.lang.javascript
X-Received: by 2002:ac8:5a84:0:b0:3ef:3126:7dca with SMTP id c4-20020ac85a84000000b003ef31267dcamr2977533qtc.2.1682178427615;
Sat, 22 Apr 2023 08:47:07 -0700 (PDT)
X-Received: by 2002:a9d:5785:0:b0:6a5:e210:3ed with SMTP id
q5-20020a9d5785000000b006a5e21003edmr2570004oth.1.1682178427347; Sat, 22 Apr
2023 08:47:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.javascript
Date: Sat, 22 Apr 2023 08:47:07 -0700 (PDT)
In-Reply-To: <20210313153232.40fa0c8b0adf07d7e807084d@gmail.com>
Injection-Info: google-groups.googlegroups.com; posting-host=82.131.36.15; posting-account=JYCD-AoAAABJjYHTEug7bzEvKBag4Jpy
NNTP-Posting-Host: 82.131.36.15
References: <20210313153232.40fa0c8b0adf07d7e807084d@gmail.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <f1233f7f-04df-474f-8b4d-3f7b6ecc5659n@googlegroups.com>
Subject: Re: input/output parameters
From: yyyyyyyyyyyywwwww@zohomail.eu (Postiljon Petskin)
Injection-Date: Sat, 22 Apr 2023 15:47:07 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4085
 by: Postiljon Petskin - Sat, 22 Apr 2023 15:47 UTC

On Saturday, March 13, 2021 at 2:32:40 PM UTC+2, Anton Shepelev wrote:
> Hello, all
>
> I started learning JavaScript but yesterday, but am already
> stuck at implementing input/output parameters. As I
> understand, they are not part of the language, yet I find
> them very convenient for normal procedural programming. For
> example, they allow returning a boolean flag and using
> functions inside `if` tests, similar to the very convenient
> TryParse() and TryGetValue() functions in C#:
>
> TryParse: https://docs.microsoft.com/en-us/dotnet/api/system.int32.tryparse
> TryGetValue: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.trygetvalue
>
> Unfortunately for me, JavaScript seems to compensate the
> lack of in/out parameters with much more complicated
> functional and object-oriented mechanisms. I therefore have
> tried to implement them myself, but have not come up with a
> satisfactory solution. The examples below demonstrate a
> function for integer division that stores the result in
> variable and returns a boolean value indicating whether the
> division was exact:
>
> // for bi-direction in/out parameters, return a code that
> // creates an anonymous object storing the the value *and*
> // setter clousure:
>
> function out_1(vn)
> { return "x => " + vn + " = x"; }
>
> function int_div_1(a, b ,c)
> { var /*integer */ r; // ratio
> var /*boolean */ x; // result is exact
>
> r = Math.floor(a / b);
> x = r * b === a;
> c( r );
> return x;
> }
>
> function out_2( vn, val, ret )
> { return `${vn} = ${val}, ${ret}`; }
>
> function int_div_2(a, b, vn)
> { var /*integer */ r; // ratio
> var /*boolean */ x; // result is exact
>
> r = Math.floor(a / b);
> x = r * b === a;
> return out_2(vn, r, x);
> }
>
> { let /*integer */ ratio;
> let /*boolean */ exact;
>
> exact = int_div_1(7, 3, eval(out_1("ratio")));
> console.log(`7/3: ratio = ${ratio}; exact = ${exact}.`);
>
> exact = int_div_1(6, 3, eval(out_1("r")));
> console.log(`6/3: ratio = ${ratio}; exact = ${exact}.`);
>
> exact = eval(int_div_2(7, 3, "ratio"));
> console.log(`7/3: ratio = ${ratio}; exact = ${exact}.`);
>
> exact = eval(int_div_2(6, 3, "ratio"));
> console.log(`6/3: ratio = ${ratio}; exact = ${exact}.`);
> }
>
> Can you think of better way to emulate output parameters,
> and preferable also bi-directional input/output parameters?
>
> --
> () ascii ribbon campaign -- against html e-mail
> /\ http://preview.tinyurl.com/qcy6mjc [archived]

You agree, that You are the most unoriginal person in the history of the universe ?

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor