Functional Programming in Java, Second Edition: p 151 "func" instead of "memoizedFunction"

@venkats

At 2/3rd of the page, we read;

Within the computeMaxProfit() method, we perform our task, and when it’s time to recurse we route the call to func

func should be memoizedFunction, as used in the example code.

This will return quickly if the value has been cached or memoized.

Aren’t those two words equivalent? So just:

This will return quickly if the value has been cached.

But one may want to note at the start of this chapter that “cached” and “memoized”/“memoing” are synonyms (I would say)

P.S.

The example code uses alternatingly length and rodLength as name for the input parameter; this should be unified.

In this case then one could write:

    public int maxProfitMemoized(final int length) {
        BiFunction<Function<Integer, Integer>, Integer, Integer> biFunction = this::computeMaxProfit;
        return Memoizer.callMemoized(biFunction, length);
    }

The above also emphasizes the fact that this::computeMaxProfit actually maps to BiFunction<Function<Integer, Integer>, Integer, Integer>, i.e. actually allows the compiler to create an anonymous implementation of BiFunction<Function<Integer, Integer>, Integer, Integer> that calls this::computeMaxProfit, something that is not entirely self-evident.

P.P.S.

In an article by David S. Warren, “Memoing for Logic Programs”, the following reference for “memoing” is given:

“Memo” Functions and Machine Learning

https://www.nature.com/articles/218019a0

@dtonhofer

Hi David,

Many thanks for identifying places for improvement, with this and earlier comments. I will get a hand on the book in a couple of weeks to make final edits before it goes off to typesetting. I will address each of your suggestions at that time. Much appreciated. I will make sure to thank you in the book as well.

Regards,

Venkat

Thank you Venkat,

I will continue to press on, currently at the end Chapter 8 (“Optimizing Recursions”), and post my notes.

Sometimes I go quite far in the suggestions, especially for the code, please do not take offense.

With best regards,

– David

Thank you, David. I really appreciate the suggestions and will review them and address as necessary. Thank you so much for your time and attention to these details.

1 Like

Addressed the suggestions for parameter name and also reference to func. Thank you.

1 Like