dtonhofer

dtonhofer

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

Marked As Solved

venkats

venkats

Author of Programming Kotlin, Rediscovering JavaScript (and 6 other titles)

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

Also Liked

venkats

venkats

Author of Programming Kotlin, Rediscovering JavaScript (and 6 other titles)

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.

Where Next?

Popular Pragmatic Bookshelf topics Top

mikecargal
Title: Hands-on Rust: question about get_component (page 295) (feel free to respond. “You dug you’re own hole… good luck”) I have somet...
New
conradwt
First, the code resources: Page 237: rumbl_umbrella/apps/rumbl/mix.exs Note: That this file is missing. Page 238: rumbl_umbrella/app...
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
jskubick
I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint. As entered, the SwitchCompat changes color to hol...
New
oaklandgit
Hi, I completed chapter 6 but am getting the following error when running: thread 'main' panicked at 'Failed to load texture: IoError(O...
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
Henrai
Hi, I’m working on the Chapter 8 of the book. After I add add the point_offset, I’m still able to see acne: In the image above, I re...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
AstonJ
You might be thinking we should just ask who’s not using VSCode :joy: however there are some new additions in the space that might give V...
New
Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
AstonJ
Continuing the discussion from Thinking about learning Crystal, let’s discuss - I was wondering which languages don’t GC - maybe we can c...
New
rustkas
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
New
New

Latest in Functional Programming in Java, Second Edition

Functional Programming in Java, Second Edition Portal

Sub Categories: