[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Callbacks in the abstact data types and extra contextual data
From: |
Bruno Haible |
Subject: |
Re: Callbacks in the abstact data types and extra contextual data |
Date: |
Fri, 10 Jul 2020 20:37:57 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-179-generic; KDE/5.18.0; x86_64; ; ) |
Hi Marc,
> > > a number of modules (like the hash module or the list module) allow
> > > the user to specify callbacks (e.g. a comparison function).
> > > Unfortunately, these procedures do not take a context parameter, which
> > > can be a problem because C lacks closures.
> >
> > Is this a practical, actual problem, or only a theoretical one?
>
> It is a practical one; in a computer algebra application, I have lots
> of small entities (two words each), whose sort order is determined by
> the extra data.
OK. Then let's take the problem seriously.
I think it's time to solve the problem once and for all. I propose to add
a module that defines a function 'partial_function_last' such that, when
you have a function pointer
int (*cmp3) (void *arg1, void *arg2, void *context)
then
cmp2 = partial_function_last (cmp3, context);
produces a function pointer
int (*cmp2) (void *arg1, void *arg2)
that invokes cmp3 with the given context.
Wikipedia calls it "partial function application".
The module will also have a function 'partial_function_free' that frees
a function that was constructed in this way.
Give me a couple of days to implement that.
Bruno