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
NUMBERP predicate
Re: NUMBERP predicate
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
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
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.
Ahh nuntius was faster.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
Re: NUMBERP predicate
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
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
Got it, like controller values in MIDI. I can see how this is more efficient than calculating each... thank you.nuntius wrote:In a dynamic language like Lisp, data values are "tagged" with information describing their type.