[racket] Pattern patching and structures

From: José Lopes (jose.lopes at ist.utl.pt)
Date: Wed Nov 16 00:56:31 EST 2011


Thank you for the quick reply. I am aware of the code replacement you 

However, what I really wanted was to preserve the name of the local 
variable (e.g., brick) and find some other way to refer to the 
structure (e.g., struct:brick).

I prefer this naming convention because I refer to local variables much 
more often than I refer to structures. Therefore, I think the code is 
more readable if it is possible to preserve the names of local 
variables that are instances of structures, and every now and then 
refer to the structure with an alternate name to escape name shadowing.

I was playing with omit-define-syntaxes and constructor-name.
However, I didn't find a combination of structure parameters that would 
help me do exactly what I have described.

Is there a way to do it?


On quarta-feira, 16 de Novembro de 2011 13:41:35, Asumu Takikawa wrote:
> On 2011-11-16 13:11:33 +0800, José Lopes wrote:
>> (define-struct brick
>>    (shape cs size))
>> and the following function
>> (define (right brick)
>>    (match brick
>>      ((struct struct:brick (shape cs size))
>>       (make-brick shape (xy (- (x size) 1) (y size)) size))))
> The function argument binding "brick" is capturing the "brick"
> identifier in the match pattern. If you rename the argument and use
> "brick" instead of "struct:brick" here it should work.
> Cheers,
> Asumu
> _________________________________________________
>    For list-related administrative tasks:
>    http://lists.racket-lang.org/listinfo/users

José António Branquinho de Oliveira Lopes
58612 - MEIC-A
jose.lopes at ist.utl.pt

Posted on the users mailing list.