Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Venery (Collections for Forth) #77

Open
RogerLevy opened this issue Nov 19, 2018 · 8 comments
Open

Venery (Collections for Forth) #77

RogerLevy opened this issue Nov 19, 2018 · 8 comments

Comments

@RogerLevy
Copy link
Member

I was inspired by 8th's collections and decided to start a collections library for standard Forth.

Spent just 5 or 6 hours and already we've got basic functionality on arrays, strings, and node trees. All tested and working.

Arrays and strings are static but node allocation is user-defined (an example using system heap is in the test code at the bottom)

https://github.com/RogerLevy/venery

@larsbrinkhoff
Copy link
Member

Nice!

@AntonErtl
Copy link

The ffl (Forth Foundation Library) contains collections.

@RogerLevy
Copy link
Member Author

RogerLevy commented Nov 19, 2018

True. This is a framework in classic minimalist Forth style. And it will provide a set of common commands that will work on different kinds of collections - operations like search, itterate (with break) join, split, push, pop etc. It is meant more as a dialect you adopt, like those OO extensions.

@pahihu
Copy link

pahihu commented Nov 20, 2018

+1

See Rob Pike: “Notes on Programming in C" (https://www.lysator.liu.se/c/pikestyle.html) section Complexity Rule 4.

"The following data structures are a complete list for almost all practical programs:
array
linked list
hash table
binary tree"

@alexshpilkin
Copy link
Member

Well, first of all, a good collections library is hard. The Scheme list library (SRFI 1) took a lot of design work, and it only deals with a particular flavour of singly linked lists in a case that’s easier than that in Forth (higher-order functions, automatic memory management). The C++ people thought they they had it... until they hadn’t, and even berfore people with specialized needs (read: heavy users of the containers) complained that the libraries were at the same time slowed down by their generality and not general enough (and again, the C++ case, where opaque non–machine-word–sized things can be treated as first-class, is easier abstraction-wise). The Rust people may also have something interesting to say in this respect.

So it’s good to have more than one general-ish Forth data structures library, I think.

The Pike quote is better taken with a grain of salt. His context essentially presumes the absence of libraries, i.e. what you should be ready to reimplement yourself (and be alarmed if you stray outside), rather than what you should expect in a library. The things he mentions are thus better thought of as categories of data structures than concrete data structures.

Linked lists, in particular: singly- or doubly-linked? Intrusive or not? Circular or not, distinguished head node or not? If singly-linked, use O(1) deletion at the cost of copying the node contents (needs sentinel tail node), or keep a pointer to the previous node while iterating, or settle for O(n) deletion? If doubly-linked, use the Knuth XOR trick to halve the overhead or not? &c.

The ways to implement hash tables are even more diverse. (I’ll also dare to presume that Pike didn’t include crit-bit/PATRICIA/&c. trees on his list because he didn’t know about them.) And we haven’t even touched dynamic memory allocation, which is both difficult interface-wise and shouldn’t be implemented using only the structures on Pike’s list (unless “arrays” are counted very loosely).

@pahihu
Copy link

pahihu commented Nov 20, 2018

Nice overview, thanks.

@RogerLevy
Copy link
Member Author

I'm not doing any fancy tricks, so it won't have blazing speed. I'll optimize it here and there but I'll leave the hardcore work to others assuming it got adopted on any scale. Primary goals are to make it easy-to-use and powerful.

@RogerLevy
Copy link
Member Author

RogerLevy commented Nov 25, 2018

Just added several words (insertion, deletion, joining, conditional iteration)

Also documented all the commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants