
dtonhofer
Functional Programming in Java, Second Edition: p 151 "func" instead of "memoizedFunction"
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 tofunc
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
Marked As Solved

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

venkats
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










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /zig
- /scala
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /neovim