Arc Forumnew | comments | leaders | submitlogin
2 points by jmatt 6312 days ago | link | parent

I think he's looking for syntax sugar to make it easier for programmers who are not used to functional / prefix code.


2 points by bOR_ 6311 days ago | link

Is there a list of the syntax sugar we have so far?

I remember being told about table!key being equivalent to (table key), and : is used to string functions together (although I keep forgetting it works from inside out).

I'm not sure what . offers, except that you can do *(3 . + . 5) with it. The example of foo.bar being equal to (foo bar) isn't helping much either ;)

-----

2 points by absz 6311 days ago | link

See http://arclanguage.org/item?id=4012 .

Note that you can also use : to compose multiple functions.

The Anarki also has, if you include "ssyntaxes.arc":

11. x..y, which is the same as (range x y), and x..y..z, which is the same as (range x y z) (a range from x to y with step size z).

12. f//g, which is the same as (orf f g); this returns a function where ((orf f g) x y ...) is equivalent to (or (f x y ...) (g x y ...)). This can be used with as many functions as you want.

13. f&&g, which is like f//g but uses andf instead of orf, so the function is equivalent to (and (f x y ...) ...).

14. typ?, which returns the function (fn (x) (isa x 'typ)).

15. User-definable ssyntax, so you can add your own!

Also, note that ssyntax only works with variables and integers, not with literal lists or function calls.

And your example of using . for infix is actually a holdover from mzscheme, and not used anywhere particularly; its existence in Arc seems to be accidental.

-----

1 point by dpara 6311 days ago | link

aah beautiful, forget I ever said anything :)

-----

1 point by almkglor 6311 days ago | link

  foo:bar
  ==> (compose foo bar)
  ~foo
  ==> (complement foo)

  foo!bar
  ==> (foo 'bar)
  foo.bar ; no spaces
  ==> (foo bar)

-----