alexander.m.cecile
2019-5-13 13:01:55

@alexander.m.cecile has joined the channel


diallo.ms
2019-5-13 18:51:59

Hello,

I am studying ‘for loops’ and working on the following exercice: reformulate the following example using the existing abstractions in ISL+: (require 2htdp/abstraction) (for/sum ([c "abc"]) (string->int c))

Here is my answer: (foldr + 0 (map (lambda (x) (string->int x)) '("a" "b" "c")))

My answer comprises 2 steps: - creationg a list of numbers (corresponding to each character) through map - summing the numbers of the list thanks to foldr

My question: is there a solution that requires only 1 step?


plragde
2019-5-13 19:16:47

Yes, there is. Try to delay the string-to-int conversion until you absolutely need the int. ISL+ also has string->list which will help.


diallo.ms
2019-5-13 19:20:14

ok, I’ll look into it. Thanks!