Re: Testing for NULL
- Posted by andi49 Sep 02, 2015
- 1940 views
xecronix said...
#!/usr/bin/env eui sequence x -- The next executable line is an error as expected. -- But, how can I test/defend against this error in advance? -- ie -- -- if x = ??? then -- -- do something -- end if printf(1, "x is %s", {x}) -- How to test for this error? -- No problem here. Works as I expected x = "some sequence" printf(1, "x is %s\n", {x}) -- I don't know how to express this in Euphoria either. -- What I hoped for was a way to set x to some value -- after valid assignment that would cause the error at the -- start of the code. x = 0 -- This causes a type error. But how do you unset a variable? printf(1, "x is %s\n", {x})
This came up when I wanted to do this
public function fname(sequence self, sequence x = 0) if x then self[FNAME] = x end if return self[FNAME] end function
Hi, i'am not really sure about what you are like todo.
But what about this? (Windows code)
-- #!/usr/bin/env eui include std/console.e -- for anykey() object x = 0 -- x="test" -- The next executable line is an error as expected. -- But, how can I test/defend against this error in advance? -- ie -- -- if x = ??? then -- -- do something -- end if if atom(x) then printf(1, "x is %d\n", {x}) -- How to test for this error? else printf(1, "x is %s\n", {x}) -- How to test for this error? end if -- No problem here. Works as I expected x = "some sequence" printf(1, "x is %s\n", {x}) -- I don't know how to express this in Euphoria either. -- What I hoped for was a way to set x to some value -- after valid assignment that would cause the error at the -- start of the code. x = 0 -- This causes a type error. But how do you unset a variable? -- printf(1, "x is %s\n", {x}) if atom(x) then printf(1, "x is %d\n", {x}) -- How to test for this error? else printf(1, "x is %s\n", {x}) -- How to test for this error? end if any_key()