-
Notifications
You must be signed in to change notification settings - Fork 33
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
Proposal: A suite of generally useful functions #182
Comments
(I thought I replied to it but apparently I never submitted... oops) I like this idea and pondered for a while to start a kind of "standard library" with useful functionality implemented in ucode. Question is how to package it (ucode-stdlib?) and how to organize the "classes" within that library, e.g. whether to use python style short names (math, itertools, array, ...) or Java style name hierarchies... I'm slightly leaning towards the short name approach but would love to hear other opinions. |
It was many thousands of years ago since I wrote Java. Would you remind us of what its name hierarchies are like? |
Example from the official documentation: https://docs.oracle.com/javase/7/docs/api/index.html |
Got it. So, more levels, I take it. Personally, I don't have a strong opinion one way or the other. |
Okay, so let's define a number of "classes" based upon your submission:
Maybe the "random" and "output" modules are too narrow in scope and should be made into a "numeric" and "data" module to deal with anything numerical (calculations, randomness, ...) and data structure (formatting, transforming, higher level structures) respectively. |
I added the functions |
Cool! Some of the functions in "general" are not array related, or only partially so, so if there will be a class called "array", they should probably be outside of it:
(I assume it was meant to say "datetime".) Yeah, date calculation and manipulation would be useful. It's a mess to deal with, so I'm thinking that it makes sense to call upon some existing library.
The "random" category should probably be extended:
|
Updated the |
I propose here a suite of functions that I found myself reaching for, and missing in the standard library. I present them in ucode, as that's how I use them; possibly, they should be implemented in C instead.
The tests at the end demonstrates what the functions do.
General
General-purpose functions, most of them for analyzing or manipulating arrays. A source of inspiration is Python's itertools. However, as ucode does not have iterators with lazy evaluation (right?), some of the itertools functions do not make sense in ucode, and some other might be less efficient.
Printing
The pretty printer was written before I learned that there already is one! However, I think I can offer two improvements with my version: it prints
[ ]
and{ }
on a single line, and it breaks arrays and objects into multiple lines only when needed to avoid values being too long. Also I'm happy about how short the function could be made (after several rewrites).Time
Random
Returns random data in a few useful forms. Gets its randomness from
/dev/random
.Tests
The text was updated successfully, but these errors were encountered: