[Cuis-dev] Methods that return multiple values

Luciano Notarfrancesco luchiano at gmail.com
Wed Jun 21 06:13:03 PDT 2023


Smalltalk doesn’t have a convention for methods returning multiple values,
and I’m not aware of any implementation.
An example of such thing is the extended gcd: ‘a xgcd: b’ returns g, s, t
where g is the gcd, and as + bt = g. Writing methods that return multiple
values is easy with the curly brackets syntax, Integer>>#xgcd: ends with
something like
    ^ {g. s. t}
But using sending messages that return multiple values is kind of annoying,
I end up doing something like:
    xgcd := a xgcd: b.
    g := xgcd at: 1.
    s := xgcd at: 2.
    t := xgcd at: 3
Some years ago I thought about using blocks for this, but I never tried it.
Today I just did a little experiment implementing anArray | aBlock as ‘^
aBlock valueWithPossibleArgs: self’ and I can do:
    (a xgcd: b) | [:g :s :t| … ]

This is seems quite nice already, I guess I’ll start using it and see how
it feels. But the point of this mail is not to show a solution, but to ask
if anyone have thought about this or if they know any nicer solutions. Any
ideas?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230621/2919aeac/attachment.htm>


More information about the Cuis-dev mailing list