[gambit-list] looking for a "weak" apply function

Christian christian at pflanze.mine.nu
Sun Nov 12 09:07:00 EST 2006


Hello

apply is quite a handy simple mechanism for destructuring lists, but:
if the list doesn't match the function prototype, an exception is
thrown. Sometimes I don't want to get an exception but instead try to
apply another function (more generally: to back-track).

So I'm looking for an alternative apply function which takes an
alternative continuation as a third argument (instead of the implicit
consing mechanism offered by standard apply when giving it multiple
arguments):

 (cond-apply
    fn1
    lis
    (lambda ()
       (cond-apply
          fn2
          lis
          (lambda ()
             (error "no match:" lis)))))

or

 (or (cond-apply fn1 lis)
     (cond-apply fn2 lis) 
     (error "no match:" lis))

call-with-exception-* don't do any good since it's relatively slow
and, worse, would leave the handler in place while the called function
is running.

I'm remembering a lowlevel function to get the arity of a function
(returning a positive fixnum for a fixed number of arguments, and a
negative fixnum if the function is taking a rest argument). Strangely,
I cannot find it again now. What is it called? (Or did I see it in
Chicken, not Gambit?) If that function is efficient, I could write
cond-apply in a fairly efficient way.

Thanks
Christian.




More information about the Gambit-list mailing list