From 395aad915a98aaeea721fcf8d24baec989a13154 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 21 Mar 2016 02:34:10 -0400 Subject: fix formatting on a couple of pages --- public/make-memoize.md | 61 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'public/make-memoize.md') diff --git a/public/make-memoize.md b/public/make-memoize.md index 03bb2dc..64f4f5f 100644 --- a/public/make-memoize.md +++ b/public/make-memoize.md @@ -3,6 +3,7 @@ A memoization routine for GNU Make functions --- date: "2014-11-20" license: WTFPL-2 +markdown_options: "-markdown_in_html_blocks" --- I'm a big fan of [GNU Make][make]. I'm pretty knowledgeable about it, @@ -29,21 +30,21 @@ unsuitable for my needs. So, I implemented my own, more flexible memoization routine for Make. - # This definition of `rest` is equivalent to that in GMSL - rest = $(wordlist 2,$(words $1),$1) - - # How to use: Define 2 variables (the type you would pass to $(call): - # `_NAME_main` and `_NAME_hash`. Now, `_NAME_main` is the function getting - # memoized, and _NAME_hash is a function that hashes the function arguments - # into a string suitable for a variable name. - # - # Then, define the final function like: - # - # NAME = $(foreach func,NAME,$(memoized)) - - _main = $(_$(func)_main) - _hash = __memoized_$(_$(func)_hash) - memoized = $(if $($(_hash)),,$(eval $(_hash) := _ $(_main)))$(call rest,$($(_hash))) +
# This definition of `rest` is equivalent to that in GMSL
+rest = $(wordlist 2,$(words $1),$1)
+
+# How to use: Define 2 variables (the type you would pass to $(call):
+# `_NAME_main` and `_NAME_hash`.  Now, `_NAME_main` is the function getting
+# memoized, and _NAME_hash is a function that hashes the function arguments
+# into a string suitable for a variable name.
+#
+# Then, define the final function like:
+#
+#     NAME = $(foreach func,NAME,$(memoized))
+
+_main = $(_$(func)_main)
+_hash = __memoized_$(_$(func)_hash)
+memoized = $(if $($(_hash)),,$(eval $(_hash) := _ $(_main)))$(call rest,$($(_hash)))
However, I later removed it from the Makefile, as I [re-implemented][reimplement] the bits that it memoized in a more efficient way, such that memoization @@ -53,21 +54,21 @@ Later, I realized that my memoized routine could have been improved by replacing `func` with `$0`, which would simplify how the final function is declared: - # This definition of `rest` is equivalent to that in GMSL - rest = $(wordlist 2,$(words $1),$1) - - # How to use: - # - # _NAME_main = your main function to be memoized - # _NAME_hash = your hash function for parameters - # NAME = $(memoized) - # - # The output of your hash function should be a string following - # the same rules that variable names follow. - - _main = $(_$0_main) - _hash = __memoized_$(_$0_hash) - memoized = $(if $($(_hash)),,$(eval $(_hash) := _ $(_main)))$(call rest,$($(_hash))) +
# This definition of `rest` is equivalent to that in GMSL
+rest = $(wordlist 2,$(words $1),$1)
+
+# How to use:
+#
+#     _NAME_main = your main function to be memoized
+#     _NAME_hash = your hash function for parameters
+#     NAME = $(memoized)
+#
+# The output of your hash function should be a string following
+# the same rules that variable names follow.
+
+_main = $(_$0_main)
+_hash = __memoized_$(_$0_hash)
+memoized = $(if $($(_hash)),,$(eval $(_hash) := _ $(_main)))$(call rest,$($(_hash)))
Now, I'm pretty sure that should work, but I have only actually tested the first version. -- cgit v1.2.3