Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

Real programmers don't comment their code. It was hard to write, it should be hard to understand.


programming / comp.lang.tcl / Re: How to return a value from a proc

SubjectAuthor
* How to return a value from a procCecil Westerhof
+* Re: How to return a value from a procAlex P
|`- Re: How to return a value from a procCecil Westerhof
`- Re: How to return a value from a procAlex P

1
Subject: How to return a value from a proc
From: Cecil Westerhof
Newsgroups: comp.lang.tcl
Organization: Decebal Computing
Date: Sat, 7 May 2022 04:52 UTC
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.lang.tcl
Subject: How to return a value from a proc
Date: Sat, 07 May 2022 06:52:21 +0200
Organization: Decebal Computing
Lines: 10
Message-ID: <87wneygd16.fsf@munus.decebal.nl>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0bb501fec4c7843ba82d15083014ff3d";
logging-data="17726"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CMG0ZDc8auNxYsij25TKn1iWvYFIiDdk="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:y6qzWNHQHLB2u0AcWcez/Egr6gg=
sha1:boxFvxyCvLevzIYBgl9EIVPay3w=
View all headers
At the moment I do as last statement of a proc:
        lsort -index 1 -integer -decreasing [lsort -index 0 ${swapList}]

Is this OK, or is it better to do:
    return [lsort -index 1 -integer -decreasing [lsort -index 0 ${swapList}]]

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


Subject: Re: How to return a value from a proc
From: Alex P
Newsgroups: comp.lang.tcl
Date: Sat, 7 May 2022 11:59 UTC
References: 1
X-Received: by 2002:a05:620a:6cc:b0:69b:dd1b:3235 with SMTP id 12-20020a05620a06cc00b0069bdd1b3235mr5528431qky.374.1651924775896;
Sat, 07 May 2022 04:59:35 -0700 (PDT)
X-Received: by 2002:a05:6870:424b:b0:ed:97b3:7240 with SMTP id
v11-20020a056870424b00b000ed97b37240mr6598452oac.238.1651924775636; Sat, 07
May 2022 04:59:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 7 May 2022 04:59:35 -0700 (PDT)
In-Reply-To: <87wneygd16.fsf@munus.decebal.nl>
Injection-Info: google-groups.googlegroups.com; posting-host=217.118.95.85; posting-account=VcikiQoAAAB8qn43rZQzxdhWq0g1FGMy
NNTP-Posting-Host: 217.118.95.85
References: <87wneygd16.fsf@munus.decebal.nl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fcd3e536-2d5a-4c15-a3b7-af389edf6cd5n@googlegroups.com>
Subject: Re: How to return a value from a proc
From: aplsim...@gmail.com (Alex P)
Injection-Date: Sat, 07 May 2022 11:59:35 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
As for a performance, both are identical in Tcl 8.6, but as for a style, *return...* seems to be better.

Also, *return* makes a code a bit more self-documented, as if saying: look, this procedure can be used in expressions.

And *return* (as well as *proc* and *method*) command is highlighted by some editors, so that a code with *proc* + *return* is framed with them, which make the code more viewable.

At last, if a procedure returns values in several places, the last command must be *return*. It's an insurance against possible mistakes and a matter of good taste.


Subject: Re: How to return a value from a proc
From: Alex P
Newsgroups: comp.lang.tcl
Date: Sat, 7 May 2022 12:10 UTC
References: 1
X-Received: by 2002:a05:620a:2412:b0:6a0:5f8e:c050 with SMTP id d18-20020a05620a241200b006a05f8ec050mr815578qkn.462.1651925407293;
Sat, 07 May 2022 05:10:07 -0700 (PDT)
X-Received: by 2002:a05:6870:c5a5:b0:da:ab36:48dd with SMTP id
ba37-20020a056870c5a500b000daab3648ddmr3147630oab.150.1651925407098; Sat, 07
May 2022 05:10:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sat, 7 May 2022 05:10:06 -0700 (PDT)
In-Reply-To: <87wneygd16.fsf@munus.decebal.nl>
Injection-Info: google-groups.googlegroups.com; posting-host=217.118.95.85; posting-account=VcikiQoAAAB8qn43rZQzxdhWq0g1FGMy
NNTP-Posting-Host: 217.118.95.85
References: <87wneygd16.fsf@munus.decebal.nl>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <253b6386-4c39-4bd3-9531-877ada8868dbn@googlegroups.com>
Subject: Re: How to return a value from a proc
From: aplsim...@gmail.com (Alex P)
Injection-Date: Sat, 07 May 2022 12:10:07 +0000
Content-Type: text/plain; charset="UTF-8"
View all headers
As for a performance, both are identical in Tcl 8.6, but as for a style, 'return...' seems to be better.

The 'return' command makes a code a bit more self-documented, as if saying: look, this procedure can be used in expressions!

Also, 'return' (as well as 'proc' and 'method') command is highlighted by some editors, so that a code with proc + return is framed with them, which makes the code more viewable.

At last, if a procedure returns values in several places, its last command must be 'return'. It's an insurance against possible mistakes and a matter of good taste.


Subject: Re: How to return a value from a proc
From: Cecil Westerhof
Newsgroups: comp.lang.tcl
Organization: Decebal Computing
Date: Sat, 7 May 2022 13:46 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Cec...@decebal.nl (Cecil Westerhof)
Newsgroups: comp.lang.tcl
Subject: Re: How to return a value from a proc
Date: Sat, 07 May 2022 15:46:20 +0200
Organization: Decebal Computing
Lines: 22
Message-ID: <87v8uhfob7.fsf@munus.decebal.nl>
References: <87wneygd16.fsf@munus.decebal.nl>
<fcd3e536-2d5a-4c15-a3b7-af389edf6cd5n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="0bb501fec4c7843ba82d15083014ff3d";
logging-data="7479"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/paHbXEqFA5/83kRDZBmCmMbbI4nQyj7o="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:4a7sSTGJCpxTNwLYWY4qb7b1C1Q=
sha1:5WLRpseCX2iP421uUjzLGvIVA6E=
View all headers
Alex P <aplsimple@gmail.com> writes:

As for a performance, both are identical in Tcl 8.6, but as for a style,
*return...* seems to be better.

Also, *return* makes a code a bit more self-documented, as if saying:
look, this procedure can be used in expressions.

And *return* (as well as *proc* and *method*) command is highlighted by
some editors, so that a code with *proc* + *return* is framed with them,
which make the code more viewable.

At last, if a procedure returns values in several places, the last
command must be *return*. It's an insurance against possible mistakes
and a matter of good taste.

OK, I will add the return.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


1
rocksolid light 0.7.2
clearneti2ptor