ref: 63558a798d4b3a1833f097a9b8d8c27e28402463
parent: 22ae0e366f8678ac2df9104ba37c2e2ab9c0190d
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Wed Nov 27 04:41:17 EST 2024
add "makunbound"
--- a/builtins.c
+++ b/builtins.c
@@ -163,6 +163,15 @@
return args[1];
}
+BUILTIN("makunbound", makunbound)
+{
+ argcount(nargs, 1);
+ symbol_t *sym = tosymbol(args[0]);
+ if(!isconstant(sym))
+ sym->binding = UNBOUND;
+ return FL(t);
+}
+
static void
global_env_list(symbol_t *root, value_t *pv)
{
--- a/test/unittest.lsp
+++ b/test/unittest.lsp
@@ -360,9 +360,18 @@
(assert (equal? (append '(1 2)) '(1 2)))
(assert (equal? (append '(1 2) '(3 4)) '(1 2 3 4)))
+;; infinite list
(define a '(1))
(set-cdr! a a)
(assert (equal? (length a) +inf.0))
+
+;; unbinding
+(define abc 1)
+(assert (equal? (bound? 'abc) #t))
+(assert (equal? (eval '(+ abc 1)) 2))
+(makunbound 'abc)
+(assert (equal? (bound? 'abc) #f))
+(assert-fail (eval '(+ abc 1)))
;; make many initialized tables large enough not to be stored in-line
(for 1 100 (λ (i)