It is currently Fri May 26, 2017 7:24 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Functions returning arrays
Unread postPosted: Sat Sep 24, 2016 2:20 am 
Offline

Joined: Tue Mar 03, 2015 12:33 pm
Posts: 75
this throws an error "Expected 1 index but found 0: fn.rtn arr3[]"
Code:
fn.def add(arr3[])
array.length lng, arr3[]
for i=1 to lng
++arr3[i]
next i
fn.rtn arr3[]
fn.end
array.load arr1[],1,2,3,4
add(arr1[])
array.length lng,arr1[]
for i=1 to lng
print arr1[i]
next i

It works when I replace line 6 with
Code:
fn.rtn blahblah

Yeah, I know, argument passed by reference etc, but I think it's a bit dangerous to rely on this solution.


Report this post
Top
 Profile  
 
 Post subject: Re: Functions returning arrays
Unread postPosted: Sat Sep 24, 2016 3:11 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
why dangerous?

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Functions returning arrays
Unread postPosted: Sat Sep 24, 2016 3:19 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
btw you are already passing arr1[] by reference and modifying all its elements, no need to return it.

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Functions returning arrays
Unread postPosted: Sat Sep 24, 2016 4:04 am 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
arrays are always passed to function by reference(manual).
PS Btw, global(outside) arrays are visible inside functions?


Report this post
Top
 Profile  
 
 Post subject: Re: Functions returning arrays
Unread postPosted: Sat Sep 24, 2016 4:50 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
gikam wrote:
PS Btw, global(outside) arrays are visible inside functions?

No they are not

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: Functions returning arrays
Unread postPosted: Sun Sep 25, 2016 12:03 pm 
Offline

Joined: Tue Mar 03, 2015 12:33 pm
Posts: 75
mougino wrote:
why dangerous?

I'm not sure if it will still be possible in some new version of BASIC! for example or if the results will be as predictable as they are now. Will they?
mougino wrote:
btw you are already passing arr1[] by reference and modifying all its elements, no need to return it.

Some basics throw an error "you must return some data" or something, I just didn't check it ;)


Report this post
Top
 Profile  
 
 Post subject: Re: Functions returning arrays
Unread postPosted: Mon Sep 26, 2016 9:11 am 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
mougino wrote:
gikam wrote:
PS Btw, global(outside) arrays are visible inside functions?

No they are not

thank you


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred