function to create structure with passed name

Discussions about the Liberty BASIC language, with particular reference to LB Booster
Adamkonrad
Posts: 5
Joined: Fri Mar 28, 2025 1:57 pm

function to create structure with passed name

Post by Adamkonrad »

Is it possible, without a conversion table of some sort in an array, to pass a name of structure to be created
what I mean is it possible to accomplish something of the sort a$ = "something" : struct a$, x as etc, etc by 'simple' means
guest
Site Admin
Posts: 210
Joined: Tue Apr 03, 2018 1:34 pm

Re: function to create structure with passed name

Post by guest »

Adamkonrad wrote: Mon Jun 23, 2025 3:45 pm Is it possible, without a conversion table of some sort in an array, to pass a name of structure to be created
what I mean is it possible to accomplish something of the sort a$ = "something" : struct a$, x as etc, etc by 'simple' means
I don't know of any 'simple' way. Creating a variable with a name determined at run time is relatively easy, but the same isn't true of a structure.

What's the use case? Why do you want to do this?

LBB supports arrays of structures, is there any way this capability could be leveraged to do what you want?
Adamkonrad
Posts: 5
Joined: Fri Mar 28, 2025 1:57 pm

Re: function to create structure with passed name

Post by Adamkonrad »

I'm
just experimenting and exploring possibilities
I noticed in bbc basic manual,
that you can use once defined structure as a prototype for new structures, and hoped that something similar might work in LBB,
moreover perhaps have something like type in some other basics, especially as you have arrays of structures in LBB, write a subroutine or function that allows creation of something similar to type

as in LBB you made it possible to pass arrays to functions, what is extremely helpful I also hoped to pass structures as in bbc basic, but don't think it's possible in LBB, but that's a digression now

information
while playing with structures and manual, I noticed that in manual you give an example of passing to function and use abbreviation s{} in prototype and then s.x in function body, in current bbc basic editor s. expands to step, and s.x to step.x so the example
might be changed for easier following
guest
Site Admin
Posts: 210
Joined: Tue Apr 03, 2018 1:34 pm

Re: function to create structure with passed name

Post by guest »

Adamkonrad wrote: Mon Jun 23, 2025 9:26 pm I noticed in bbc basic manual,
that you can use once defined structure as a prototype for new structures, and hoped that something similar might work in LBB
Although you can use a previously-defined structure as a 'prototype' for a new structure, that still doesn't help with creating a structure with a name determined at run-time; the 'prototype' structure must be declared conventionally rather than be 'variable'.
in current bbc basic editor s. expands to step, and s.x to step.x so the example might be changed for easier following
By default, BBC BASIC does not expand s. to STEP. This will only happen if you enable two options: Lowercase keywords and Abbreviations. Neither of these options is recommended, nor enabled by default, precisely because they can introduce incompatibilities of this kind.

The documentation says this of the Abbreviations option: "This feature is initially disabled and should be used with care, because abbreviations can be confused with the syntax for structure members. This is particularly an issue when Lowercase Keywords are enabled".

In fact, enabling Lowercase keywords automatically disables the Abbreviations option if previously selected, although you can enable it again.
Adamkonrad
Posts: 5
Joined: Fri Mar 28, 2025 1:57 pm

Re: function to create structure with passed name

Post by Adamkonrad »

ups
my mistake
sorry

I will follow the recommendations

Thank you