Community discussions

MUM Europe 2020
 
User avatar
LatinSuD
Member Candidate
Member Candidate
Topic Author
Posts: 174
Joined: Wed Jun 29, 2005 1:05 pm
Location: Spain
Contact:

Variables behaviour in 3.10

Wed Jun 04, 2008 8:24 pm

What's the correct use of variables in 3.x? I am missing some docs and i can't get it to work, even the given examples (ddns on wiki).

An undefined variable should have a type of nil, but it has a type of "nothing"!
An unset variable has a type of "nil", but mind quotes because, as opposed to all examples, it requires the word "nil" to be quoted or it just won't work.

Try this script, but beware it will work only the first time:
:global nonExist

# Round 1. Variable should not exist

:log info ( "Round 1. Non existing variable has type of: " . [:typeof $nonExist ] )

:if ( [ :typeof $nonExist ] = nil ) do={ 
   :log info "Nil type"
}

:if ( [:typeof $nonExist ] = nothing ) do={
   :log info "Nothing type"
}

:if ( [:typeof $nonExist ] = "nil" ) do={
   :log info "Quoted Nil type"
}

:if ( [:typeof $nonExist ] = "nothing" ) do={
   :log info "Quoted Nothing type"
}

# Round 2. Clear variable. I assume this is the way to do it.
:set nonExist

:log info ( "Round 1. Cleared variable has type of: " . [:typeof $nonExist ] )

:if ( [ :typeof $nonExist ] = nil ) do={ 
   :log info "Nil type"
}

:if ( [:typeof $nonExist ] = nothing ) do={
   :log info "Nothing type"
}

:if ( [:typeof $nonExist ] = "nil" ) do={
   :log info "Quoted Nil type"
}

:if ( [:typeof $nonExist ] = "nothing" ) do={
   :log info "Quoted Nothing type"
}
Expected result:
Round 1. Non existing variable has a type of: nil
Nil type
Quoted Nil type
Round 2. Cleared variable has a type of: nil
Nil type
Quoted Nil type
Actual result:
Round 1. Non existing variable has a type of: nothing
Quoted Nothing type
Round 2. Cleared variable has a type of: nil
Quoted Nil type
 
User avatar
airstream
Member Candidate
Member Candidate
Posts: 188
Joined: Fri Feb 03, 2006 6:33 am
Location: New Zealand

Re: Variables behaviour in 3.10

Mon Jun 23, 2008 5:13 am

I too am having hassles with the :nothing operator in V3 here:
{ :local foo
 :local bar
 
 :if ($foo = [:nothing] ) do={ :set foo foo }
 :put $foo
}

This just wont see the newly created variable as nothing (empty/unset) as in 2.9 so it wont set foo. foo will remain an empty variable.
Keep tryin' its bound to work!!
-----
-----
ROOT@COSMOS> Reality.sys corrupted -- Reboot Universe (Y/N)?
>_

Who is online

Users browsing this forum: No registered users and 11 guests