Arc Forumnew | comments | leaders | submitlogin
2 points by eds 5914 days ago | link | parent

Would it not be possible to use the "." syntax that already exists? For example, if + were defined something like this:

  (def + args
    ...)
Then to call + on a list a which contains '(1 2 3):

  (+ . a)
I know this doesn't work in the current Arc, but maybe support for it could be added. (Or maybe not if there is some other reason you can't do that with lists... but I can't think of any such reason.) At any rate you shouldn't have to define new syntax for it to make it work, you just have to make the interpreter eval the form (fn . args) correctly. (In CL it works if you try "(eval `(+ . ,a))", which isn't exactly the same thing, but gets at what I am proposing.)


4 points by vsingh 5914 days ago | link

Your solution is not sufficiently general.

For example, it should keep working if the 'a' in (+ . a) is replaced with its actual value. In that case, we get:

    (+ . '(1 2 3))
which is the same thing as saying

    (+ . (quote (1 2 3))
which is equivalent to

    (+ quote (1 2 3))
which obviously doesn't do the same thing as

    (apply + '(1 2 3))
which is what you wanted.

-----

1 point by bogomipz 5905 days ago | link

That means (+ . (1 2 3)) does what you want, doesn't it?

Granted, to do the equivalent of (+ @(foo)) you would have to do;

  (let temp (foo)
       (+ . temp))
Which is not very nice at all, so I'm not arguing against @. On the contrary.

Edit: I used to think that . and @ would only differ in the sense that cons and splice have different list building semantics, but now I believe that they should also differ in the timing of the operation;

  (+ . (foo))  -> (+ foo)
  (+ . '(foo)) -> (+ quote foo)
  (+ @(foo))   -> what we want, given that foo returns a list
  (+ @'(foo))  -> (+ 'foo)

-----

2 points by shiro 5914 days ago | link

That's a tempting idea; the problem is that you can only use a single variable after the dot. Because of the very definition of S-expression,

    (+ . (f x y))
is indistinguishable from

    (+ f x y)
However, just allowing single-variable case may be good to cover typical cases.

-----

3 points by absz 5914 days ago | link

It's close, but doesn't quite have the same semantics: with your syntax, the variable has to be at the end, but using the @ for splicing, one can write (+ 1 2 @lst 3 4).

-----

2 points by bogomipz 5913 days ago | link

Yes, which also means the @ cannot reuse the lst object in this case, and therefore shouldn't do so when it happens to be at the end either. The dot is a notation for CONS, while @ would require copying the list that is spliced in.

Both . and @ are very useful and would be great to have available in any context.

-----