Arc Forumnew | comments | leaders | submitlogin
Proposal: "." Syntax Sugar
1 point by dpara 6312 days ago | 12 comments
What it can do:

equal variable names mean equal types (defmethod put (A b c)...) (defmethod pop (A d x)...) (defmethod plop(A d z)...)

now these methods can be evaluated with the following forms: (pop A d x),(A.pop d x), (A d.pop x), (a d x.pop)

Pros: -it can make some function calls more readable -allows editors to display the ääh "what can be done with the current parameters"-list, which I find incredibly handy -java/c++/... programmers recognize it

Cons: - dunno, extra language construct?

So what did I miss?



1 point by jmatt 6312 days ago | link

I think when keyword parameters are added that this will be less of an issue for java/c programmers. See CL or gauche scheme for keyword parameters.

-----

1 point by dpara 6312 days ago | link

One of my problems with lisp is that is hard for me to find (fast) what can be done with a specific data type/object.

By typing any (number of) dataype(s) first and then some <unused character> the editor can give better guesses at what I want. And that can be done by allowing the functionname to stand anywhere in the brackets.

-----

1 point by jmatt 6312 days ago | link

You just need to properly set up an IDE. Personally I use emacs and slime. Though there are other options. I have autocomplete that works better than intellisense (visual studio). My experience is intellisense in VS2008 schools eclipse.

It's doable you just have to put in some time to learn emacs / slime or a similar lisp IDE.

http://common-lisp.net/project/slime/

See the screencasts and tutorials section to get up to speed fast(er).

-----

1 point by eds 6310 days ago | link

Mind letting us in on how to get autocomplete to work with emacs and slime? (Or is there howto for it somewhere?)

-----

1 point by jmatt 6308 days ago | link

Sure.

Meta-TAB -> slime-complete-symbol

and

C-c M-i -> slime-fuzzy-complete-symbol

It can be found in the manual here:

http://common-lisp.net/project/slime/doc/html/Programming-He...

Also you can access documentation including the common lisp hyperspec:

http://common-lisp.net/project/slime/doc/html/Documentation....

It's an uphill battle to figure it out the first time but it gets easier.

-----

1 point by dpara 6312 days ago | link

ok, maybe . is not so perfect... because of the dotted pairs (a . b), but the idea essentially stays the same maybe giving the dotted pair the semicolon ,

-----

2 points by almkglor 6312 days ago | link

Both . and : are already used:

  foo.bar ==> (foo bar)
  foo:bar ==> (compose foo bar)
  (foo:bar nitz) ==> (foo (bar nitz))
Also, I don't quite get what you want the equivalent call to be.

-----

2 points by jmatt 6312 days ago | link

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)

-----