Vectors

20 views
Skip to first unread message

The Beez

unread,
Mar 20, 2023, 4:59:25 AM3/20/23
to 4tH-compiler
Hi 4tH-ers!

I'm polishing up my C++ knowledge and bumped into Vectors. Now, we already got dynamic arrays, so I decided to add an OOP wrapper around it - which technically means we got some kind of OOP arrays.

We already got dynamic strings, so..

When creating a vector you can initialize it with values (the Forth way). If you don't want to initialize the vector you have to supply "0" (meaning: no values). You can grow or shrink a vector, get and set values, push and pop values and get the current size.

No, it's not the full range of methods a C++ vector offers, but I think it covers most of the basics. You can always subclass it.

Gee, I'm really beginning to talk like a real OOP junkie..

Hans Bezemer

Phillip Kelly

unread,
Mar 20, 2023, 5:10:40 AM3/20/23
to 4th-co...@googlegroups.com
Thanks Hans

Made note of this one!

--
You received this message because you are subscribed to the Google Groups "4tH-compiler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 4th-compiler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/4th-compiler/ae194ebf-a5ef-4c29-975f-142a1dd460d6n%40googlegroups.com.


--
Yours Sincerely
Mr. Phillip Kelly
 

The Beez

unread,
Mar 20, 2023, 1:26:10 PM3/20/23
to 4tH-compiler
Well, while I was at it I remembered some horrible program I wrote about an array of objects - called FOOSARRY.4PP
So I pulled it and plugged vectors into it - see if that could clean things up a bit.

I was not disappointed. I subclassed Vector, rewrote the constructor and destructor and added another method for good measure.
In short, the main program now looks like this:

10 0 instance Dogs Lassies             \ create a "dogs" vector of ten dogs
                 
Lassies -> barking                     \ now let all the dogs bark
Lassies delete                         \ delete the vector

Not too shabby! ;-)

Hans Bezemer

Phillip Kelly

unread,
Mar 20, 2023, 4:25:25 PM3/20/23
to 4th-co...@googlegroups.com
That's very nice.

It is actually very similar to the Python pickle format used for serialization and deserialization of datasets for machine learning that I am reading about atm.

Phillip Kelly

unread,
Mar 20, 2023, 4:29:20 PM3/20/23
to 4th-co...@googlegroups.com
I should add, that it is the pickle dictionaries I am referring to in my last email...the formatting is similar

On Tue, Mar 21, 2023 at 3:26 AM The Beez <the.bee...@gmail.com> wrote:

The Beez

unread,
Mar 21, 2023, 12:11:05 PM3/21/23
to 4tH-compiler
.. and while was at it, I decided to use the DSTR.4PP lib in all FOOS programs. It was not too hard to implement. Got it right almost first time.

Hans Bezemer
Reply all
Reply to author
Forward
0 new messages