Skip to content

Commit 65fae37

Browse files
committed
added memo, defmemo
1 parent 8054db9 commit 65fae37

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ OPTIONS:
3636
`* + - / < > apply bound car ccc cdr close coerce cons cos dir dir-exists disp ensure-dir err expt eval file-exists flushout infile int is len log macex maptable mod mvfile newstring outfile pipe-from quit rand read readline rmfile scar scdr sin sqrt sread stderr stdin stdout string sym system t table tan trunc type write writeb`
3737

3838
## Library
39-
`++ -- <= = >= aand abs accum acons adjoin afn aif alist all alref and andf assoc atend atom avg before best bestn caar cadr carif caris case caselet catch cddr check commonest compare complement compose consif conswhen copy copylist count counts cut dedup def do1 dotted drain each empty even fill-table find firstn flat for forlen get idfn iflet in insert-sorted insort insortnew intersperse isa isnt iso join keep keys last len< len> let list listtab loop map map1 mappend max med median mem memtable merge mergesort min mismatch most multiple n-of nearest no noisy-each nor nthcdr number obj odd on only ontable or orf pair point pop pos positive pr prn pull push pushnew quasiquote rand-choice rand-elt range reclist recstring reduce reinsert-sorted rem repeat retrieve rev rfn rotate round roundup rreduce set single some sort split sref sum summing swap tablist testify tuples trues union uniq unless until vals w/table w/uniq when whenlet while whiler whilet wipe with withs zap`
39+
`++ -- <= = >= aand abs accum acons adjoin afn aif alist all alref and andf assoc atend atom avg before best bestn caar cadr carif caris case caselet catch cddr check commonest compare complement compose consif conswhen copy copylist count counts cut dedup def defmemo do1 dotted drain each empty even fill-table find firstn flat for forlen get idfn iflet in insert-sorted insort insortnew intersperse isa isnt iso join keep keys last len< len> let list listtab loop map map1 mappend max med median mem memo memtable merge mergesort min mismatch most multiple n-of nearest no noisy-each nor nthcdr number obj odd on only ontable or orf pair point pop pos positive pr prn pull push pushnew quasiquote rand-choice rand-elt range reclist recstring reduce reinsert-sorted rem repeat retrieve rev rfn rotate round roundup rreduce set single some sort split sref sum summing swap tablist testify tuples trues union uniq unless until vals w/table w/uniq when whenlet while whiler whilet wipe with withs zap`
4040

4141
## Features
4242
* Reference counting garbage collection (shared_ptr)

arc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#endif
3535

3636
namespace arc {
37-
constexpr auto VERSION = "0.26.1";
37+
constexpr auto VERSION = "0.27";
3838

3939
enum type {
4040
T_NIL,

library.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,4 +1027,13 @@ non-nil."
10271027
"Inserts 'x' between the elements of 'ys'."
10281028
(and ys (cons (car ys)
10291029
(mappend [list x _] (cdr ys)))))
1030+
(def memo (f)
1031+
"Turns function 'f' into a _memoized_ version that also stores results returned
1032+
by args passed in, so that future calls with the same inputs can save work."
1033+
(let cache (table)
1034+
(fn args (aif (cache args) it (= (cache args) (apply f args))))))
1035+
1036+
(mac defmemo (name parms . body)
1037+
"Like [[def]] but defines a memoized function. See [[memo]]."
1038+
`(assign ,name (memo (fn ,parms ,@body))))
10301039
)EOF";

0 commit comments

Comments
 (0)