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-arguments

  "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