Added VEACH method to VECTOR

19 views
Skip to first unread message

The Beez

unread,
Jan 27, 2024, 1:08:42 PMJan 27
to 4tH-compiler
Hi 4tH-ers!

If you don't like OOP, stop reading. You might remember I turned the dynamic array library into an OOP vector library some time ago.

You might be happy to know I added a FOREACH like method to it. It takes an execution token, which it will apply to the contents of every element.  You read that correctly - the contents, not the address of the element. The dynamic array library doesn't support raw addresses anyway, but requires the address of the entire array and an index.

But if you stored pointers to objects there, it is quite useful. It really simplified the FOOS ARRY.4pp example. E.g. the deconstructor of the Dogs vector can be reduced to:

  :delete [: delete ;] this -> veach ;method

And the barking method is simply:

  :method barking [: -> bark ;] this -> veach ;method

I hope you like this addition. MAP and REDUCE seem to be a bit harder, but given enough interest, I might give it a go as well.

Hans Bezemer

The Beez

unread,
Jan 28, 2024, 10:36:11 AMJan 28
to 4tH-compiler
Well, you know how it is. You're going through the code at night and think "Darn! I could have done the same thing here!"
And so it went. The LIST and HASHMAP FOOS libraries could do with a .EACH method too.

So today they got it. Several other (small) methods were added as well, and LIST was all done from the bottom up - rewritten, so to say.

A couple of FOOS programs could be simplified (significantly), but all in all it worked all as intended. Code in SVN.

Hans Bezemer
Reply all
Reply to author
Forward
0 new messages