[Info-vax] DEC Basic and dynamic memory ?

Arne Vajhøj arne at vajhoej.dk
Sat Jan 29 13:00:57 EST 2022


On 1/29/2022 12:16 AM, Dave Froble wrote:
> On 1/28/2022 8:33 PM, Arne Vajhøj wrote:
>> On 1/28/2022 2:57 PM, Simon Clubley wrote:
>>> How easy is it in DEC Basic to build a tree of (say) 1000 nodes of
>>> a custom data structure in dynamic memory and then walk the tree
>>> either depth-first or breadth-first ?
>>>
>>> I've had a quick look at the dynamic storage section of the DEC Basic 
>>> user
>>> manual, but I don't see how you link a set of nodes together into a 
>>> tree.
>>> However, as mentioned previously, I don't know DEC Basic and searching
>>> for the word pointer didn't reveal anything appropriate, so I assume
>>> it's another keyword I am not aware of.
>>>
>>> In addition, how easy is this to do if the nodes are not all of the
>>> same record type, but have a common tag at the start of each record
>>> to say what kind of record it actually is ? I see you have variant
>>> records in DEC Basic. Do they also work in a dynamic memory based
>>> tree structure ?
>>
>> Basic is different than C and Pascal. You do not call a dynamic
>> allocation function and get back a machine address that you need
>> to free later.
>>
>> But you can do a tree by using a dynamic sized array and indexes
>> into that as "pointers".
>>
>> And Basic map dynamic is similar to C union.
>>
>> Example code (maybe not super elegant - either because
>> it is not the right language for the task or because my Basic
>> skills are very limited - but it seems to work):
>>
>> $ typ tree.bas
>> record treenoderec

>> $ typ dyn.bas
>> program dyn
>>
>> %include "tree.bas"

> Arne, I have difficulty following your code examples.  Is it me, or you?

Probably me.

:-)

In this case Simon outlined a problem where Pascal and C are obvious
languages and me with no Basic experience wrote some Basic code - that
is almost ensure an "unsual style". Or to put it another way: I am
(or was) a Fortran programmer and Fortran programmers can program
in Fortran in any language.  :-)

Arne




More information about the Info-vax mailing list