Arc Forumnew | comments | leaders | submitlogin
4 points by fallintothis 5893 days ago | link | parent

Multiple assigment: (= (x y) (list 1 2))

This, however, conflicts with regular assignment. It's ambiguous in that it's quite context-dependent. For instance:

  arc> (= y '(1 2 3))
  (1 2 3)
  arc> y
  (1 2 3)
  arc> (= (car y) (list 1 2)) ;we're accessing y, not assigning to car
  (1 2)
  arc> y
  ((1 2) 2 3)
  arc> ;but what of this?  x isn't a function, though
       ;the syntax is kind of inconsistent if used for both purposes
  (= (x y) (list 1 2))
  Error: "reference to undefined identifier: _x"
However, you can still do multiple assignment; just not destructuring assignment:

  arc> (= x 1 y 2)
  2
  arc> x
  1
  arc> y
  2
You could instead define, e.g.:

  (mac ds= (vars vals)
    `(set ,@(apply + nil (map list vars vals))))
Then:

  arc> (ds= (x y) (1 2))
  2
  arc> x
  1
  arc> y
  2
Which, confidentially, doesn't work for using literal lists in the 'vals position as you did, but that should still be doable. Could also use '= instead of 'set, if you still wanted to do something like:

  arc> (ds= (x y) ((list 1 2 3) (list 4 5 6)))
  (4 5 6)
  arc> x
  (1 2 3)
  arc> y
  (4 5 6)
  arc> (ds= ((car x) (cdr y)) ('a 2))
  2
  arc> x
  (a 2 3)
  arc> y
  (4 . 2)

I do like the idea of conceptually merging hash tables and arrays, or at least think it should be explored.


3 points by Amferreira 5893 days ago | link

You are right, I had forgot about (= (car y) (list 1 2)).

-----