1. NULL value anyone?

Why doesn't Euphoria have a NULL value for an object?

How does the eu:object function recognize that a variable does not have an assigned value?

Given an object "x" with an assigned value, how may it be reverted back to "does not have an assigned value"?

A NULL value could be useful when a function returns results where {} or 0 are legal values for an algorithm.

_tom

new topic     » topic index » view message » categorize

2. Re: NULL value anyone?

_tom said...

How does the eu:object function recognize that a variable does not have an assigned value?

Internally, OE has a special value called NOVALUE, which is defined as 0xbfffffffL on 32bit and 0xbfffffffffffffff on 64bit. This is basically used the way you describe NULL as being used. If someone attempts to use a variable, and it's value is NOVALUE, the interpreter assumes that the variable was not initialized and calls RTFatal.

object() just makes the check against NOVALUE and returns 0 instead of calling RTFatal.

_tom said...

Given an object "x" with an assigned value, how may it be reverted back to "does not have an assigned value"?

Not sure if this is possible today. One might need to modify the interpreter to do this - but inside the interpreter it's simple. Just set the variable back to NOVALUE.

_tom said...

Why doesn't Euphoria have a NULL value for an object?

A NULL value could be useful when a function returns results where {} or 0 are legal values for an algorithm.

_tom

I don't know the answer to this. It's been like this since the RobC days.

new topic     » goto parent     » topic index » view message » categorize

3. Re: NULL value anyone?

_tom said...

Why doesn't Euphoria have a NULL value for an object?

NULL is:
Confusing, Complicated.

The human mind understands something that exists, while null value is not a value at all - it is a backward way to deal with non-logicaly situations, which Rob wisely avoided.

There is no true need for null value in a program or database - unless you've lost your logic or purpose.

Rob wisely avoided many fake and misleading programming methods, which MS and others couldn't.

new topic     » goto parent     » topic index » view message » categorize

4. Re: NULL value anyone?

Shian_Lee said...
_tom said...

Why doesn't Euphoria have a NULL value for an object?

NULL is:
Confusing, Complicated.

The human mind understands something that exists, while null value is not a value at all - it is a backward way to deal with non-logicaly situations,

This is a philosphical POV which I won't address, other than to say "just because the feature is there doesn't mean that you have to use it."

Shian_Lee said...

Rob wisely avoided many fake and misleading programming methods, which MS and others couldn't.

which Rob wisely avoided.

No he didn't. He used it internally (see NOVALUE).

Shian_Lee said...

There is no true need for null value in a program or database - unless you've lost your logic or purpose.

Then why did RobC use it?

new topic     » goto parent     » topic index » view message » categorize

5. Re: NULL value anyone?

Seems to me there is a need for null values in a program. How else are you going to warn the programmer, "Hey dummy, you forgot to supply a value for ..."?

If you forget to declare a variable x, and then write ? x * 2, you expect to be warned that "x is undeclared". Similarly, if you do declare "atom x" and then code ? x * 2, what is the answer supposed to be? There's no default value of x that could be assigned without causing somebody some trouble sometimes.

What is two times "darned if I know"? How could that produce meaningful results?

new topic     » goto parent     » topic index » view message » categorize

6. Re: NULL value anyone?

irv said...

If you forget to declare a variable x, and then write ? x * 2, you expect to be warned that "x is undeclared". Similarly, if you do declare "atom x" and then code ? x * 2, what is the answer supposed to be? There's no default value of x that could be assigned without causing somebody some trouble sometimes.

