Path: utzoo!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!mcsun!ukc!cam-cl!news From: bdb@cl.cam.ac.uk (Brian Brunswick) Newsgroups: comp.lang.icon Subject: Re: Multiple value assignment in icon??? Message-ID: <1991Mar16.142726.5947@cl.cam.ac.uk> Date: 16 Mar 91 14:27:26 GMT Article-I.D.: cl.1991Mar16.142726.5947 References: <1991Mar13.180536.22613@cl.cam.ac.uk> <1991Mar15.013415.1499@midway.uchicago.edu> Reply-To: bdb@cl.cam.ac.uk (Brian Brunswick) Organization: U of Cambridge Comp Lab, UK Lines: 67 In article <1991Mar15.013415.1499@midway.uchicago.edu> goer@quads.uchicago.edu (Richard L. Goerwitz) writes: >Bdb@cl.cam.ac.uk (Brian Brunswick) writes (with regard to the problem >of assigning a series of results to a series of variables): >> >>Something like every (x|y):=f() is no good, of course. >> > >This is sooo close to working.... [explanation of what goes wrong] > >Aha! We've suddenly run into one very good use for coexpressions. >Here's what to do: > > val := create f() > every (x|y) := @val Yup, I'd spotted that this was possible, but was put off by the extra temporary variable needed - I'd really like something on one line. One can't even do things like ...@(val := create f()), since rhs evaluated multiple times when lhs is resumed. I did experiment with putting inteligence in a wrapper function, but it doesn't have enough information to work safely enough to withstand mistakes. >Now here's an excercize to see if you fully grasp how Icon de- >references variables. Why will the following NOT work the way you >want it to? > > var := create (x|y) > every val := f() do > var := val Urble ... create makes its own copy of local variables ... but would they even survive undereferenced (ug!) to be (pointlessly) used? I suppose globals would work. >Referring to a solution offered (but not quoted here): Which was using a wrapper of ![...] around the procedure return values to turn them into anonymous variables, which enables the calling line to use a multiple swapping assignment to do rotation amongst several variables and accumulate results that way. ( every z:=:y:=:x:=:f() ) > >> Am I missing something, or does this irritation spoil an otherwise >> pretty language? > >Your solution isn't particularly idiomatic. You clearly sensed this. >Hence your posting. Your question was really very good, though, be- >cause you've clearly grasped precisely the sort of situation that makes >coexpressions useful and elegant additions to the language. You aren't >missing a thing, but rather demonstrating an understanding of the sort >of logic that led to the implementation of coexpressions.... > >I hope this helps. > >-Richard Goerwitz (goer@sophist.uchicago.edu) Hmm... I'm not so sure that I don't prefer my cludge to having to introduce an extra intermediate variable. Of course, its only good so long as its clearly recognised as an idiom by the reader, otherwise its needless obfuscation. Also, I hesitated somewhat at creating a co expression just to do something that short that I'm likely to use quite a lot. Isn't that likely to be quite expensive in terms of garbage produced? Or would reusing the same temporary to hold it mean that reference counting or something rescues things? Brian.Brunswick@uk.ac.cam.cl Disclaimer. Short sig rules!