Skip to content

Instantly share code, notes, and snippets.

@martialboniou
Created December 24, 2012 11:58
Show Gist options
  • Save martialboniou/4368997 to your computer and use it in GitHub Desktop.
Save martialboniou/4368997 to your computer and use it in GitHub Desktop.
CL version of destroy for Shen
\* This script is aimed to run on Shen 7.1 on any Common Lisp port *\
(package cl-destroy- [destroy-it]
(define simple-retract
X Vec -> (let Pos (hash X (limit Vec))
(vector-> Vec Pos (fail))))
(define retract
X Vec -> (let Pos (hash X (limit Vec))
Content (trap-error (<-vector Vec Pos) (/. (protect E) (error "no vector element to rectract")))
(do (vector-> Vec Pos (fail))
Content)))
\* (declare F []) yields a change-arity error *\
(define shen-destroy-help
X -> (error "~A is defined as a system function~%" X) where (element? X (value shen-*system*))
X -> (let Tables [shen-*property-vector*]
Lists [shen-*tracking* shen-*signedfuncs*]
(do
(map (/. Z (simple-retract X (value Z))) Tables)
(map (/. Z (set Z (remove X (value Z)))) Lists) X)))
\* in CL *\
(define destroy-it
X -> (do (trap-error (shen-destroy-help X) (/. E E))
((protect FMAKUNBOUND) X)
X)))
\* in JS *\
\* delete window.fn; // as delete works for object properties *\
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment