1. 12

  2. 5

    The Odin conversation from the orange site was high quality in this thread from 30 days ago. Sometimes lobsters have mixed reactions about links yonder but in this case the thread was nice so I’m gonna post it: https://news.ycombinator.com/item?id=22199942

    1. 1

      Multiple results: this bugs me, it’s just returning a tuple (like in Python, it’s an implicit tuple). There’s another kind in Lisp. Here we have:

      swap :: proc(x, y: int) -> (int, int) {
          return y, x;
      a, b := swap(1, 2);
      fmt.println(a, b); // 2 1

      What if you refactor your code and swap now returns y, x, z? You must update all swap callers to receive three values.

      In Lisp, say you return two results:

      (defun swap (x y) (values y x))

      by using the usual let and set macros, you get the first value, only y:

      (setf val (swap x y)) ;; val -> y

      if you want to catch the second return value, you explicitely ask for it. In CL:

      (multiple-value-bind (val-y val-x) (swap x y)

      or (nth-value 2 (swap…)).

      We can imagine the following to be equivalent:

      a := swap(1, 2) // works


      a, b := swap(1, 2) // still works

      that’s all :)

      1. 1

        I don’t actually know why, because when I actually looked it up the similarity just isn’t there, but at first glance this reminded me of Action! from my Atari 8 bit days.