basicprogramming.org


Welcome, Guest. Please login or register.
Did you miss your activation email?
Forum time; Jul 31. 2010, 04:01
Home Help Search Calendar Login Register
News: Have you got suggestions for BasicProgramming.org? Let's hear them!
Interested in creating your own programming language? Check out the QDepartment group!

+  BASIC programming forum
|-+  Interpreter Development
| |-+  yaBasic development forum. (Moderator: Thomas Larsen)
| | |-+  [bug] structs can't get passed to functions
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Reply Print
Author Topic: [bug] structs can't get passed to functions  (Read 100 times)
psnake
Sr. Member
****
Offline Offline

Posts: 438



« on: Jan 24. 2010, 16:06 » Reply with quote

Creating a struct and then passing it to a function simply doesn't work (without any errors printed)

Code:
struct foo
  n
end struct

foo.n = 10
do_something(foo)

sub do_something( s )
  print s.n
end sub

Another bug in the same style is when the struct is also an array

Code:
struct foo(10)
  n
end struct

for i = 1 to 10
  foo(i).n = i
next i

do_something( foo() )

sub do_something( s() )
  print s(1).n
end sub

This one gives the error:
Code:
"foo" is neither an array nor a subroutine

PSnake
Report to moderator   Logged

twitter: @PSnake89
Thomas Larsen
Administrator
Sr. Member
*****
Offline Offline

Posts: 255



WWW
« Reply #1 on: Jan 26. 2010, 22:32 » Reply with quote

Hi,

honestly, this is going to be a hard bug to fix. (Not impossible, of course--but still hard.) Obviously, you can pass individual "arrays" to Yabasic:

Code:
struct s (10)
   n
end struct

sub foo (a ())
   ...
end sub

foo (s.n ())  // one or both of
foo (s ().n)  // these should work

I'll have to take a look and see what I can do.

Cheers,
Thomas.

EDIT: I'm not sure this is a "bug" so much as a "feature", actually--but it would be nice to be able to pass "partial" structures as arguments, and to be able to assign them piece-by-piece.
« Last Edit: Jan 26. 2010, 22:34 by Thomas H. Larsen » Report to moderator   Logged

psnake
Sr. Member
****
Offline Offline

Posts: 438



« Reply #2 on: Jan 27. 2010, 10:30 » Reply with quote

I consider it a bug since yabasic accepts and executes the code but it behaves quite differently than what the programmer would expect.

Also, the syntax doesn't look quite right, imho, because s.n(1) in the same as s(1).n. I think the first case shouldn't be allowed.
And it can get worst when an element of the struct is itself an array. For example:
Code:
struct s(10)
  a(10)
end struct

// all cases are accepted and work
s(1).a(1) = 10    // the syntax that imo is correct
s(1,1).a = 20     // both indexes related to s
s.a(1,1) = 30     // both indexes related to n

I think it makes the code less readable and it might be harder for a newbie to even understand structs.

PSnake
Report to moderator   Logged

twitter: @PSnake89
Pages: [1] Go Up Reply Print 
« previous next »
Jump to:  
Atom RDF RSS 0.91 RSS 2.0


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!