TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: highflyingbird on June 20, 2012, 01:37:52 PM

Title: what number is for nil?
Post by: highflyingbird 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.
Title: Re: what number is for nil?
Post by: Lee Mac 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
Title: Re: what number is for nil?
Post by: BlackBox 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?
Title: Re: what number is for nil?
Post by: Dommy2Hotty 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:
Title: Re: what number is for nil?
Post by: BlackBox 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?  :-)
Title: Re: what number is for nil?
Post by: dgorsman 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:
Title: Re: what number is for nil?
Post by: Kerry on June 20, 2012, 06:55:12 PM

what number is for nil?

number != 42;
Title: Re: what number is for nil?
Post by: irneb 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 (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 (http://en.wikipedia.org/wiki/Two%27s_complement), 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.
Title: Re: what number is for nil?
Post by: highflyingbird 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.
Title: Re: what number is for nil?
Post by: Lee Mac 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.  :-)
Title: Re: what number is for nil?
Post by: gile 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 (http://www.theswamp.org/index.php?topic=41187.msg463463#msg463463)).

About nil, there was this thread (http://www.theswamp.org/index.php?topic=39888.msg451877#msg451877).
Title: Re: what number is for nil?
Post by: LibertyOne on June 21, 2012, 05:53:02 PM
Italy:1 England: nil
Title: Re: what number is for nil?
Post by: Lee Mac on June 21, 2012, 06:13:01 PM
Italy:1 England: nil

 :-(
Title: Re: what number is for nil?
Post by: bruno_vdh 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+
Title: Re: what number is for nil?
Post by: VovKa on June 24, 2012, 05:26:07 PM
Italy:1 England: nil

 :-(

my apologies  :cry:
Title: Re: what number is for nil?
Post by: Lee Mac on June 24, 2012, 05:55:23 PM
Italy:1 England: nil

 :-(

my apologies  :cry:

Thanks, though, we didn't really put on much of a performance - I think we were just holding out til penalties, then hoping for some luck   :wink:
Title: Re: what number is for nil?
Post by: highflyingbird on June 24, 2012, 06:12:05 PM
What a pity!