setMissPolicy

Synopsis

setMissPolicy(%ohash, &closure)

Sets the miss policy for an ordered hash. The miss policy is called when a key with no associated value is requested. The ordered hash is then populated with the value returned by the miss policy closure.

Parameters

%ohash - the ordered hash to set the miss policy for

&closure - the miss policy closure. When called, the closure receives the following arguments:
ArgumentDescription
$1the ordered hash scalar
$2the original key (before string conversion)

Side Effects / Notes

Examples

# Memoization with Miss Policies: Fibonacci Sequence sub fib { local('%fhash'); %fhash = ohash(0 => 0L, 1 => 1L); setMissPolicy(%fhash, { return $1[$2 - 1] + $1[$2 - 2]; }); return %fhash[$1]; } println("fib[90]: " . fib(90L));

fib[90]: 2880067194370816120

See Also