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-28 07:00 pm (UTC)
From: [personal profile] chrisamaphone
yep, fn is lambda and '=>' is '.'.

it does enumerate. it applies the provided function (which takes the index as an argument) to every element of the list, and returns a list of the results. "appi" can be used if you just want to apply some effectful computation to every element, like printing it.

(no subject)

Date: 2010-04-29 04:25 am (UTC)
From: [identity profile] bhudson.livejournal.com
The writeup looked frightening. "Vector.mapi, comma, you dumbass" would have worked better than starting from first principles and then pointing out that actually you don't need to implement quite everything.

You can abbreviate the writeup even further if you're single-national Canadian.

(no subject)

Date: 2010-04-29 04:39 am (UTC)
From: [personal profile] chrisamaphone
yeah, well, maybe if some verbose jerk hadn't gone and stolen the opportunity. :P

but yeah i dunno, posting the actual implementation seems pedagogically more necessary in the ML example since a "map" call is totally bizarre-looking to someone used to seeing a loop structure.

(no subject)

Date: 2010-04-29 01:57 pm (UTC)
From: [identity profile] bhudson.livejournal.com
But if you're trying to teach someone how to write mapi (fn (x, i) => printf I'" => "S $ i x) thelist, and you're worried they won't understand that line of code, why expect they'll get any illumination out of the implementation of mapi?

This is a problem I've frequently had with CMU SML people. I'm used to a world that believes in abstraction. This method of giving the detailed implementation first is the very antithesis of abstraction.

(no subject)

Date: 2010-04-29 04:30 pm (UTC)
From: [personal profile] chrisamaphone
yeah, you make a good point. i think in this case my instincts were just wrong. i'm going to have to think about why i had them.

(no subject)

Date: 2010-04-29 05:33 pm (UTC)
From: [identity profile] wjl.livejournal.com
For me it was just truth in advertising: SML doesn't come with a List.mapi. But also, there's the point to be made that in a higher-order language, you're not tied to whatever looping constructs "come with" the language -- you can just roll your own, and people frequently do.

(no subject)

Date: 2010-04-30 04:57 am (UTC)
From: [identity profile] bhudson.livejournal.com
I suspect that's part of the difference between people who care about languages qua languages, rather than people who care about languages as problem-solving tools. Looking at it as a language, I *hate* python and its utter lack of static typechecking. As a tool, it's pretty decent - it's got a huge user community who have hit the same problems I hit, and have developed a rich set of libraries. SML isn't (sadly) even an option right now: I'm writing plugins for an application software, and for some odd reason there just isn't an SDK in SML.

(no subject)

Date: 2010-04-29 04:41 am (UTC)
From: [identity profile] wjl.livejournal.com
my apologies for being civil? :P

February 2020

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

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags