Comment 4 for bug 378735

Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote : Re: [Bug 378735] Re: Missing source annotations

On May 25, 2009, at 9:20 AM, leppie wrote:

> Hi
>
> This works, thanks, but the behaviour is rather inconsistent now as
> both
> the following forms end up as annotated-call:

You mean annotated-lambda, right?

> (define
> (foo x) ; <- this list is the 'area' for the 'lambda'
> (+ x 1))
>
> (define bar
> (lambda (x) (+ x 1)) ; <- this list is the 'area' for the 'lambda'
> )

What exactly is an 'area'? In Ikarus, I only have a starting
position in an annotation, but I presume you have a start and
end positions that constitute this area, right? The annotation
psyntax now uses for lambda is the whole (lambda ---) form
while the one it uses for (define (name . ---) ---) is the name
form. So, your first example should say:

(define (
          foo ; <- this is the area for the lambda
          x)
   (+ x 1))

right?

One way to make it more consistent is to change the lambda
annotation so that it only grabs the "lambda" keyword in the
(lambda ---) form.

> Now I can live with the above handling, but would prefer that the body
> of the function be wrapped in the 'area'.
>
> IOW for the first example it will be:
>
> (define (foo x) (+ x 1)) ; <- this list is the 'area' for the
> 'lambda'

I think this is how it used to be before the commit, right?
The general problem we have is that syntax-case strips out
some syntax information as it destructures the syntax object
and constructs plain pairs that have no syntax information.
(the user too can construct plain pairs using cons, map, ...)
So, after a macro step, we're guaranteed that identifiers have
their annotations intact but we don't have the same guarantee
for lists. This is why I think using the "lambda" keyword as
the annotation is better than using the whole (lambda ---)
form.

Anyways, try to experiment with chi-defun in the expander,
passing different objects (x, kwd, ctxt, body*, ...) to see
what's the best effect for you and I can accommodate.

   (define (chi-defun x r mr)
     (syntax-match x ()
       [(kwd (ctxt . fmls) . body*)
        (let-values (((fmls body)
                      (chi-lambda-clause fmls fmls body* r mr)))
           (build-lambda (syntax-annotation ctxt) fmls body))]))

> I know I pass psyntax an annotation for that 'area'. But keeping track
> of it (from what I can see) looks like quite involved.

For macros, yes. I need to think about it some more. Keep
me posted.

Aziz,,,