The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: random832@fastmail.com (Random832)
Subject: [TUHS] 80 columns ...
Date: Sat, 11 Nov 2017 12:30:20 -0500	[thread overview]
Message-ID: <1510421420.1505476.1169232000.0EB6B20D@webmail.messagingengine.com> (raw)
In-Reply-To: <20171111170456.uq6tb63rtq6hkuc6@matica.foolinux.mooo.com>

On Sat, Nov 11, 2017, at 12:04, Ian Zimmerman wrote:
> On 2017-11-10 13:21, Norman Wilson wrote:
> > -- I miss one particular case of assigment having a value:
> > that of
> > 	while ((val = function()) != STOP)
> > 		do something with val
> 
> I was once in a remote job interview with a Ruby shop.  I don't know
> Ruby, but they said I could use Python.  Of course this situation came
> up (it's pretty common when you think about it) and on this occasion a
> whim made me write it thus:
> 
> while True:
>     val = function()
>     if val == STOP:
>         break
>     do_something()
> 
> Their reply was overflowing with shock and horror that I would use
> "while True", and that was the end of that opportunity for me.
> Apparently Ruby has a construct to handle this cleanly, without having
> to call function() from two sites.

Python has one as well, though it's a bit obscure - ISTR around half of
the people who commented on a thread on the python mailing lists where
this came up weren't familiar with it.

for val in iter(function, STOP):
    do_something()

If the function needs arguments, you have to use a lambda. If the
condition is something other than equality to some value... well, you
can hack something together, but it's debatably cleaner than the while
True loop.

(If the function is readline, though, you can just iterate over the file
object)


  reply	other threads:[~2017-11-11 17:30 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-10 17:21 Norman Wilson
2017-11-10 17:56 ` Larry McVoy
2017-11-11 17:04 ` Ian Zimmerman
2017-11-11 17:30   ` Random832 [this message]
2017-11-11 18:05     ` Ian Zimmerman
  -- strict thread matches above, loose matches on Subject: below --
2017-11-08 20:52 ron minnich
2017-11-08 21:02 ` Larry McVoy
2017-11-08 21:19   ` Dan Cross
2017-11-08 21:24     ` Larry McVoy
2017-11-08 21:28       ` Steve Nickolas
2017-11-08 23:28         ` Dave Horsfall
2017-11-08 23:35           ` Ron Natalie
2017-11-08 23:39             ` Dave Horsfall
2017-11-08 21:34       ` Dan Cross
2017-11-08 21:40         ` Dan Cross
2017-11-08 21:40         ` Larry McVoy
2017-11-08 21:43           ` Dan Cross
2017-11-09  1:00             ` Theodore Ts'o
2017-11-08 23:46     ` Steffen Nurpmeso
2017-11-09  6:52       ` Otto Moerbeek
2017-11-08 21:06 ` Bakul Shah
2017-11-08 21:18   ` Steve Nickolas
2017-11-08 22:17 ` Grant Taylor
2017-11-08 22:30   ` Arthur Krewat
2017-11-08 23:07     ` Andy Kosela
2017-11-08 23:15       ` Arthur Krewat
2017-11-08 23:15         ` Warner Losh
2017-11-08 23:49           ` Arthur Krewat
2017-11-09  0:04             ` Dave Horsfall
2017-11-08 23:24         ` Andy Kosela
2017-11-09  7:24 ` Lars Brinkhoff
2017-11-09 15:02   ` Don Hopkins
2017-11-09 19:14     ` Ron Natalie
2017-11-10 16:18       ` Nemo
2017-11-10 19:05         ` Jon Steinhart
2017-11-10 20:36           ` Toby Thain
2017-11-10 20:39             ` Larry McVoy
2017-11-10 20:46               ` Warner Losh
2017-11-10 20:59                 ` Larry McVoy
2017-11-11  9:24                 ` David Arnold
2017-11-10 20:43             ` Jon Steinhart
2017-11-10 20:58               ` Larry McVoy
2017-11-10 21:02                 ` Jon Steinhart
2017-11-10 21:09                   ` Larry McVoy
2017-11-10 21:12                     ` Jon Steinhart
2017-11-10 21:34                       ` William Corcoran
2017-11-10 21:50                         ` Jon Steinhart
2017-11-10 22:58                         ` Dave Horsfall
2017-11-10 23:05                           ` Jon Steinhart
2017-11-10 23:52                             ` Toby Thain
2017-11-11  0:24                             ` Larry McVoy
2017-11-11 16:40                   ` Ian Zimmerman
2017-11-11 16:47                     ` Larry McVoy
2017-11-11 17:23                       ` Jon Steinhart
2017-11-11 17:38                         ` Ralph Corderoy
2017-11-10 22:46               ` Toby Thain
2017-11-10 22:59                 ` Jon Steinhart
2017-11-11 14:33                   ` Andy Kosela
2017-11-11 17:19                     ` Jon Steinhart
2017-11-11 17:24                       ` Larry McVoy
2017-11-11 17:25                         ` Jon Steinhart
2017-11-10 23:59           ` Don Hopkins
2017-11-10 22:10         ` Dave Horsfall
2017-11-09 20:46     ` Lars Brinkhoff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1510421420.1505476.1169232000.0EB6B20D@webmail.messagingengine.com \
    --to=random832@fastmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).