loops: having my cake and eating it too?
Apr. 27th, 2010 07:43 pmOne programming annoyance when writing loops is wanting to access each element of the list without passing the index, i.e. with code like:
I'm not aware of any solutions to this in current usage.
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)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)You can abbreviate the writeup even further if you're single-national Canadian.
(no subject)
Date: 2010-04-29 04:39 am (UTC)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)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)(no subject)
Date: 2010-04-29 05:33 pm (UTC)(no subject)
Date: 2010-04-30 04:57 am (UTC)(no subject)
Date: 2010-04-29 04:41 am (UTC)