# HG changeset patch # User Steve Losh # Date 1542238951 18000 # Node ID 37133d1e538a92987489bf17f5b354f5db4ff9d4 # Parent 70497b31cb2476bf0916908521b4f025ba5b6bc9 Add ref diff -r 70497b31cb24 -r 37133d1e538a src/base.lisp --- a/src/base.lisp Wed Nov 14 18:31:39 2018 -0500 +++ b/src/base.lisp Wed Nov 14 18:42:31 2018 -0500 @@ -74,6 +74,21 @@ (defun pbpaste () (values (sh '("pbpaste") :output t))) +(defgeneric ref% (object key)) + +(defmethod ref% ((object hash-table) key) + (gethash key object)) + +(defmethod ref% ((object vector) key) + (aref object key)) + +(defun ref (object &rest keys) + (recursively ((object object) + (keys keys)) + (if (null keys) + object + (recur (ref% object (first keys)) (rest keys))))) + ;;;; Help --------------------------------------------------------------------- (defun first-letter (command) @@ -257,6 +272,11 @@ (throw :do-not-add-undo-state nil)) +;;;; Commands/Objects --------------------------------------------------------- +(define-command ref (object key) + (push! (ref object key))) + + ;;;; Commands/System ---------------------------------------------------------- (define-command doc (symbol) "Print the documentation for the symbol at the top of the stack."