Arc Forumnew | comments | leaders | submitlogin
1 point by d0m 5214 days ago | link | parent

Doesn't it make a little bit less pretty?

(foreach x in '(1 2 3)) vs (foreach x :in '(1 2 3)) ?

I'm sure you have good reasons to use this convention.. mind sharing them?



2 points by evanrmurphy 5214 days ago | link

I think the colon is his convention for within the definition, as a visual marker to distinguish keyword parameters from others. When you later call a function or macro defined as such, you won't need to prepend the colon to arg you're passing (similar to how mine was called in within the definition but could be fruitloops when I called it).

Edit: On second thought, probably does use the colon when calling the function as well.

-----

3 points by shader 5213 days ago | link

The colon is a standby from other lisps; Common Lisp would intern symbols starting with : to a special KEYWORD symbol table.

That was important because you could do things like keyword based arguments to functions, etc. i.e. if you had a function that was defined as

  (defun greet (&key (a "Hello") (b "World")) 
    (print a " " b))
then you could call it like:

  >(greet)
  Hello World
  >(greet :b "Bob")
  Hello Bob
  >(greet :b "Alice" :a "Yo")
  Yo Alice
etc. As you can see, it's a lot more flexible than "traditional" optional arguments, since you can specify any of them, and in any order.

-----

1 point by akkartik 5212 days ago | link

Yes I've been using the : in calls as well, but as I wrote the comment it occurred to me that I didn't have to. Either works.

-----

2 points by akkartik 5212 days ago | link

The prettiness wasn't a concern; as programmers we're used to needing hyphens or underscores, to ignoring parentheses and focusing on indentation. The colon's like that.

-----