Author Topic: Error meaning please...  (Read 2079 times)

0 Members and 3 Guests are viewing this topic.

Brian Alvarez

  • Guest
Error meaning please...
« on: November 23, 2018, 05:16:31 PM »

 What does this error mean?

Code: [Select]
ERROR: index expression complexity [..]

Brian Alvarez

  • Guest
Re: Error meaning please...
« Reply #1 on: November 23, 2018, 05:19:48 PM »
This is the code:

Code: [Select]
function which_index(string p1, int p2) as int
    return 5 ' just as an example
end function

string fff[10]

fff[which_index("something", 5)] = "Hello fff"

JRS

  • Guest
Re: Error meaning please...
« Reply #2 on: November 23, 2018, 06:29:41 PM »
Interesting. I have neve tried using a function to reference an array index before.

I'm going to give it a try in SB for fun.

Brian Alvarez

  • Guest
Re: Error meaning please...
« Reply #3 on: November 23, 2018, 07:23:50 PM »
Apparently it cannot be done. I will try different methods, maybe a combination of macros and functions will work.
I got it working for some numeric values, but for strings it crashes.

Brian Alvarez

  • Guest
Re: Error meaning please...
« Reply #4 on: November 23, 2018, 07:46:13 PM »

Apparently i dont know how to pass an array of strings. And i cant find any examples to do it...

JRS

  • Guest
Re: Error meaning please...
« Reply #5 on: November 23, 2018, 07:58:45 PM »
SB seems to handle it okay.

Code: Script BASIC
  1. FUNCTION ECHO(in)
  2.   ECHO = in
  3. END FUNCTION
  4.  
  5. array[0] = 100
  6. array[1] = "A String"
  7. array[2] = .2
  8.  
  9. PRINT array[ECHO(0)],"\n"
  10. PRINT array[ECHO(1)],"\n"
  11. PRINT FORMAT("%g",array[ECHO(2)]),"\n"
  12.  


jrs@jrs-laptop:~/sb/examples/test$ scriba funcidx.sb
100
A String
0.2
jrs@jrs-laptop:~/sb/examples/test$


Brian Alvarez

  • Guest
Re: Error meaning please...
« Reply #6 on: November 23, 2018, 08:14:35 PM »
I am using Oxygen.

JRS

  • Guest
Re: Error meaning please...
« Reply #7 on: November 23, 2018, 08:21:48 PM »
Quote from: John
I'm going to give it a try in SB for fun.

I didn't have to guess you were using O2.

Brian Alvarez

  • Guest
Re: Error meaning please...
« Reply #8 on: November 23, 2018, 08:27:47 PM »
 Oh, ok. :)

 Have fun John.

 Meanwhile, I'm getting frustrated here. :)
No workarounds in sight!! Im getting worried.

 I think im going to rest now. Maybe when i come
back i will see one of the magical solutions from Charles.

JRS

  • Guest
Re: Error meaning please...
« Reply #9 on: November 23, 2018, 08:31:15 PM »
Quote
Apparently i dont know how to pass an array of strings. And i cant find any examples to do it...

Code: Script BASIC
  1. FUNCTION ECHO(my_array)
  2.   PRINT my_array[0],"\n"
  3.   PRINT my_array[1],"\n"
  4.   PRINT FORMAT("%g", my_array[2]),"\n"
  5. END FUNCTION
  6.  
  7. array[0] = 100
  8. array[1] = "A String"
  9. array[2] = .2
  10.  
  11. ECHO array
  12.  


jrs@jrs-laptop:~/sb/examples/test$ scriba passarray.sb
100
A String
0.2
jrs@jrs-laptop:~/sb/examples/test$


Charles Pegge

  • Guest
Re: Error meaning please...
« Reply #10 on: November 23, 2018, 08:50:24 PM »
Hi Brian.

One would normally split the computation of an index, and its use in an array, into 2 separate expressions. This is what a compiler has to do anyway. And the code is easier to understand when you come to revise it.

But I might be able to persuade o2 to accept this kind of nesting, without complaining about 'complexity'.

Brian Alvarez

  • Guest
Re: Error meaning please...
« Reply #11 on: November 23, 2018, 11:16:55 PM »
Please do! I was thinking of doing it myself, but i rather focus on writing the rest of the stock functions. :)

JRS

  • Guest
Re: Error meaning please...
« Reply #12 on: November 23, 2018, 11:20:36 PM »
With O2, array references need the null [] brackets. I also wish Charles would have gone with the variant TYPE for variables.

Charles Pegge

  • Guest
Re: Error meaning please...
« Reply #13 on: November 24, 2018, 06:05:34 AM »
Brian,

Passing whole string arrays byref:

Code: [Select]
'[]' indicates whole array passed byref
'
'function f(byref s as string [])
'function f(byref s as string ptr)
'function f(s as string ptr)
function f(s as string [])
'function f(string s[])
======================
print s[1] s[2] s[3] s[4]
s[3]="c"
end function

f(s)
print s[1] s[2] s[3] s[4]