Arc Forumnew | comments | leaders | submitlogin
2 points by rocketnia 4783 days ago | link | parent

I don't like that implementation of 'rotate, since it causes subexpressions of car.places to be evaluated twice. (I don't know if 'shift has similar quirks without looking at its code.)

This is something I cared about when working on Penknife that I now realize I don't actually use. (In fact, I don't use 'rotate or 'swap at all; it only comes up in 'zap.) My current way of thinking is that I wouldn't bother to fix it. I'd put a note in the documentation instead, or else detect unsupported usage and raise an error. And then I guess I'd make sure to apologize for that caveat every time I talked about the utility. :-p

If you want to fix it, I've found it's pretty elegant to have a (place ...) form that gives you a getter and a setter.

  (mac rotate args
    `(fn-rotate ,@(map [do `(place ,_)] args)))
It's probably just as elegant with fexprs.


1 point by akkartik 4782 days ago | link

"I'd put a note in the documentation instead.."

Indeed:

  mac shift $args ; multiply-evals to maintain places
    `(= ,@(zip-flat $args cdr.$args))
http://github.com/akkartik/wart/commit/2299ca5f0f

-----

1 point by rocketnia 4782 days ago | link

I half thought so. :-p Very nice implementation!

-----

2 points by akkartik 4780 days ago | link

You'll like my impl of wipe, then :)

  ; infinite nil generator
  = nils '(nil)   cdr.nils nils

  mac wipe places
    `(= ,@(zip-flat places nils))

-----

1 point by rocketnia 4779 days ago | link

That is pretty nice, yeah. ^_^

-----