I have a problem with Mark Mahoney "An Animated Introduction to Clojure" Chapter 3 Interest in an account, but in GNU #guile. What should I write here? https://pastebin.com/W40WLtxa
Conversation
Notices
-
spectrumgomas@functional.cafe's status on Thursday, 17-Jun-2021 21:27:40 CEST spectrumgomas -
Abbie Normal (abbienormal@social.device5.co.uk)'s status on Thursday, 17-Jun-2021 22:00:56 CEST Abbie Normal I see in the clojure version they use a for cycle
That's strange
What does the clojure procedure return ?
A list ? Or maybe a number ?
Or anything else ?
If, as I think, you want a list, you could write it like this:
(map (lambda (interest-function) (interest-function principal year-number)) interest-functions)
In conversation permalink -
spectrumgomas@functional.cafe's status on Thursday, 17-Jun-2021 22:00:56 CEST spectrumgomas @AbbieNormal (interest-functions (map value-after-years-generator rates)) creates a list of partial functions in interest-functions. Now I want apply all these functions and create a list with the results.
In conversation permalink -
Abbie Normal (abbienormal@social.device5.co.uk)'s status on Thursday, 17-Jun-2021 22:21:19 CEST Abbie Normal doesn't this work ?
(map (lambda (interest-function) (interest-function principal year-number)) interest-functions)
In conversation permalink -
spectrumgomas@functional.cafe's status on Thursday, 17-Jun-2021 22:21:19 CEST spectrumgomas @AbbieNormal I don't think so. interest-functions isn't the list of arguments. It's a list of partial functions.
In conversation permalink Ekaitz Zárraga 👹 repeated this. -
spectrumgomas@functional.cafe's status on Thursday, 17-Jun-2021 22:47:26 CEST spectrumgomas @AbbieNormal Ah, I've never seen map over a list of functions before. Then that's probably the solution. Thanks!
In conversation permalink -
Abbie Normal (abbienormal@social.device5.co.uk)'s status on Thursday, 17-Jun-2021 22:47:27 CEST Abbie Normal I know and I apply them, in that code 🙂
In conversation permalink spectrumgomas and Ekaitz Zárraga 👹 repeated this. -
Abbie Normal (abbienormal@social.device5.co.uk)'s status on Thursday, 17-Jun-2021 22:47:27 CEST Abbie Normal you can map over a list of functions
map applies that "lambda" on every function in interest-functions
and the lambda calls every one of those partial functions with "principal" and "year-number"
In conversation permalink
-