Arc Forumnew | comments | leaders | submitlogin
Mappair
3 points by skenney26 5629 days ago | 3 comments
While reading through arc.arc I noticed a pattern that appears in a few places, mapping an anonymous function to a list of pairs:

  (map (fn ((p v)) (expand= p v))
           (pair terms)))
A convenient shortcut would be:

  (mappair p v (expand= p v) terms)
Which could be written:

  (mac mappair (x y expr args)
   `(map (fn ((,x ,y)) ,expr)
         (pair ,args)))
This idiom is used in expand=list, obj, copy, deftem, and addtem.


1 point by Adlai 5629 days ago | link

AFAIK, the parameter list for fn doesn't do destructuring in Arc. I think it's an easy fix though -- does this work?

   (mac mappair (x y expr args)
     (w/uniq arg
       `(map (fn (,arg)
               (let ,x ,(car  ,arg)
                    ,y ,(cadr ,arg) )
                 ,expr) )
             (pair ,args) ) ) )

-----

1 point by CatDancer 5629 days ago | link

AFAIK, the parameter list for fn doesn't do destructuring in Arc

  arc> ((fn ((x y)) (+ x y)) '(5 10))
  15

-----

1 point by Adlai 5629 days ago | link

My bad. I should start using the language a bit first...

-----