3 ms·
This critique is just a bit unfair to Scheme, given his first couple examples being used to show how cumbersome it is compared to Miranda. Normally you'd have a
by ehsanu1 15y ago
This critique is just a bit unfair to Scheme, given his first couple examples being used to show how cumbersome it is compared to Miranda. Normally you'd have a fold function defined and use that instead:
(define (sum x) (fold + 0 x))
Writing it this way is more idiomatic Scheme, and isn't really cumbersome.
- akkartik 15y agoI have never seen this sort of definition in scheme. Can you provide a pointer or three to show that this is 'idiomatic'?
- PurplePanda 15y agoSee chapter 1.3 of SICP. It talks about the motivation and usage of higher order abstractions in general, and also about fold specifically, which they call 'accumulate'.
- akkartik 15y agoAh yes, thanks, we discussed it several times over on the arc forum (e.g. http://arclanguage.org/item?id=10791 http://arclanguage.org/item?id=10791) I was asking more about code in the wild that uses accumulate instead of the naive recursive formulation. That's typically what we mean by idiomatic. I see foldl often in haskell, but rarely in scheme. I'm not disagreeing that it's a great idea, just that this is how it 'would have been written'. Personally I find the naive recursive formulation plenty clear.
- omaranto 15y agoMaybe you've never seen it in Scheme because Scheme's standard library is so anemic. Of the usual FP higher order list manipulation functions it only provides map! And people are understandably reluctant to have everyone write their own differently named library functions. The situation has probably improved since the list manipulation SRFI (I think it is SRFI-1), as those are quite popular and available in most implementations.