It’s high time for an update!
Most of the fundamentals have been implemented. Development has been proceeding slowly because I’ve been wrestling with a challenging problem: how should arrays, structures, and other such data types be passed to—and returned from—subroutines in a clean and consistent way? I think that, ideally, we should be able to write code that looks a bit like this:
person.name$ = "Foo Barbaz"
person.dob.year = 1983
person.dob.month = 10
person.dob.day = 5
printDetails (person) // how should the contents of "person" be passed?
sub printDetails (p)
print p.name$ + " was born on " \
+ str$ (p.dob.year) + "/" \
+ str$ (p.dob.month) + "/" \
+ str$ (p.dob.day) + "."
end sub
I think I’ve finally figured out how to solve this problem in an elegant way. I plan to implement tables (which are pretty much equivalent to associative arrays) that will be able to contain values (real numbers, character strings, and—importantly—references to other tables) identified by arbitrary keys (integers and character strings). To ensure that tables can be used as structures, a.b will be treated as syntactic sugar for a("b") and subroutines will be able to take references to tables as arguments (for instance, test (a)).
For maximum speed, I plan to implement tables using a composite structure containing both an array part (for values identified by integer keys within a particular range) and a crit-bit trie part (for values identified by any other keys), but the underlying implementation will be abstracted and hidden at the user level.
Hi.
Looks freaking cool. I think it is gettin time to do something serious with yabasic 3.0. Man, i have waited this
Anyway, how is the Yabasic 3 Vademecum goin on? Still under work i hope.
Thanks for the encouragement, E.K.V.! Elmar’s still willing to work on the Vademecum, but wants a slightly more concrete implementation first.
Im still exited to get yab3 final in my hands. I want to code something with it due it seems to become as fast and easy to use one
I am very much looking forward to this release. Adding “hashes” (associative arrays, tables, …) to Basic is very very cool!
I hope that there will be some function provided to return a list of keys in a given table. Also, how will tables be declared (DIM? to what?)? Or will they just spring into existence when “an array” with a non-integer subscript (or a.b notation) is refereced?
I use perl a lot, but the most important feature is hashes.
Thanks! Yabasic is great, and is looking to become even better!
Marty, thanks for your interest!
There will be a function, or some equivalent, to list the keys in a table. And, at this stage, the plan is for tables just to spring into existence when they are used for the first time; in other words, no variables will need to be predeclared—although, of course, local and static variables will have to be predeclared as such.
Thomas,
First and foremost, thanks for extending yabasic in the direction of tables/associative arrays/hashes…. I’m playing with it in Linux (I don’t have an environment that I can compile source for in Windows).
I’m finding difficulty understanding what you’ve done here.
It looks soooo promising, but when I build it in linux, I can do ‘person.key$ = “value” ‘, but key$ isn’t a variable. This made sense from your code post providing an example. But if person.key$ is syntactic sugar for person(“key$”) = “value” – then I’d expect to be able to do it, but it provided me with a syntax error.
To make this “fully useful” – I see a need to have the contents of a variable be used as a key, and some way to get a list of the keys for a particular variable.
Is this there, and I just don’t understand? Or planned? Or am I missing something important.
Many thanks!
—Marty
PS: The kind of thing I’d look to do would be to store a file (say a .csv) as keys and values (say the first value of the .csv line is the key, and the rest of the line is the value). Store these in a table for quick access.
At some point, I’d like to retrieve these, but I need a way, for a given table, to get a list of the keys in the table.
It seems you are providing this functionality, but I’m not quite understanding how it works.
For:
#!/usr/bin/yabasic3
key$ = “54321″
value$ = “Bartels, Martin”
person.key$ = value$
print person.key$
key$ = “12345″
value$ = “Btfsplk, Joe”
person.key$ = value$
print person.key$
key$ = “54321″
print person.key$
rem person(“key$”) = “value”
rem print person.key$
——
I get:
Bartels, Martin
Btfsplk, Joe
Btfsplk, Joe
It would be more useful if key$ were interpreted as a variable. To that end, I attempted the remarked lines, but got “synax error at end of line”
If I’m misunderstanding how this is supposed to work, please correct me.
Many Thanks!
—MartyB
For the prior note – if “key$” had a way of being interpreted as a variable. The use of it as a field name is also a good one, I’m not trying to eliminate that.
Thomas,
Thanks for your answer on keys, I appreciate that, and can wait. [Sorry, missed that response until this morning.]
I look forward to being set straight in terms of syntax to deal with variable keys.
And, again, thanks for a good, solid Basic!
—Marty
Thanks, Marty, for your encouragement!
The current development versions of Yabasic don’t have the underlying implementation that I laid out above. So you can’t use, for example,
print items("orangeJuice")orprint a("b$")at the moment. I’ve been doing some work on a crit-bit tree implementation which will allow for this kind of thing to be added to Yabasic very simply; and, in fact, crit-bit trees will almost certainly become the primary underlying data structure used by Yabasic. Hopefully I will be able to get a basic development release with this functionality out before the end of February.Oh, and I do plan to make the “$” suffix optional.
Feel free to ask more questions; I don’t mind at all!
Cheers.