Arc Forumnew | comments | leaders | submitlogin
4 points by nex3 6168 days ago | link | parent

I don't like the idea of binding in the order they're used - it seems like it would make a lot of uses impossible (at least without making it more verbose than a fn would have been).

It seems better and more concise to somehow specify the variables with numbers, presumably with some sort of prefix:

  ([- $1 $2 $3] 3 2 1)
  ([- \1 \2 \3] 3 2 1)
  ([- #1 #2 #3] 3 2 1)
We could even bind the prefix character itself to the second argument, to make the two-arg case even shorter:

  ([+ _ #] 2 1)


3 points by Zak 6168 days ago | link

I thought about using numbers like that too, but when I posted this I was too tired to remember why that might be a better idea. You're right - it would make more sense to use numbers, and if you're writing a function that's long enough that numbers would make it hard to read, use fn. Zero-indexed numbers with sigils to designate the place in the arg list are better.

  ([- $1 $2 $0] 1 3 2])
translates to

  ((fn ($0 $1 $2)
      (- $1 $2 $0))  1 3 2))
I don't like binding the sigil by itself to the second arg - it's starting to look like Perl. I'd even be in favor of eliminating the underscore and only using the sigil-number notation, with the special case that the sigil by itself is arg 0.

-----

1 point by dreeves 6164 days ago | link

That's what mathematica does:

(#1 - #2 - #3)&[3,2,1]

with # equivalent to #1.

(By the way, mathematica is all s-expressions (or rather, equivalently, McCarthy's m-expressions) underneath. You can call FullForm on any expression to strip away the syntactic sugar, eg, FullForm[a+b] => Plus[a,b]. Note the f[a,b] instead of (f a b). A nice thing about the commas is that you can throw in infix wherever it's convenient, like If[x>2+2, B, b] instead of If[Greater[x,Plus[2,2]], B, b]. The best lisp solution I've seen for that is curly sweet-expressions: http://www.dwheeler.com/readable/ )

-----

1 point by jimbokun 6168 days ago | link

([- (_ 1) (_ 2) (_ 0)] '(1 3 2))

What about that?

-----

1 point by Zak 6167 days ago | link

Adding parens to make it more "lispy"? I don't see the point, really. Also, why are you passing it a quoted list instead of the actual values you want?

-----

1 point by jimbokun 6167 days ago | link

Because this actually works in the current version of Arc. Maybe not quite as concise as the proposed syntax, but probably as close as you can get without adding syntax (at least that I can think of).

So you need to weigh the cost of adding more syntax to the language for the savings of "$1" vs. "(_ 1)".

-----

1 point by nex3 6167 days ago | link

Note that the latter is more than twice the size of the former, and that you'd also need to put the arguments to [] into a list prior to passing them into the fn. I'd say $1 is a pretty big win in terms of conciseness.

-----