Re: Functional programming with GLib



I was thinking about that, but then fell into the trap of worrying
about suggesting it because someone might expect me to implement it.

I agree though; a reworking of GOptionContext which integrates better
with GApplication, supports sub-commands and supports custom argument
formats more easily would be lovely. Drawing inspiration from python-
argparse would also be good.

Philip

On Thu, 2017-04-27 at 15:29 +0100, Emmanuele Bassi wrote:
For command line parsing I'd actually favour a slightly bolder
approach of deprecating GOptionContext, and having something slightly
more modern — in terms of being bindable in other languages, and
well-integrated with API like GApplication.

For instance, something similar to [clap.rs][0].

Ciao,
 Emmanuele.

[0]: https://clap.rs/

On 27 April 2017 at 15:15, Philip Withnall <philip tecnocode co uk>
wrote:
Hey,

The general policy for GLib is that utility functions which are
useful
(and used in) several projects are considered for being added to
GLib.

To me, a functional programming approach using GLists is not
something
which every project is going to use. Is there any harm in keeping
it as
a separate library? There’s nothing stopping projects from linking
to
GLib *and* GXLib. :-)

The command line parsing stuff you have looks a bit more widely
applicable. Were you considering merging those into GLib?

http://www.djcbsoftware.nl/code/gxlib/gxlib-Command-line-parsing.ht
ml

Anyway, nice work on GXLib. It looks well documented.

Philip

On Sun, 2017-04-23 at 21:46 +0300, Dirk-Jan C. Binnema wrote:
Hi All,

A while back, I wrote some functions for functional-flavored
programming
with GLib. It's fully documented[1], has tests, etc.

It would (for me at least) be useful to have some of these
functions
in
GLib-proper, but I suspect the GLib-maintainers are not /too/
eager
to
accept contributions to GList... anyway, perhaps its useful for
others.

As a simple example, suppose we want to calculate the sum of
primes
up
to 100 (a common task after all):

,----
int    sum;
GList *nums, *primes;

nums   = gx_list_iota (100, 1, 1);
primes = gx_list_filter (nums, (GXPred)gx_is_prime, NULL);
sum    = gx_list_sum (primes); /* => 1060 */

g_list_free (nums);
g_list_free (primes);

`----

There's also folding, mapping etc. See a short article about
this:
   http://www.djcbsoftware.nl/2015/10/04/functional-glists/
(2015?! time does fly). Am still developing it though.

Repo: https://github.com/djcb/gxlib
Docs: http://www.djcbsoftware.nl/code/gxlib/

Best wishes,
Dirk.


_______________________________________________
gtk-devel-list mailing list
gtk-devel-list gnome org
https://mail.gnome.org/mailman/listinfo/gtk-devel-list



Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]