Arc Forumnew | comments | leaders | submitlogin
3 points by rocketnia 4943 days ago | link | parent

After hammering on your approach a little, here's what I get. ^_^ I like to maintain the fact that Arc's '+ is left-associative, so I don't give myself as much leeway with the additional arguments.

  ; We're going to have a meaning for number-plus-list, so we override
  ; the default number behavior, which assumes that only numbers can be
  ; added to numbers.
  (extend + args (let (a b) args (and number.a number.b))
    (let (a b . rest) args
      (apply + (do.orig a b) rest)))
  
  (extend + args (let (a b) args (and cdr.args number.a alist.b))
    (let (n xs . rest) args
      (apply + (map [+ n _] xs) rest)))
Saying (treewise cons [only.+ _ n] xs) is a bit more wordy than necessary here, but it's still a good way to accomplish (+ n xs) inline, without extending '+.

Oh, hey, if 'treewise could tell that it had a cyclic data structure, it would also be a more robust option... but that's not the case yet. Should it be?



1 point by fallintothis 4943 days ago | link

I like to maintain the fact that Arc's '+ is left-associative

Good work!

if 'treewise could tell that it had a cyclic data structure, it would also be a more robust option

Do you mean cyclic structure like this?

  arc> (= xs (list 1))
  (1)
  arc> (do1 nil (= (cdr xs) xs))
  nil
  arc> (xs 1000)
  1
Never thought of that. I mean, the P part of the vanilla Arc REPL breaks on them, and I've never been compelled to use cycles. When are cyclic lists used? I guess if you're representing certain graphs?

In a more general sense, I wear my opinion about treewise on my sleeve: http://arclanguage.org/item?id=12115.

-----