Container library for FreeBASIC?

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Container library for FreeBASIC?

Post by Cretin Ho »

I need a container library for FreeBASIC, that provides data structures such as C++ vector, dynamic array, map, queue,...

I'm still new to language so I don't know where to search for something like that. Thanks.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Container library for FreeBASIC?

Post by Cretin Ho »

Is this library what I'm looking for? The name contains "List", the code is too complex for me to understand.

viewtopic.php?f=8&t=26533
Lost Zergling
Posts: 538
Joined: Dec 02, 2011 22:51
Location: France

Re: Container library for FreeBASIC?

Post by Lost Zergling »

Dynamic arrays already exist. Arrays can be indexed directly according to a C ++ syntax, but indeed the so-called "high level" functions are not the core of the language and require the use of libraries. LZLE (stable, in progress) and LZAE (wip, incomplete) undoubtedly address some of the problems that you mention (notably via lists), but in a spirit and a syntax which want to be accessible and in accordance with the idea that I myself do what Basic can still be, that is to say by favoring the versatile and easy side, and by considering memory dynamics as a programming element rather than as a constraint on which the end user must be able to make the abstraction. The way of doing Basic sort of, with a little coding, that might do the job most of the time but that's probably exactly not what you're looking for. The functional scope is nevertheless extended, user feedback is welcome. It should be possible to find work and brainstorming on arrays (topic "new array features"). Other libraries undoubtedly exist.
Added :
"Is this library what I'm looking for? The name contains "List", the code is too complex for me to understand."
->Yes, I know, that was a bit hard for me to code. Do not focus on pointers complexity (cooking but no trickery), focus on syntax behaviour, tests & features. Try examples & few docs provided here viewtopic.php?f=9&t=26551
(some might be outdated, but functional)
Thx for your interest.
adeyblue
Posts: 300
Joined: Nov 07, 2019 20:08

Re: Container library for FreeBASIC?

Post by adeyblue »

I've just finished doing a List, LinkedList, Stack, Queue and BitSet here which may be in a future version of FB. They've been tested (the tests are in src/tests/containers) but I haven't done the examples yet.

As FB doesn't support generics, they're all defined as macros to be both strongly typed and generic, so compared to every other UDT, an extra step is required before using them.

For instance

Code: Select all

#include "containers/list.bi"
FBCont_DefineListOf(Long) '' define the container for longs, need to do one of these for every different type
'' Things in namespaces have to be defined as 
'' FBCont_DefineListOf(FirstNamespace, SecondNameSpace, TheType)
Type LongList As FB_List(Long) '' this isn't required, but makes things easier
'' again for namespaces this would be
'' Type TheTypeList As FB_List(FirstNamespace, SecondNameSpace, TheType)

Dim myList As LongList '' can construct from an array, or from one of the other containers
myList.Add(56)
myList += 10
dim listCount As Long = myList.Count
For i As Long = 1 To listCount
    Print Using "List & = &"; i; myList[i - 1]
Next
Which'd print
List 1 = 56
List 2 = 10

The only requirement for what goes in them is that UDTs need an Operator=, since they have methods like Contains And IndexOf which need to find things.

I plan on doing more when I get time but the main sticking point is how to make macros work when more than one type parameter is required, for things like Key-Value structures.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Container library for FreeBASIC?

Post by Cretin Ho »

Thanks all. I will investigate your solutions when I have time.
Lost Zergling
Posts: 538
Joined: Dec 02, 2011 22:51
Location: France

Re: Container library for FreeBASIC?

Post by Lost Zergling »

@Cretin Ho. Thank you. If you have any question, remarks, demand or suggestion I'd be glad to answer.
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: Container library for FreeBASIC?

Post by badidea »

There used to be the FreeBASIC-Extended-Library which may include some of the wanted functionality, but is not maintained any more it seems.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Container library for FreeBASIC?

Post by Cretin Ho »

badidea wrote:There used to be the FreeBASIC-Extended-Library which may include some of the wanted functionality, but is not maintained any more it seems.
Will FreeBASIC has a standard container library like the C++ STL containers in the near future? I mean a standard container library shipped as an optional part of the language in the inc directory, not third party's solutions like now.

FreeBASIC seems to not support generics. Could this is the reason why such library not yet possible?

Free Pascal people has many container libraries available apart from their own shipped as part of their RTL. But Free Pascal has generics, though.
Lost Zergling
Posts: 538
Joined: Dec 02, 2011 22:51
Location: France

Re: Container library for FreeBASIC?

Post by Lost Zergling »

Is this library what I'm looking for?

