chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Re: A few questions


From: John Cowan
Subject: Re: [Chicken-users] Re: A few questions
Date: Thu, 31 Jan 2008 16:22:52 -0500
User-agent: Mutt/1.5.13 (2006-08-11)

Elf scripsit:

> > In any case, figuring out how many of its arguments a procedure
> > examines is equivalent to solving the halting problem, alas.
> 
> um, how do you figure its the same as the halting problem?  to me it
> clearly isnt.  min arg counts are trivial, max arg counts are slightly
> harder but clearly feasible, and determining the number of args for
> something like case-lambda... well, go look at the svn logs at my insane
> (reverted) case-lambda.  its a fairly trivial problem.

Yes, if you get control at the macro level.  But the rest list is a list;
the procedure can pass it, or parts of it, to arbitrary other procedures
that act in arbitrary ways on it, so you can't be sure exactly which
parts eventually get looked at and which don't.

You can handle stereotyped cases like case-lambda and the DSSSL functions,
but when people use a rest argument and then pick optional arguments out
of it with explicit cars and cadrs and all, you aren't going to be able
to return something that encodes "accepts two, three, or five arguments".

> perhaps if there was no requirement to wrap [multiple values] in
> call-with-values, it would be more palatable.

See SRFI 8, which Chicken implements and which is designed to make
receiving multiple values very easy.

> example of the last bit: (define (foo x)
>     (values x x))
> 
> (define (bar x y)
>     (+ x y))
> 
> (bar (foo x)) would be a valid call, with bar-x bound to foo-x and
> bar-y bound to foo-x, if multivals were handled better.

I can't find the paper that explains why this superficially attractive
idea (which has been reinvented over and over) is actually a nightmare
of pessimization.  But just consider the problem of the flow analysis you
need to do in order to figure out at compile time whether bar is being
called with the right number of arguments or not.

> the extra syntax requirements and cpu time i think are what annoys me.

In fact the CPU cost is nil on Chicken (or any CPS-based compiler):
all that's happening is that the multiple-valued procedure is calling
its continuation with two or more arguments -- or zero arguments, if
it returns (values).  Multiple values are just the dual of multiple
arguments, and CPS makes them perfectly equivalent.

-- 
After fixing the Y2K bug in an application:     John Cowan
        WELCOME TO <censored>                   address@hidden
        DATE: MONDAK, JANUARK 1, 1900           http://www.ccil.org/~cowan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]