[racket] prefix/rename for signatures in unit and define-signature forms

From: dfeltey at ccs.neu.edu (dfeltey at ccs.neu.edu)
Date: Fri May 9 16:39:34 EDT 2014

I've been digging in to this some more, and it seems that the prefix form works backwards on a sig-spec, for example:

(define-signature a^ (a))
(define-signature dcc^ ((open (prefix d: (prefix c: (prefix c: a^))))))
(define d@ (unit (import dcc^) (export) c:c:d:a))

(unit (import)
      (export (prefix d: (prefix c: (prefix c: a^))))
      (define c:c:d:a 5))

This makes some sort of sense, I suppose, but it doesn't really match what the docs seem to say.

On the other hand rename does seem to work in expected way when used by itself:

(define-signature da^
  ((open (rename (rename (rename a^ (b a)) (c b)) (d c)))))
(unit (import da^) (export) d)
(unit (import (rename (rename (rename a^ (b a)) (c b)) (d c))) (export) d)

When I try to nest different combinations of rename and prefix together, however, I get the strange behavior I was experiencing yesterday, and I cannot figure out how to correctly reason about what the resulting bindings should be.

Thanks
Dan


----- Original Message -----
From: dfeltey at ccs.neu.edu
To: users at racket-lang.org
Sent: Thursday, May 8, 2014 4:56:52 PM GMT -05:00 US/Canada Eastern
Subject: [racket] prefix/rename for signatures in unit and define-signature forms

I'm trying to make sense of how prefix/rename work for signatures, but in trying to run some examples the actual implementation doesn't seem to match either my intuition or the documentation. 

For example I have the following simple signature:

(define-signature a^ (a))

I then try to build a new signature from a^ with a combination of open and prefix/rename.

(define-signature b-bad^
  ((open (prefix x: (rename (prefix y: a^) (q y:a))))))

This example, however, gives the error: 
"open: listed identifier not present in signature specification in: x:y:a"

I'm not sure I understand this since it appears as though prefixing x: comes before the renaming, but I would have though that first y: is prefixed to a, so that y:a is in the signature which can then be renamed q. So in the end the only variable in the signature should be x:q.

Attempting the same in a unit form gives a similar error:

(define u-bad 
  (unit (import (prefix x: (rename (prefix y: a^) (q y:a)))) 
        (export)
        x:q))
"unit: listed identifier not present in signature specification in: x:y:a"


If I change the prefix x: to y: things seem to work for some reason.

(define-signature b-good^
  ((open (prefix y: (rename (prefix y: a^) (q y:a))))))

In this case, I still expect the variable in the signature to be something like y:q, but trying a similar renaming in a unit form fails:

(define u-bad2 
  (unit (import (prefix y: (rename (prefix y: a^) (q y:a)))) 
        (export)
        y:q))

With the error:
"y:q: unbound identifier in module in: y:q"

 while the following does work

(define u-good 
  (unit (import (prefix y: (rename (prefix y: a^) (q y:a)))) 
        (export)
        q))


Am I misunderstanding something obvious about the way that the renaming/prefixing should be taking place on the level of a signature or unit import/export clause? The results I'm seeing are completely unintuitive to me and the documentation doesn't seem to clarify this for me.

Thanks
Dan
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Posted on the users mailing list.