Arc Forumnew | comments | leaders | submitlogin
Suggestion for two core features
8 points by cchooper 5942 days ago | 14 comments
There's not been much discussion of core language topics recently, so here are two of my suggestions:

1) You should be able to pass lists to lists.

  '(1 2 3)!(4 5 6)!(7 8 9)
  => (1 2 3 4 5 6 7 8 9)
It looks nicer with variables

  (= x '(1 2 3) y '(4 5 6) z '(7 8 9))

  x.y.z
  => (1 2 3 4 5 6 7 8 9)
2) Allow functions to be passed to numbers for multiple application.

  (= cdddddr (5 cdr))

  (cdddddr '(1 2 3 4 5 6))
  => (6)


6 points by nex3 5942 days ago | link

2 can be pretty easily accomplished using defcall from Anarki:

  (defcall int (i fn)
    (reduce (fn (f fs) f:fs) (n-of i cdr)))

-----

4 points by nex3 5942 days ago | link

Oops, stupid mistake. That should actually be

  (defcall int (i f)
    (reduce (fn (f fs) f:fs) (n-of i f)))

-----

1 point by eds 5940 days ago | link

This works, but do note that 'compose can take multiple arguments as in http://arclanguage.org/item?id=6121.

-----

3 points by sacado 5942 days ago | link

2) is an interesting idea, but would it really be useful ? The only real use I can think of is your example with multiple cdrs, but then wouldn't it be better to add the cdr functions up to 4 ds, then use the composition syntax in the rare cases you would need more ?

-----

2 points by drcode 5942 days ago | link

on #2, I would prefer:

(5 x) ==> (is 5 x)

...and also:

('foo x) ==> (is 'foo x)

...assuming that doesn't cause a problem I don't see right now...

-----

2 points by nex3 5942 days ago | link

I don't like this because then you have inconsistent behavior between types. It feels like you're saying, "If you can find something useful to do on function call, do that... otherwise just run is." Why wouldn't

  ((table) (table))
work?

-----

2 points by sacado 5942 days ago | link

I don't like it. What does (tb x) mean ? Does it mean "look for the key 'x in table 'tb" (provided 'tb is a table) or "is variable 'x holding the same thing as variable 'tb" ?

However, I think this could be a good candidate for ssyntax :

  foo?x ==> (is foo x)

-----

2 points by cchooper 5942 days ago | link

Definitely like that idea. Using is is a real pain and I have to use it all the time.

-----

1 point by cchooper 5942 days ago | link

The problem I see with the second one is:

  ('foo) x) == ((quote foo) x)
so there would be no way of telling if you were trying to do a list-ref.

-----

2 points by wfarr 5942 days ago | link

1) Not feasible currently. 'foo.bar expands to (foo bar), so you're example would expand to (x y z), or ((1 2 3) (4 5 6) (7 8 9)) where (1 2 3) is being applied as a function.

While it could be implemented, I think it would only serve to further confuse existing syntax.

2) This require some serious hackery on integers to get that to work.

-----

3 points by cchooper 5942 days ago | link

1) Good point. I should have written

  (x!y!z)
  => (1 2 3 4 5 6 7 8 9)
Edit: not I shouldn't! The first way was right.

2) I don't think so. I can't see this is much different to having lists or hashes in functional place.

-----

3 points by eds 5942 days ago | link

Actually, (2) is quite trivial (in Anarki):

  (defcall int (n f)
    (eval (cons 'compose (n-of n f))))
But of course this means you can't use the current version of infix math at the same time.

-----

2 points by Jesin 5927 days ago | link

I don't like the list concatenation idea, but I think the Church encoding idea, while maybe not good per se, is at least interesting and perhaps worth considering.

-----

1 point by cchooper 5927 days ago | link

Really? I thought easy list concatenation was the better idea. Arc is a list-based language, and concatenation is a very basic list operation, so I thought it would be a good thing to optimise it as much as possible.

-----