I think the scenario you're describing here is a good case for Try/Catch. Otherwise, if I have an uninitialized object and I try to pass that object to a routine, I will encounter a runtime error. But with try/catch, I could have the opportunity to gracefully recover from that failure. I odn't think this is a case for NULL, although I do agree that having an option to un-initialize a variable would be nice (isn't that what delete does?)

-Greg

new topic     » goto parent     » topic index » view message » categorize

7. Re: NULL value anyone?

I've already used "No value" 25 years ago, as many times as I needed.

NoValue was simple out-of-range or illegal value that used to flag specific variables for specific purpose. That's what Rob did.

The ability to assign NULL to an object - complicates Euphoria.

An average skilled programmer don't need it. Objects can be flagged as null in too many ways.

I don't care/need to add: i = is_null(x), i = is_empty(x), etc. But assign null "value" to an object is looking for more complications and unmaintainable code, while it is not truly necessary.

Same as 'goto' - "nulling" objects may lead to vertigo while maintaining a program.

new topic     » goto parent     » topic index » view message » categorize

8. Re: NULL value anyone?

Just as a point of order, dll.e defines

global constant NULL = 0 

which is muddying the waters a bit, so as jimcbrown already did we should be using NOVALUE to discuss this matter.

Phix also has an internal NOVALUE, aka h4, which has the slightly different value #40000000 or #4000000000000000, but it's the same idea, being +/-1 MININT/MAXINT, and (in Phix) you can use it in inline assembly:

integer i 
    ... 
    #ilASM {mov [i],h4} 

Not that I am convinced that has any significant merit. Note that when dealing with non-integers you would want additional test/decref/dealloc code to avoid memory leaks.

Anyway, while x = NOVALUE feels like it might be useful, after 10+ years of using this language I have yet to see any compelling examples, and things like return NOVALUE, myproc(NOVALUE) and s = {1,NOVALUE,3} have the potential to introduce serious technical challenges as well as significant performance degradation, not to mention making things harder to code, debug, and maybe even understand.

Looking at the return case in a bit more detail, assuming that

a = b 

ought to issue a (fatal/recoverable/catchable) error when b is unassigned, how exactly is

function f() return NOVALUE end function 
a = f() 

supposed to do anything different? And what happens when f returns b when it is unassigned? Does this help explain why Eu does not have such?


ghaberek said...

having an option to un-initialize a variable would be nice (isn't that what delete does?)

No, to answer your question at the end,

the manual said...

After the cleanup routines are called, the value of the object is unchanged, though the cleanup routine will no longer be associated with the object.

Pete

new topic     » goto parent     » topic index » view message » categorize

9. Re: NULL value anyone?

Here is my NULL rant...

This all started when I looked at the code that makes a stack work:

  • std/stack.e o[4
  • mystack J.Cook
  • stack.e L.Hilley et al

But, reinventing the wheel is more educational.

A stack is a sequence of items. It is a "stack" because you have the discipline to always add (push) and remove (pop) items from the top of the stack.

  • a stack with items: { "cat", "dog" }
  • an empty stack: {}
  • no stack at all: 0

Popping a value from an empty stack is a bad thing--it is an error condition. So I return 0 zero instead. I can check for atoms so I can "catch" this error without crashing.

Testing for atoms vs sequences is an idiomatic Euphoria concept. It does hide the idea that "no stack" has been given the reasonable looking value 0 zero instead of a glaring (here it is idiot!) value like NULL, NOTANUBMER, NAN, FAIL, EXCEPTION which is used in Another_Language.

-- elementry stack push and pop subroutines 
include std/console.e 
 
function push( object stack, object x ) 
    if atom(stack) then  
        return {x}  
        -- new stack from underflow condition 
    end if 
    return append(stack, x ) 
end function 
 
function pop( object stack ) 
    if length(stack) = 0 then      
        return { 0, 0 } 
        -- next pop will be underflow 
    else  
        return { stack[1..$-1], stack[$] } 
    end if 
end function 

A sample run looks like:

object sk = 0 -- new "underflow" stack -- uninitiated 
object x      -- unspecified item 
 
sk = push(sk,"cats") 
sk = push(sk,"dogs") 
display( "               [1]", {sk} ) 
 
     
{sk,x} = pop(sk) 
if atom(sk) then display( "Underflow" ) 
else 
    display(x) 
end if 
display( "               [1]", {sk} ) 
 
{sk,x} = pop(sk) 
if atom(sk) then display( "Underflow" ) 
else 
    display(x) 
end if 
display(sk) 
display( "               [1]", {sk} ) 
Shian_Lee said...

NULL is: Confusing, Complicated.

There is a place for human simplicity.

irv said...

What is two times "darned if I know"? How could that produce meaningful results?

I like Irv's intuition here.

petelomax said...

Looking at the return case in a bit more detail, assuming that a = b

ought to issue a (fatal/recoverable/catchable) error when b is unassigned

Agreed.

I was thinking about a poor man's exception mechanism.

If "b" is uninitialized I can test for it before I try to do an assignment using the object function. I used the word NULL to represent that uninitialized state (maybe there is a better word than NULL). My observation is once you do an assignment you can't undo it. That means I can't use an uninitialized variable as a "trick" to monitor some error condition.

_tom

new topic     » goto parent     » topic index » view message » categorize

10. Re: NULL value anyone?

"That means I can't use an uninitialized variable as a "trick" to monitor some error condition." (_tom).

Why do you need a trick to do something so simple, such as monitoring a stack? - Set/Reset a boolean and that's all.

What other languages do is not always better. That is the *only* reason to use Euphoria.

new topic     » goto parent     » topic index » view message » categorize

11. Re: NULL value anyone?

Shian_Lee said...

Why do you need a trick to do something so simple, such as monitoring a stack? - Set/Reset a boolean and that's all.

The stack example is there because it is simple. There are already three complete solutions to stacks for Euphoria.

Flags are maybe not so simple!

  • I would need an extra variable for each stack. The example works on any number of stacks.
    • How do I put that variable into a sequence representing a stack?
    • Or, what do I do with a bunch of global boolean variables? How do I name them? How do I remember to use them?

Arguments have to be done with code not opinions.

A "trick" is an exploration of the limits of Euphoria for me.

Shian_Lee said...

What other languages do is not always better. That is the *only* reason to use Euphoria.

There is always something to be learned from Other_Language. Sometimes Other_Language only shows me that Euphoria will work better for me, sometimes I learn something powerful.

_tom

new topic     » goto parent     » topic index » view message » categorize

12. Re: NULL value anyone?

Create a sequence of booleans for all stacks - or a multidimensional sequence that traces the history and average usage of all stacks in the last 24 hours. This is less then elementary.

I've learned much from other languages, that's why I was looking for something better.

A boolean is a 'bit' more simple/efficient/standard then anything else. No need for any code example, since any programmer on Earth knows it.

Didn't you see what Pete said? In my words: don't turn Euphoria into a useless collection of useless ideas.

new topic     » goto parent     » topic index » view message » categorize

13. Re: NULL value anyone?

Shian_Lee said...

Create a sequence of booleans for all stacks - or a multidimensional sequence that traces the history and average usage of all stacks in the last 24 hours. This is less then elementary.

I've learned much from other languages, that's why I was looking for something better.

A boolean is a 'bit' more simple/efficient/standard then anything else. No need for any code example, since any programmer on Earth knows it.

Didn't you see what Pete said? In my words: don't turn Euphoria into a useless collection of useless ideas.

In the spirit of having some fun and exploring new ideas...with the understanding that all of this is just trying out new ideas (Like I said stack.e is in the library.)

You have to convince me with an example. How am I going to index the sequence of booleans and coordinate them with my numerous stacks? Do I take my simple stack sequence and turn it into a nested sequence? I do not see the simplicity here.

Yes, a boolean flag is "trivial" but how do I organize them?

[/quote]

Shian_Lee said...

Didn't you see what Pete said? In my words: don't turn Euphoria into a useless collection of useless ideas.

Pete has much wisdom.

_tom

new topic     » goto parent     » topic index » view message » categorize

14. Re: NULL value anyone?

True. Pete is the real thing.

Tom, obviously, from your request for examples - you don't have much of practical experience in real world programming. You're asking me to teach you the alphabet? See you later.

new topic     » goto parent     » topic index » view message » categorize

15. Re: NULL value anyone?

Shian_Lee said...

True. Pete is the real thing.

Tom, obviously, from your request for examples - you don't have much of practical experience in real world programming. You're asking me to teach you the alphabet? See you later.

http://openeuphoria.org/wiki/view/CodeOfConduct.wc

Andreas

new topic     » goto parent     » topic index » view message » categorize

16. Re: NULL value anyone?

Shian_Lee said...

Tom, obviously, from your request for examples - you don't have much of practical experience in real world programming. You're asking me to teach you the alphabet? See you later.

Thanks for reading. And thanks for you interest in Euphoria.

As I've said before, I am not a programmer. So it is not much of a challenge to one up me in programming prowess.

My stack pop-push functions are less than 20 lines of code. They leverage the properties of atom-sequence and multiple assignment. I just can't see how a boolean will make the example work better, simpler, or make is smaller.

I will continue to value your comments.

_tom

new topic     » goto parent     » topic index » view message » categorize

17. Re: NULL value anyone?

My gut reaction to the stack issue is that rather than:

x = pop(stack) 
if x=NOVALUE then 
    display("Underflow") 
else 
    display(x) 
end if 

the code should be more like

if empty(stack) then 
    display("Underflow") 
else 
    x = pop(stack) 
    display(x) 
end if 

HTH, Pete

new topic     » goto parent     » topic index » view message » categorize

18. Re: NULL value anyone?

First of all Tom, please accept my apology.
I did not mean to underestimate you in any way. I was rude and it's not the first time.
Your work here is extremely important. Without good documentation the languages is totally useless.

About the stack example:

_tom said...

Testing for atoms vs sequences is an idiomatic Euphoria concept. It does hide the idea that "no stack" has been given the reasonable looking value 0 zero instead of a glaring (here it is idiot!) value like NULL, NOTANUBMER, NAN, FAIL, EXCEPTION which is used in Another_Language.

-- elementry stack push and pop subroutines 
include std/console.e 
 
function push( object stack, object x ) 
    if atom(stack) then  
        return {x}  
        -- new stack from underflow condition 
    end if 
    return append(stack, x ) 
end function 
 
function pop( object stack ) 
    if length(stack) = 0 then      
        return { 0, 0 } 
        -- next pop will be underflow 
    else  
        return { stack[1..$-1], stack[$] } 
    end if 
end function 

A sample run looks like:

object sk = 0 -- new "underflow" stack -- uninitiated 
object x      -- unspecified item 
 
sk = push(sk,"cats") 
sk = push(sk,"dogs") 
display( "               [1]", {sk} ) 
 
     
{sk,x} = pop(sk) 
if atom(sk) then display( "Underflow" ) 
else 
    display(x) 
end if 
display( "               [1]", {sk} ) 
 
{sk,x} = pop(sk) 
if atom(sk) then display( "Underflow" ) 
else 
    display(x) 
end if 
display(sk) 
display( "               [1]", {sk} ) 

Could be modified, for example, to (not debugged):

-- it's faster to call  append(stack, x)  directly. 
function push(sequence stack, object x) 
    return append(stack, x) 
end function 
  
function pop(sequence stack) 
    integer len = length(stack) 
 
    if len then      
        return {stack[1..len - 1], stack[len]} 
    else  
        return {} -- return stack to its initial state. 
    end if 
end function 
  
-- Example for modified push()/pop(): 
sequence stack = {} 
object   item = "Shian is rude" 
 
stack = push(stack, item)    --> or faster:  append(stack, item) 
stack = pop(stack) 
 
if length(stack) then       
    item = stack[2] 
    stack = stack[1] 
end if 

About using Booleans... Normally I use stacks in-line as a global/local/private sequence, for specific purpose, so in this case I can optimize the process by using an integer as a length counter, to avoid calling length(). Booleans can be used in many ways to optimize the code, for example: stack1_empty = not length(stack[1][4])
If I must test for an empty stack many times then it's better to code: if stack1_empty then...
instead of coding if not length(stack[1][4]) then...

There are many other ways to use Booleans, depends on what the stack is for. Booleans can be stored in a single integer and set/reset using or_bits()/and_bits() which is fast and convenient.

The important thing to remember is that NOVALUE modifies the behavior of Euphoria in a massive way, and the "Cost Vs Benefit" might be awful and truly not reasonable.

new topic     » goto parent     » topic index » view message » categorize

19. Re: NULL value anyone?

Shian_Lee said...

There are many other ways to use Booleans, depends on what the stack is for. Booleans can be stored in a single integer and set/reset using or_bits()/and_bits() which is fast and convenient.

The important thing to remember is that NOVALUE modifies the behavior of Euphoria in a massive way, and the "Cost Vs Benefit" might be awful and truly not reasonable.



Seems to me once again Shian-Lee that you are around programming quite some time.
You might possibly even remember 8086-asm coding where we used to utilise even insignificant bits
in opcodes to store booleans, just for saving crucial bytes of space as in those days
64Kb was a lot of memory that came at incredible prices.

NOVALUE indeed is a monster in disguise only needed by those who don't understand bit-wise booleans ;)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu