NUMBERP predicate

Discussion of Common Lisp
Post Reply
mrdelurk
Posts: 7
Joined: Thu Oct 08, 2015 1:43 pm

NUMBERP predicate

Post by mrdelurk » Thu Oct 08, 2015 2:49 pm

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

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: NUMBERP predicate

Post by nuntius » Thu Oct 08, 2015 4:21 pm

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

Goheeca
Posts: 271
Joined: Thu May 10, 2012 12:54 pm
Contact:

Re: NUMBERP predicate

Post by Goheeca » Thu Oct 08, 2015 4:28 pm

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.
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.

nuntius
Posts: 538
Joined: Sat Aug 09, 2008 10:44 am
Location: Newton, MA

Re: NUMBERP predicate

Post by nuntius » Thu Oct 08, 2015 5:00 pm

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

mrdelurk
Posts: 7
Joined: Thu Oct 08, 2015 1:43 pm

Re: NUMBERP predicate

Post by mrdelurk » Thu Oct 08, 2015 5:08 pm

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.

Post Reply