awwx.ws

localt0

Use t as a local variable

http://awwx.ws/localt0.patch:

--- a/ac.scm	2010-02-20 12:15:04.000000000 -0500
+++ b/ac.scm	2010-02-20 12:39:20.000000000 -0500
@@ -397,8 +397,8 @@
       (let ((b (ac b1 (ac-dbname! a env))))
         (list 'let `((zz ,b))
                (cond ((eqv? a 'nil) (err "Can't rebind nil"))
-                     ((eqv? a 't) (err "Can't rebind t"))
                      ((lex? a env) `(set! ,a zz))
+                     ((eqv? a 't) (err "Can't rebind t"))
                      (#t `(namespace-set-variable-value! ',(ac-global-name a) 
                                                          zz)))
                'zz))

Because using a local variable with the same name as a global variable doesn’t affect the global variable, it would do no harm to use t as a local variable if you wanted to:

(let t 3
  (++ t)
  t)

However setting t is disallowed in arc3.1, even if the variable is local:

arc> (let t 3
       (++ t)
       t)
Can't rebind t

This hack allows t to be set when it’s a local variable:

arc> (let t 3
       (++ t)
       t)
4
arc> t
t
arc> (++ t)
Can't rebind t

t but not nil

Why not do the same thing for nil?

Since nil is the empty list, this code:

(let nil 3 nil)

is the same as this list destructuring:

(let () 3 nil)

which assigns 3 to no variables, rather than making nil a local variable.

arc> (let nil 3 nil)
nil

Besides, I use the global nil explicitly in my code a lot more than I use the global t explicitly, so it’s more useful to me to be able to use t as a local variable than it is to be able to use nil as one.

License

Same as Arc.

Contact me

Twitter: awwx
Email: andrew.wilcox [at] gmail.com