What the heck is *unbound* ?

Using Nyquist scripts in Audacity.
Post and download new plug-ins.
Forum rules
If you require help using Audacity, please post on the forum board relevant to your operating system:
Windows
Mac OS X
GNU/Linux and Unix-like
Post Reply
Paul L
Posts: 1788
Joined: Mon Mar 11, 2013 7:37 pm
Operating System: Please select

What the heck is *unbound* ?

Post by Paul L » Fri Nov 22, 2013 2:46 am

I discovered this weird thing in the *obarray*.

Do this:

Code: Select all

(let ((x 'car))
(print x))
Nyquist prints
CAR
Unsurprising, right? But now do this:

Code: Select all

(let ((x '*unbound*))
(print x))
Nyquist says
error: unbound variable - X
if continued: try evaluating symbol again
Function: #<FSubr-LET: #7cf6238>
Arguments:
((X (QUOTE *UNBOUND*)))
(PRINT X)
1>
Weird!

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: What the heck is *unbound* ?

Post by steve » Fri Nov 22, 2013 4:24 am

*unbound* is a system constant that is equivalent to "no value".
Normally if you use LET, SETQ or SETF, you are binding a symbol (or field) to a value, but with (SETQ x '*UNBOUND*) you are doing the opposite - you are binding to "no value", or to put it another way you are "un-binding" x.

Code: Select all

(setq x 10)
(print x) ; prints "10"
(setq x '*unbound*)
(print x) ; prints "error: unbound variable - X"
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: What the heck is *unbound* ?

Post by steve » Fri Nov 22, 2013 4:40 am

*SCRATCH* is a special variable in that it survives from one run to the next.

This is not a good example of how to use *SCRATCH* but I think it's quite a good example of how '*UNBOUND* works.
Try running this code a few times:

Code: Select all

(print *scratch*)
(if (not (boundp '*scratch*))
    (setq *scratch* "*scratch* now has a string value")
    (progn
      (print *scratch*)
      (setq *scratch* '*unbound*)))
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Paul L
Posts: 1788
Joined: Mon Mar 11, 2013 7:37 pm
Operating System: Please select

Re: What the heck is *unbound* ?

Post by Paul L » Fri Nov 22, 2013 4:52 am

The funny thing was, I tried to make a list of all things in *obarray* and iterate it with dolist. But at a certain point, my local loop variable was bound to '*unbound* which was in the list, and the code in the body of the loop made an error because my local variable was unbound!

The workaround was to do (mapcar #'list symbols), and then my loop variable was bound to '(*unbound*) and not '*unbound*, and then I could take the car to get the symbol just like any other.

Common Lisp: the Language says there should be makunbound an fmakunbound functions for unbinding symbols, but as we know XLisp does not implement all of that Common Lisp standard.

Post Reply