Your choice.
Will FreeBASIC has a standard container library like the C++ STL containers in the near future? I mean a standard container library shipped as an optional part of the language in the inc directory, not third party's solutions like now.
I don't know. I think important term is 'solutions'. It is very easy to add custom functionality to LZLE just by adding the required data types at the listnode level, and accessing them like the .Tag and .RwTag properties. Everything else remains more or less operational (reindexing is carried out on strings). It is possible to create several .bi (lzle_1.bi, and so on) to manage the memory as closely as possible on differentiated types. This solution is imperfect, but it exists and does not require a lot of time, nor an extraordinary technical level to implement.
FreeBASIC seems to not support generics. Could this is the reason why such library not yet possible?
I will not be able to answer you. However, I think it could also be related to the management of pointers. The construction of an instruction set which "disregards" pointers presents notable difficulties, but the support of generics presents only a very limited interest without a relevant and coherent instruction set making it possible to effectively use this' genericity 'in a standardized multipurpose conceptual framework (for example, the type' Variant 'under VB or family VB always presented the limit of the exploitation of the content, but in a more general way, any generic type only pushes back the problem of the use of the data and is only a convenience of factorization of code in a given conceptual perimeter).
In lzle the preferred approach is that of pointers abstraction, in lzae what you call a 'genericity' is approached by overloading, but the real functional convenience is in the abstraction of pointers around a generic instruction set in its functional area.
Free Pascal people has many container libraries available apart from their own shipped as part of their RTL. But Free Pascal has generics, though
I do not know Free Pascal, but "generics" are not useful without a suitable instruction set to handle them. And without a dedicated functional area, it would be reduced to a code factorization solution.
Cretin Ho
Posts: 182
Joined: Feb 04, 2021 13:01

Re: Container library for FreeBASIC?

Post by Cretin Ho »

I will try if I could make use of your library when I have time. Thank you for your works.
adeyblue
Posts: 300
Joined: Nov 07, 2019 20:08

Re: Container library for FreeBASIC?

Post by adeyblue »

I think if third-party isn't good enough then you're in the wrong language. The 'official' distribution is minimal (seemingly on purpose) and with maybe five people occasionally working on it, it isn't going to suddenly balloon with tons of new 'official' features anytime soon.
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Container library for FreeBASIC?

Post by marcov »

Lost Zergling wrote:
Is this library what I'm looking for?
Free Pascal people has many container libraries available apart from their own shipped as part of their RTL. But Free Pascal has generics, though
I do not know Free Pascal, but "generics" are not useful without a suitable instruction set to handle them. And without a dedicated functional area, it would be reduced to a code factorization solution.
Note that having (and maturing) a generics/templates language extension caused a boom in container types, because it allows typesafe containers. Without it, not very safe macro trickery is your own hope, which is sometimes hard for beginners to understand.

Since older Free Pascal and Delphi didn't have macrosystems usable for this, most people used simply generator programs to generate type safe derivations of the standard container types. I have done that in the past too, but it mostly only worked fine for reference types.

But generics are not exactly a trivial extension, it took ten years to mature and make it somewhat compatible to Delphi.
Lost Zergling
Posts: 538
Joined: Dec 02, 2011 22:51
Location: France

Re: Container library for FreeBASIC?

Post by Lost Zergling »

Yes, indeed, the ambition is much more modest: a targeted over implementation which fits naturally into the language, but not into the internal structure of the object implementation. Moreover, independence from the FB source code was a major specification, especially to be able to do it my way. The important point is not so to be 'real' generic, but to be able to benefit functional facilities 'in the taste of' while remaining in the spirit of something easy to use. It is not the object functional domain which encapsulates generic capacities, it is the functional subdomain which manages everything and seeks to act a bit 'as if'. This is possible because the functional subdomain advocates a memory path paradigm (as a key) as a design object, which is distinct from the academic object paradigm. As long as the user's goal is not to design their own generic (subdomains)(redo everything in pointers), it does the job, but the truly integrated object model which aims to converge code and architecture is 'better' (more powerfull when it comes to design a custom framework). It promotes the efficiency/easyness ratio of 'everyday code' rather than raw science.
Not a problem for Basic.
(ps : once again I do not know Free Pascal. I can just imagine what you are talking about, a " 10 yrs research project " is supposingly ambitious. Also consider FB does not disregard nor pointers nor object design programming capabilities).
Added : lzle will support the addition of custom datatypes into listnode or listcontainer datatypes (not only references) because the allocation proceds is len(datatype), till the datatype size is not subject to overflow the original specifications. lzle optimisation is depending the developper can assume to manage a bit the substitutability properties the handled datas, having so a dynamic vision of his design (as an analogy with wintergaten marble machine).
Post Reply