NULL, ISNULL() and uninitialized variables in the Ring programming language

Hello

when we try to use uninitialized variable in the Ring programming language, we get a clear runtime error message

Example

See x

Output

Line 1 Error (R24) : Using uninitialized variable : x
in file tests\seeuninit.ring

The same happens when you try to access uninitialized attributes
Example

o1 = new point
see o1
see o1.x
class point x y z

Output

x: NULL
y: NULL
z: NULL

Line 3 Error (R24) : Using uninitialized variable : x
in file tests\seeuninit2.ring

if you want to check for the error, just use Try/Catch/End

Try
see x
Catch
See “Sorry, We can’t use x!” + nl
Done

Output

Sorry, We can’t use x!

Now we will talk about NULL and ISNULL()

Since we get error message when we deal with uninitialized variables
We can check these errors using Try/Catch/Done, So we uses NULL and ISNULL() for dealing with Strings.

NULL is a variable contains an empty string

ISNULL() is a function that returns true (1) if the input is an empty string or just a string contains “NULL”

This because we need to test these values (empty strings) and strings contains “NULL” that sometimes come from external resource like DBMS.

Example

See IsNull(5) + nl +        # print 0
IsNull("hello") + nl +      # print 0
IsNull([1,3,5]) + nl +      # print 0
IsNull("") + nl +           # print 1
IsNull("NULL")              # print 1
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s