gusl: (Default)
[personal profile] gusl
One programming annoyance when writing loops is wanting to access each element of the list without passing the index, i.e. with code like: for (el in list) while simultaneously wanting to know the index without writing i=0 and i++.

I'm not aware of any solutions to this in current usage.

(no subject)

Date: 2010-04-29 05:19 am (UTC)
From: [identity profile] gustavolacerda.livejournal.com
IMHO

mapi (fn (i, el) => ... code(i, el) ...) list

is less elegant than

for i, v in enumerate(list):
  code(i, v)

because

* the Python fewer tokens
* in the ML, what the heck is "..." anyway?
* in the ML, one explicitly writes the lambda. One of the reasons Paul Graham invented Arc is because "lambda(x)" appears too often in Lisp.
Edited Date: 2010-04-29 05:20 am (UTC)

(no subject)

Date: 2010-04-29 01:32 pm (UTC)
From: [identity profile] wjl.livejournal.com
The "..." isn't ML -- just metasyntax for "some junk goes here".

(no subject)

Date: 2010-04-29 01:40 pm (UTC)
From: [identity profile] wjl.livejournal.com
Regarding the lambda, in ML's defense, it is at least shorter and more distinctive than LISP's. Haskell takes it to the exteme, with "\ x ->" instead of "lambda (x)". Macros for inventing new binding constructs might be nice, I suppose, but there's a trade off: if everyone invents their own syntax, nobody can read anybody else's code anymore, or even be able to tell which variables are bound.

(no subject)

Date: 2010-04-29 01:44 pm (UTC)
From: [identity profile] wjl.livejournal.com
In fact, the ML has one fewer token if you count the implicit "indent" and "unindent" tokens required by Python's syntax :)

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags