LICPP
LICPP copied to clipboard
Need an elegant way to implement `multiple-value-bind`
It is currently impossible to implement multiple-value-bind
.
In fact we can do something similar to std::tie
by:
type foo, bar;
mvb(a_cons, cons(&foo, &bar), rest);
But this requires variable declaration in advance, which is not what we want.
A well-packed dirty hack is acceptable as long as it is not directly exposed to the user.
The current implementation is:
a helper function _mvb
that binds a list of values to a list of pointers (basically, by assignment)
a type _values_t
that evals into the type of the list of pointers corresponding to the list of values
finally the wrapper function multiple_value_bind
that takes a list as its first argument, and rest pointers of variables, it will bind the values and return a lambda expression that takes an expression, after the expression, bind the original values of the pointers back to them.
Maybe std::bind
is a good direction to give a try