Arc Forumnew | comments | leaders | submitlogin
Any reason not to use "?" instead of "o" for optional parameters?
20 points by briandamgaard 6107 days ago | 34 comments
I appreciate the design choice to limit the "optional" parameter indicator to a single character instead of the "&optional" keyword from Common Lisp. However, in my opinion the "o" keyword doesn't stand out as much as "?" would do. An example:

(fn foo (a b (o c 1)) <body>)

(fn foo (a b (? c 1)) <body>)

Mnemonically I think many people will agree with me that "?" is a better 1-character indicator for "optional". It can be read as "is the parameter supplied?".

The "?" choice seems so obvious and natural that I cannot believe is hasn't been considered during the language specification process, and it makes me think there must be some deep reason why it hasn't beeen chosen. Any comments?



7 points by rkts 6107 days ago | link

Even more annoying (to me) is that this means o can't be a variable in a destructuring bind:

  arc> (let (x) '(blah) x)
  blah

  arc> (let (o) '(blah) o)
  Error: "cadar: expects argument of type <cadarable value>; given ((o))"

-----

8 points by NickSmith 6107 days ago | link

Yeah, ? is far more obvious. To me, 'o' looks like any other little variable.

-----

8 points by pg 6107 days ago | link

I want to conserve ? for future use as ssyntax.

-----

4 points by nex3 6107 days ago | link

What about =? This would make a lot of sense for optional parameters with defaults, because it signifies assigning to the parameter if it's not given.

Granted, it would make less sense for just-plain-optional params, but it would be easier to visually pick out of the param list than o.

-----

3 points by shiro 6106 days ago | link

But isn't it possible that you have foo?bar as ssyntax and a lone ? for other purpose?

-----

1 point by nex3 6105 days ago | link

But what if he wants to conserve the lone ? as well?

-----

1 point by shiro 6105 days ago | link

Well we can only speculate. He said he wants to reserve '?' for ssyntax, and I pointed out '?' in ssyntax and lone '?' can coexist. If he also reserve lone '?', that's his decision.

-----

3 points by rkts 6107 days ago | link

Another (fairly obvious) idea: since optional parameters can't be followed by non-optional ones, just have a single ? for all optional parameters, as in CL:

  (fn (a b ? (c 3) (d 4)) ...)
This is shorter and mirrors the dot notation for rest parameters.

-----

4 points by pg 6107 days ago | link

I wanted to leave open the option of other types of parameters besides optional ones.

-----

2 points by bogomipz 6105 days ago | link

Does the suggestion really close that door? For instance, if you wanted to add keyword arguments, they could go like this:

  (fn (a b ? (c 3) (d 4) ! (e 5) (f 6) . rest) ...)
Combining all four argument flavors in the same function is of course not a good idea.

-----

1 point by kennytilton 6103 days ago | link

Looks like how common lisp works. And agreed: mixing optional with keyword args would be a nasty thing to do to users. Probably they saw that it was /possible/ and said sure, why not?

-----

4 points by jgrahamc 6107 days ago | link

Wouldn't

(fn foo (a b (c 1)) <body> )

be even cleaner?

-----

6 points by rkts 6107 days ago | link

No: parameter lists in Arc are destructuring.

-----

2 points by ryantmulligan 6107 days ago | link

Another language I have encountered uses the ? to mean optional.

http://haxe.org/ref#optional_arguments

On a different vein: this language reference page is probably the best language reference I've ever seen for a language.

-----

3 points by tokipin 6107 days ago | link

i prefer o. it's a nice-looking simple letter. ? stands out uglily

-----

2 points by sjs 6107 days ago | link

I think it's pretty important that we be able to write

  arc> ((fn ((o o o)) o) "bar!")

-----

2 points by parenthesis 6107 days ago | link

Another possibility would be a solitary & (echoing, as mentioned, &optional in CL).

-----

1 point by AndyBoySouthPas 6105 days ago | link

In CL I use named keyword arguments much more than optional ones, so I would want to keep single character prefix for keywords. This leads to a possibility: (&& x) would signify optional, (& x) would signify keyword.

-----

3 points by araujo 6107 days ago | link

I also find the single letter 'o' kind of confusing.

I like the mnemonic 'opt?' keyword:

   (def inc (n (opt? z 1))
    (+ n z))
Well, just my 2 cents

-----

2 points by lojic 6106 days ago | link

In that case, I'd vote for &opt

-----

1 point by gmosx 6105 days ago | link

I like opt? and ?

o is confusing and not very readable

-----

2 points by bcater 6107 days ago | link

"?" takes 2 key presses to make, while "o" takes only 1.

-----

3 points by shiro 6107 days ago | link

If one stroke of shift is so important, you should ditch () and use [] to represent the primary list structure :-)

(Or you would use Symbolics keyboard which you can type () without shifting.)

-----

2 points by vrk 6106 days ago | link

As a sidenote, square brackets are harder to type on Finnish/Swedish keyboards than ordinary parenthesis. The former requires Alt Gr + {8,9}, the latter Shift + {8,9).

(Why am I using the Finnish keyboard layout to edit code? A bad habit from the past, admittedly.)

-----

1 point by helium 6105 days ago | link

same in germany

-----

2 points by tokipin 6106 days ago | link

programmer dvorak: http://www.kaufmann.no/roland/dvorak/

been using it for about a year and dvorak in general for three or four. the difference in comfort vs qwerty is huge

-----

2 points by sacado 6106 days ago | link

or a french keyboard

-----

2 points by shiro 6106 days ago | link

good for french lispers! you can save 5-10% of typing!

-----

2 points by pg 6106 days ago | link

This is a good point, and in fact I consciously tried to make it possible to avoid shifting as much as possible.

-----

2 points by mdemare 6106 days ago | link

Yes, but of all the characters that need shift, "?" is surely the easiest.

-----

-1 points by bogomipz 6107 days ago | link

+1

-----

1 point by bogomipz 6106 days ago | link

Heh, it surprises me somewhat that expressing positive credit to the submitter results in being modded down.

-----

6 points by ryantmulligan 6106 days ago | link

I think that people want comments to have value in them. The best example of why this might get downmodded is if you look at it on the comments page it just looks like +1 without any context. So in that case it looks like a pretty vacuous comment. I think that if you enjoy a submission just upmod it. If you have something to add to the conversation add it.

-----

2 points by nostrademons 6106 days ago | link

There's also the voting arrow to express +1... ;-)

-----