syntaxbasicbbc-micropowerbasic

How to pass a list to a subroutine in BASIC-256


I am having difficulty passing a list to a subroutine (embarrassment); I get a compiler error. I have followed the BASIC-256 documentation on arrays (http://doc.basic256.org/doku.php?id=en:arrays) and included the [] brackets in the subroutine argument as required:

subroutine print_list(list) # or subroutine print_list(list[]) <----- **compiler** error occurs here
   for element=0 to list[?]-1
      print list[element]
   next element
end subroutine

subroutine main()
   list = {5.9, 6.0, 5.9, 5.7, 5.6, 5.7}
   call print_list(list[]) #  <----- **compiler** error occurs here
end subroutine

call main()

The compiler complains that I have an error in the subroutine call argument part.

I have tried fixing this by; (i) checking my initialization of the list; (ii) checking the subroutine definition and parameters (compiler doesn't like the square brackets there either); (iii) excluding the [] brackets from the argument and (iv) tried contacting the BASIC-256 Facebook page.

Thank you for your time....


Solution

  • Based on the info on the site, you cannot pass arrays to your own subroutines, only internal (built-in) ones.

    If the variables are global in nature, you're fine, just perform whatever actions you want on the array, but if they needed to be local, it can't be done with this particular variation of BASIC.