I saw David’s clever use of destructuring-bind
in quicksort and thought, it looks like a pretty simple special form to implement.
The core would be this:
object* destructure (object* structure, object* data, object** env) {
if (structure == nil) return;
if (symbolp(structure)) push(cons(structure, data), *env);
else if (consp(structure)) {
if (!consp(data)) error(canttakecar, data);
destructure(car(structure), car(data), env);
destructure(cdr(structure), cdr(data), env);
}
else error(invalidarg, structure);
}
I think that all that would be needed would be to wrap it in a special form function that can be called by uLisp. I would also want to add support for &optional in the structure form, and this could also be added to closure()
so that lambdas can be destructed too.
If I implement this and get it working, I will add it to my page of uLisp patches.