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.

Popular Prag Prog topics Top

sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=&gt; (create-...
New
simonpeter
When I try the command to create a pair of migration files I get an error. user=&gt; (create-migration "guestbook") Execution error (Ill...
New
lirux
Hi Jamis, I think there’s an issue with a test on chapter 6. I own the ebook, version P1.0 Feb. 2019. This test doesn’t pass for me: ...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |&gt; handle_event() |&gt; render() but the correc...
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
taguniversalmachine
It seems the second code snippet is missing the code to set the current_user: current_user: Accounts.get_user_by_session_token(session["...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
AstonJ
Or looking forward to? :nerd_face:
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
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
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New

Latest in PragProg

View all threads ❯