Arc Forumnew | comments | leaders | submitlogin
12 points by icemaze 6140 days ago | link | parent

This one is my personal favorite:

  (mac >> body
    `(let it ,(car body)
       ,(if (cdr body) `(>> ,@(cdr body))
            'it)))
It works a little bit like CL's let* but is anaphoric and it's much easier to read. It's a pipeline: each expression is evaluated and it is bound to the result for the next expression to use. Example:

  (>> '(1 2 3 4 5)
      (keep odd it)     ; -> (1 3 5)
      (map [* 4 _] it)  ; -> (4 12 20)
      (cons 6 it)       ; -> (6 6 14 22)
      (reduce + it))    ; -> 42
It's very convenient sometimes. Plus, since most of Arc's functions have their main argument at the end (thanks devteam!) it could be modified so that it appends "it" to every expression in the body. This depends on how it's used in the real world.


5 points by noahlt 6140 days ago | link

Am I missing something, or is this just an easier way to write:

  (reduce + (cons 6 (map [* 4 _] (keep odd '(1 2 3 4 5)))))

-----

3 points by icemaze 6140 days ago | link

You are right: it just improves readability.

-----

1 point by ehird 6138 days ago | link

Ridiculous:

    (def ablast (l)
      (if (no (cdr l))
          nil
          (cons (car l) (ablast (cdr l)))))

    (def replc (x y l)
      (if (atom l) (if (is x l) y l)
          (no l) nil
          (is x (car l)) (cons y (replc x y (cdr l)))
          (acons (car l)) (cons (replc x y (car l)) (replc x y (cdr l)))
          (cons (car l) (replc x y (cdr l)))))

    (mac imp body
      (if (no body) nil
          (replc 'it `(imp ,@(ablast body)) (last body))))

-----