Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 11:00 19 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Complex data types

Author Message
elk1984

Senior Member

Joined: 11/07/2020
Location: United Kingdom
Posts: 227
Posted: 06:17pm 22 Sep 2020
Copy link to clipboard 
Print this post

I know it's Basic, but I really miss my structures and arrays of arrays. Short of digging into Comp Sci levels of data structure theory or C, has anyone else modelled anything approaching a structure, arraylist or similar "record" like data structures?

I saw on a different thread a member was working on a database include / library but a fully fledged DB whilst useful is overkill for day to day usage for me.
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 07:20pm 22 Sep 2020
Copy link to clipboard 
Print this post

  elk1984 said  I know it's Basic, but I really miss my structures and arrays of arrays. Short of digging into Comp Sci levels of data structure theory or C, has anyone else modelled anything approaching a structure, arraylist or similar "record" like data structures?

I saw on a different thread a member was working on a database include / library but a fully fledged DB whilst useful is overkill for day to day usage for me.


You can do some things with strings containing comma separated lists of items and the FIELD$() function.

I've also got some string list, set and map implementations here: https://github.com/thwill1000/sptools/tree/master/src/common - check the "tests/" folder for example usage. I don't claim they are great, but I've found them useful.

But really if you need anything complex I think you'll need to declare an array of integers and treat it as a byte array using the PEEK() and POKE() functions with offsets ... it's back to data-structure BASICs.

Best wishes,

Tom
Edited 2020-09-23 05:32 by thwill
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 381
Posted: 12:47pm 23 Sep 2020
Copy link to clipboard 
Print this post

I also pack individual small pieces of data into integer variables and then unpack them. This compensates for the fact that functions cannot return arrays.

Of course you can also use a subroutine with pass by reference to return multiple values, or just put return values into an array.

*sigh* I miss C structs, C++ and Java object-orientation, and a lot of modern language features. But it is kind of a nice challenge writing in BASIC after years of using other languages.

The most irritating thing for me about MMBasic is the total lack of name spaces. For instance, there are no name spaces for different types of variable, so, for instance, if you have a variable VAR and a variable VAR$, they collide. And user variables and reserved words also collide. Even const names and variables collide, as do variables with different case. Oh well, it's all part of the fun!

-Bill
 
mkopack73
Senior Member

Joined: 03/07/2020
Location: United States
Posts: 261
Posted: 01:07pm 23 Sep 2020
Copy link to clipboard 
Print this post

  William Leue said  I also pack individual small pieces of data into integer variables and then unpack them. This compensates for the fact that functions cannot return arrays.

Of course you can also use a subroutine with pass by reference to return multiple values, or just put return values into an array.

*sigh* I miss C structs, C++ and Java object-orientation, and a lot of modern language features. But it is kind of a nice challenge writing in BASIC after years of using other languages.

The most irritating thing for me about MMBasic is the total lack of name spaces. For instance, there are no name spaces for different types of variable, so, for instance, if you have a variable VAR and a variable VAR$, they collide. And user variables and reserved words also collide. Even const names and variables collide, as do variables with different case. Oh well, it's all part of the fun!

-Bill


Likewise, it's really hard to go back to not having those things after 20 years of using them. Even just having a linked-list of structs would be SOOO nice again... But, it is what it is...
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 381
Posted: 01:16pm 23 Sep 2020
Copy link to clipboard 
Print this post

I use stacks and queues quite a lot in my MMBasic programs. In general, I just use global variables and hope for the best, e.g.,

option default integer

dim stack(300)
dim sptr = 0

sub push val
 stack(sptr) = val
 sptr = sptr+1
end sub

function pop(val)
 sptr = sptr-1
 pop = stack(sptr)
end function

But actually there may be a less dangerous way to implement these important data structures, something like this:

sub stack operation, value
 static stk(300)
 static sptr

 select case operation
   case INIT
      sptr = 0
   case PUSH
      stk(sptr) = value
      sptr = sptr+1
   case POP
      sptr = sptr-1
      value = stk(sptr)
 end select
end sub

-Bill
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 3830
Posted: 01:20pm 23 Sep 2020
Copy link to clipboard 
Print this post

  William Leue said  I use stacks and queues quite a lot in my MMBasic programs ...


This string list implements stack operations without global state:

https://github.com/thwill1000/sptools/blob/master/src/common/list.inc

Regards,

Tom
Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 381
Posted: 01:39pm 23 Sep 2020
Copy link to clipboard 
Print this post

Oh, very nice, Tom!
-Bill
 
NPHighview

Senior Member

Joined: 02/09/2020
Location: United States
Posts: 192
Posted: 02:18pm 23 Sep 2020
Copy link to clipboard 
Print this post

I arrived here very indirectly from my BASIC roots in the Hewlett-Packard ecosystem of the 1970's and 1980's.  I'm missing map/reduce, zips, and list comprehensions in Haskell, F#, and other languages with "functional" features, like Python. I'm missing C Structs too, which I still think of, instead of "objects", when I plan out a new application.  But then, that wouldn't be Basic.

On the other hand, we have here an incredibly rich graphics and I/O environment, with plenty of opportunity to use good software development practices we've accumulated over the last 40-50 years, and a fabulous ecosystem with the likes of matherp and MauroXavier doing really impressive stuff.  FFTs and quaternions in the firmware - who would have thunk it?
Live in the Future. It's Just Starting Now!
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024