+/* Take a list consisting of a closure and some other things. Apply the
+ closure to the other things, and return the resulting list */
+static list_t *map(closure_t *self, struct cloc loc, dict_t *context,
+ list_t *args)
+{
+ list_t *r=NULL, *al;
+ item_t *ci;
+ closure_t *cl;
+ list_t se;
+
+ ci=list_elem(args,0);
+ if (ci && ci->type==t_closure) {
+ cl=ci->data.closure;
+ if (!cl->apply) {
+ cfgfatal(loc,"map","closure cannot be applied\n");
+ }
+ for (al=args->next; al; al=al->next) {
+ /* Construct a single-element list */
+ se.next=NULL;
+ se.item=al->item;
+ /* Invoke the closure, append its result to the output */
+ r=list_append_list(r,cl->apply(cl,loc,context,&se));
+ }
+ } else {
+ cfgfatal(loc,"map","you must supply a closure as the "
+ "first argument\n");
+ }
+ return r;
+}
+