Path: ...!weretis.net!feeder9.news.weretis.net!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail From: cross@spitfire.i.gajendra.net (Dan Cross) Newsgroups: comp.os.vms Subject: Re: New VSI post on Youtube Date: Sun, 25 Aug 2024 11:10:19 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: References: Injection-Date: Sun, 25 Aug 2024 11:10:19 -0000 (UTC) Injection-Info: reader1.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="427"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross) Bytes: 2836 Lines: 44 In article , Arne Vajhøj wrote: >On 8/24/2024 9:33 PM, Stephen Hoffman wrote: >> On 2024-08-20 12:36:51 +0000, Simon Clubley said: >>> One thing I wish was available in all languages is the ability to >>> return multiple values from a function call so you can return both a >>> status and the value(s) in one assignment. Ie: "a, b, c = >>> demo_function(param1, param2);". >>> >>> In languages with dynamic associative arrays (such as PHP), I simulate >>> this by returning an associative array from a function call with both >>> status and value fields. Makes coding _so_ much cleaner and robust. >> >> For those following along at home, C supports returning a struct. >> >> Languages including Swift allow returning an "optional", where you >> either get a value such as an object, or an indication or its absence. >> Swift uses the concept of "unwrapping" a result marked optional, which >> means you have to check before access. >> >> Returning objects is more widely available, and hides a lot of this >> mess, as well as hiding dealing with potentially-larger data buffers. >> Objects and message-passing is akin to itemlist-based APIs, dragged >> forward a few decades. >> >> In other languages, support for an optional requires explicit code, >> whether that might return a struct, or might return a value and a >> sentinel, or ilk. > >I don't know Swift but I will assume Swift optional is similar to >optional in other languages. > >It solves the return both status and value problem. But it is >not a general multiple return value solution. And it is really >just a small evolution of the traditional "return null >indicate an error". > > [snip overly long Java sequence] What a failure of imagination. When you have the Maybe monad, it actually opens up a lot of ground for abstraction. https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ - Dan C.