Created
          November 22, 2023 05:08 
        
      - 
      
- 
        Save garlic0x1/039324859e8e05c0f0d7a9d26edbc4fd to your computer and use it in GitHub Desktop. 
    defmemo/int->int
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | ; depends on alexandria | |
| ; memoizes int->int functions in a mutable vec | |
| (defmacro defmemo/int->int (size name (in) &body body) | |
| (let ((memo-name (read-from-string (format nil "~a-memo" name)))) | |
| `(progn (defvar ,memo-name (make-array (+ 1 ,size) :initial-element nil)) | |
| (defun ,name (,in) | |
| (if-let ((memo (aref ,memo-name ,in))) | |
| memo | |
| (setf (aref ,memo-name ,in) (progn ,@body))))))) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment