It would be nice to have something like anonymous types (like in C#) for
this situation. Although, if I remember correctly, one couldn't return them
from a function, but not sure if that was for a fundamental reason or not.
In any case, without having thought much about it, I would certainly love
something like anonymous type return values for functions, if feasible.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On
Behalf Of John Myles White
Sent: Monday, October 6, 2014 9:02 AM
To: [email protected]
Subject: Re: [julia-users] names tuples or equivalent

I think you're underselling (1), which provides the compiler with exactly
the kind of information it needs to generate extremely efficient code while
also providing names.

 -- John

On Oct 6, 2014, at 8:44 AM, Tamas Papp <[email protected]> wrote:

> Hi,
> 
> AFAIK tuples are the recommended way to return multiple values from a 
> function, but this requires that the programmer remembers the order of 
> values. I am wondering what the correct idiom is for returning 
> key/value pairs, similarly to alist/plist in Common Lisp. I have 
> considered the following alternatives:
> 
> 1. defining a composite type.
> 
>  advantages: well-defined constructor and extractor methods.
> 
>  disavantages: overkill for most situations, especially if used in 1-2  
> places. redefinition cumbersome.
> 
> 2. using hash tables (Dict), especially with their literal [ key1 =>
> value1 ] syntax.
> 
>  advantages: lightweight, can use symbols as keys. well-defined error  
> when key not found.
> 
>  disadvantages: did not benchmark it, but not sure they are  
> lightweight, for 2-5 values; hash tables usually aren't.
> 
> 3. tuples of tuples. This is apparently what keywords arguments use:
> 
>  
> http://julia.readthedocs.org/en/latest/manual/functions/#keyword-argum
> ents
> 
>  "Inside f, args will be a collection of (key,value) tuples, where 
> each  key is a symbol. Such collections can be passed as keyword 
> arguments  using a semicolon in a call, e.g. f(x, z=1; args...). 
> Dictionaries can  be used for this purpose."
> 
>  advantages: seems to be the internal mechanism.
> 
>  disadvantages: could not (yet) find the julia equivalent of cl:assoc  
> etc.
> 
> Please advise me, I would like to use the proper style.
> 
> Best,
> 
> Tamas

Reply via email to