37133d1e538a
Add ref
author | Steve Losh <steve@stevelosh.com> |
---|---|
date | Wed, 14 Nov 2018 18:42:31 -0500 |
parents | 70497b31cb24 |
children | a08b75bd86ad |
branches/tags | (none) |
files | src/base.lisp |
Changes
--- 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."