Page 1 of 1

NUMBERP predicate

Posted: Thu Oct 08, 2015 2:49 pm
by mrdelurk
I'm reading Touretzky's book on Common Lisp (gotta start somewhere with coding...), and just arrived to the NUMBERP function.
It's pretty clear what it does, what I wonder is, how. (What math calculations it is built of.)
Is it an "input value is < infinity" type of deal, am I guessing in the right direction? Thank you

Re: NUMBERP predicate

Posted: Thu Oct 08, 2015 4:21 pm
by nuntius
In a dynamic language like Lisp, data values are "tagged" with information describing their type.
Numberp then checks whether the tag is of a numeric type.

These tags may be explicit (see the tag, length, value concept in ASN.1) or implicit (based on where it is stored).

Here are a couple links that may help.

https://github.com/fiveop/sbcl-memory-layout
http://www.cs.indiana.edu/~dyb/pubs/bibop.pdf

Re: NUMBERP predicate

Posted: Thu Oct 08, 2015 4:28 pm
by Goheeca
It doesn't involve calculations, it's checking value's type whether it falls under the number type. The values of primitive types are usually unboxed, although they are tagged.

Ahh nuntius was faster.

Re: NUMBERP predicate

Posted: Thu Oct 08, 2015 5:00 pm
by nuntius
I should add that some languages like TCL have functions that try to automatically coerce values from one datatype to another.
In these languages, numberp might be implemented using parsing rules like "[+-]?[0123456789]*[.]?[0123456789]+".

See also
https://en.wikipedia.org/wiki/Duck_typing
https://en.wikipedia.org/wiki/Type_system

Re: NUMBERP predicate

Posted: Thu Oct 08, 2015 5:08 pm
by mrdelurk
nuntius wrote:In a dynamic language like Lisp, data values are "tagged" with information describing their type.
Got it, like controller values in MIDI. I can see how this is more efficient than calculating each... thank you.