Arc Forumnew | comments | leaders | submitlogin
2 points by vrk 6128 days ago | link | parent

So point 4 would mean ! is a unary postfix operator, not too different from ~, the unary prefix Boolean negation. You can do this with the current macro system (code not tested):

  (mac ! (f fst . args)
     `(= ,fst (,f ,fst . ,@args)))

  ; Then:
  ((! foo) x . args)
The problem with this is that it's not very efficient. Sure, it's easy to define destructive functions this way from any given function, but for example sorting a list in-place is different from sorting a list, then substituting the value back to the original list. If this were implemented, there would be two different sorts, for instance; insort and sort!, and the latter were always the inefficient one (unless it was defined to be insort, which doesn't make sense in this case).


4 points by im 6128 days ago | link

There are two possible resolutions if the inefficiency is too much to bear:

- Have a really, really smart interpreter that can often convert nondestructive algorithms to efficient in-place ones. This seems difficult.

- Overload foo!. That is, interpret foo! as either foo! itself if it is defined, or (lambda (x . args) (= x (foo s . args))) if it doesn't.

-----

3 points by pg 6128 days ago | link

zap is a lot like this.

-----

1 point by sacado 6128 days ago | link

The other problem is that it changes the global value of fst. It breaks if I want to modify something declared in a "let", for instance.

-----