Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Icon > If statement
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 131 of 181
Post > Topic >>

If statement

by Jeremy Cowgar <j.e.remove-dots.remy@[EMAIL PROTECTED] > Nov 22, 2006 at 07:39 PM

I am new to Icon, so this is most certainly my fault, but I am not 
understanding where to go from here. I have a rather contorted matching 
function that takes a variable number of arguments. It's not necessary 
to go into that. Here is what I would like to accomplish:

if (a is null OR a == data[1])
        AND (b is null OR b == data[2])
        AND (c is null OR c == data[3])
  then return index

So, if the user supplies a, it's matched, otherwise, it skips that 
match. So on for b and c. Here is my real Icon code:

every idx := startAt to *spec do {
   if (/loopName | loopName == spec[idx][1]) & 
         (/segName | segName == spec[idx][2]) &
         ( /segMod | segMod == spec[idx][3]) then     return idx
}

When my function runs, I get this:

Run-time error 103
File edispec.icn; Line 14
string expected
offending value: &null
Traceback:
main()
testX096() from line 24 in edispec.icn
position_of(list_485 = 
[list_1(3),list_2(3),list_3(3),...,list_482(3),list_483(3),list_484(3)],1
,"CLM",&null,&null) from line 7 in edispec.icn
{&null == ""} from line 14 in edispec.icn

Now, I decided to break this down and figure out exactly where the error 
is happening and in the process I now have:

every idx := startAt to *spec do {
   if /loopName | loopName == spec[idx][1] then
      if /segName | segName == spec[idx][2] then
         if /segMod | segMod == spec[idx][3] then
            return idx
}

The above code works just as I would expect it to. With this code about 
30 unit tests pass just fine, the other code, 30 unit tests fails.

So, my question is what is wrong with my first if statement?

Thank you,

Jeremy




 4 Posts in Topic:
If statement
Jeremy Cowgar <j.e.rem  2006-11-22 19:39:51 
Re: If statement
Steve Wampler <swample  2006-11-27 09:22:21 
Re: If statement
Cary Coutant <cary@[EM  2006-11-27 17:41:03 
Re: If statement
Steve Wampler <swample  2006-11-28 07:38:19 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 14:52:51 CDT 2008.