Author Topic: what number is for nil?  (Read 4487 times)

0 Members and 1 Guest are viewing this topic.

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
what number is for nil?
« on: June 20, 2012, 01:37:52 PM »
look at this:

_$ (> nil 0)
nil
_$ (< nil 0)
T
_$ (< nil -2147483647)
T
_$ (* -1e200 1e200)
-1.#INF
_$ (< nil -1.#inf)
nil

So,what number is for nil?
maybe it's a stupid question.just a little curious.
I am a bilingualist,Chinese and Chinglish.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: what number is for nil?
« Reply #1 on: June 20, 2012, 02:06:43 PM »
nil is not a number, but rather a null value, and hence '<' and '>' will rank a symbol with value over one without.

Consider also:

Code - Auto/Visual Lisp: [Select]
  1. _$ (< nil "a")
  2. T

BlackBox

  • King Gator
  • Posts: 3770
Re: what number is for nil?
« Reply #2 on: June 20, 2012, 02:13:34 PM »
** Lee posted before I could. LoL

Nil does not have a constant numerical value, as for example, Pi.

A simple, perhaps incomplete, way of looking at this is that Nil = Nothing (VB), or Null (C#), where zero ( 0 ) is in fact greater than nothing, to use your example.

... Make sense?
"How we think determines what we do, and what we do determines what we get."

Dommy2Hotty

  • Swamp Rat
  • Posts: 1127
Re: what number is for nil?
« Reply #3 on: June 20, 2012, 04:48:06 PM »
A simple, perhaps incomplete, way of looking at this is that Nil = Nothing

I am Nil  :cry:

BlackBox

  • King Gator
  • Posts: 3770
Re: what number is for nil?
« Reply #4 on: June 20, 2012, 05:38:37 PM »
A simple, perhaps incomplete, way of looking at this is that Nil = Nothing

I am Nil  :cry:

You're a member of TheSwamp, aren't you?  :-)
"How we think determines what we do, and what we do determines what we get."

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: what number is for nil?
« Reply #5 on: June 20, 2012, 06:40:58 PM »
We, are The Knights Who Say Nil.  In return for our assistance we demand you bring us... A SHRUBBERY!   :lmao:
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: what number is for nil?
« Reply #6 on: June 20, 2012, 06:55:12 PM »

what number is for nil?

number != 42;
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: what number is for nil?
« Reply #7 on: June 21, 2012, 04:23:51 AM »
A simple, perhaps incomplete, way of looking at this is that Nil = Nothing (VB), or Null (C#), where zero ( 0 ) is in fact greater than nothing, to use your example.
A "less simple"  ;)   "more complete way"  :lmao:

http://en.wikipedia.org/wiki/Null_pointer#Null_pointer

So in C/C++ a NULL is some constant integer value which is defined as a memory address which is impossible to be used. At least in most implementations of C/C++. This is probably why non-lispers think of nil as having some sort of value constant.

In Lisp, nil is the "base" symbol ... it's equivalent to an empty list. In AutoLisp it IS actually an empty list:
Code: [Select]
(= nil '()) ;returns T
And True/False is also implemented differently in other languages. E.g. in VB False = 0, and True = -1 ... that's because of the way computers store signed integers (at least in the case of VB's computers that is). E.g. a 8-bit 0 is stored as a bit-array of 00000000, while the usual method of denoting a negative uses 2's compliment, which means -1 is stored as 11111111 ... see why these 2 values were chosen as False and True respectively?

@HyflyingBird: Consider this, (+/-)1.#inf is actually undefined and simply used as an indication that the double float has reached one of its limits. It has no value of it's own - thus it evaluates to nil when used (as lisp interprets -1.#inf as a symbol name, which doesn't contain a value, and thus it's value IS nil):
Code: [Select]
(+ -1.#inf)
; error: bad argument type: numberp: nil
(= nil -1.#inf)
T
(< nil (* -1e200 1e200))
T
I.e. nil is considered "smaller than anything else" in Lisp ... but it's not necessarily designed that way, it's more likely just a function of the implementation of the lisp interpreter/compiler.
« Last Edit: June 21, 2012, 04:30:21 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

highflyingbird

  • Bull Frog
  • Posts: 415
  • Later equals never.
Re: what number is for nil?
« Reply #8 on: June 21, 2012, 04:55:01 AM »
@HyflyingBird: Consider this, (+/-)1.#inf is actually undefined and simply used as an indication that the double float has reached one of its limits. It has no value of it's own - thus it evaluates to nil when used (as lisp interprets -1.#inf as a symbol name, which doesn't contain a value, and thus it's value IS nil):
Code: [Select]
(+ -1.#inf)
; error: bad argument type: numberp: nil
(= nil -1.#inf)
T
(< nil (* -1e200 1e200))
T
I.e. nil is considered "smaller than anything else" in Lisp ... but it's not necessarily designed that way, it's more likely just a function of the implementation of the lisp interpreter/compiler.

irneb,Thank you very much.

I asked this question, just wanted to mention a thing: NIL is comparable.so don't fall into this trap.
I learned a lot,thank everyone again.
I am a bilingualist,Chinese and Chinglish.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: what number is for nil?
« Reply #9 on: June 21, 2012, 06:36:04 AM »
just wanted to mention a thing: NIL is comparable.so don't fall into this trap.

This can be useful in some situations, for example, the test:

Code - Auto/Visual Lisp: [Select]
  1. (if (and x (< 0 x))
  2.    ...
  3. )
  4.  

Can be reduced to:

Code - Auto/Visual Lisp: [Select]
  1. (if (< 0 x)
  2.     ...
  3. )

I actually use this logic when unloading dialog handles.  :-)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: what number is for nil?
« Reply #10 on: June 21, 2012, 04:01:41 PM »
Quote
And True/False is also implemented differently in other languages. E.g. in VB False = 0, and True = -1 ...

May be this is is true with VB6 or VBA, but VB.net is quite confusing:
CInt(True) returns -1 like in older VB versions.
Convert.ToInt32(True) returns 1 like in other dotNET languages (see here).

About nil, there was this thread.
Speaking English as a French Frog

LibertyOne

  • Guest
Re: what number is for nil?
« Reply #11 on: June 21, 2012, 05:53:02 PM »
Italy:1 England: nil

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: what number is for nil?
« Reply #12 on: June 21, 2012, 06:13:01 PM »

bruno_vdh

  • Guest
Re: what number is for nil?
« Reply #13 on: June 22, 2012, 10:02:50 AM »

Hello,

Quote
So,what number is for nil?

LISP is weakly typed, it is not a matter of numbers
Not knowing how to speak English correctly, here's an example that I hope sufficiently explicit…
Code: [Select]
_$ (< nil T)
T
_$ (> nil T)
Nil

A+

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: what number is for nil?
« Reply #14 on: June 24, 2012, 05:26:07 PM »