Macro memoize

Introduction

This macro memoizes the result of a function or method. If the result for a given function/argument combination has already been memoized, that stored result will be returned. Otherwise, the function or method will be invoked with the specified argument, and the result will be stored and returned.

Syntax


	 memoize(object-variable, function, object)

where:

Because Synergy/DE does not have a functional IF statement (and my attempt to create one evaluates both the then and else clauses) this macro must be passed a variable into which to return the result. This variable must be declared as an object (@*), so you will probably need to cast it later on. The function should not be in quotes. You can pass any type for object, even primitives. Likewise, function may return any type, even ^val.

While memoize is convenient, you may find greater flexibility in using the underlying Memo class directly. See details below.

Class Memo

This class provides a framework for memoization based on an alphanumeric identifier (e.g., a function name) and an object (e.g., an argument). If you need more than one alphanumeric identifier, you can concatenate them with an appropriate delimiter. If you need more than one object, pass a list containing them (ls.Equals() evaluates to true if the lists have the same number of members and corresponding members yield true via object.Equals).

Member reference

static method retrieve

Memo.retrieve(a, object) => object2
This method returns the result previously stored for the combination of a and object, or ^null if no such result has been stored. The match for a is case-insensitive, while the match for object uses Object.Equals().

static method store

Memo.store(object2, a, object) => object2
This method stores a result (object2) for the combination of a and object, and returns object2. The match for a is case-insensitive, while the match for object uses Object.Equals().