[racket-dev] [racket] match in Advanced Student?

From: Sam Tobin-Hochstadt (samth at ccs.neu.edu)
Date: Tue Nov 1 07:47:52 EDT 2011

[switching to dev@]

Probably the right way to do this is for me to add a
`prop:match-expander' which can be added to arbitrary structure, and
then to use that in lang/private/firstorder on the `fo' struct.

On Mon, Oct 31, 2011 at 11:41 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
> I think extending define-primitive the right thing to do... just
> saying it isn't what I did.
>
> On Mon, Oct 31, 2011 at 9:02 PM, Robby Findler
> <robby at eecs.northwestern.edu> wrote:
>> Are you referring to the special case on line 2730 of teach.rkt when
>> you say posns?
>>
>> I think that means that I'd have to make the teaching language depend
>> on 2htdp/image, which doesn't seem right.
>>
>> I would have thought that the right thing would be to extend the
>> define-primitive protocol so that I can declare that 'color' is both a
>> function and a struct constructor and then match would not have to
>> special case 'color'. No?
>>
>> Robby
>>
>> On Mon, Oct 31, 2011 at 9:48 PM, Jay McCarthy <jay.mccarthy at gmail.com> wrote:
>>> The HtDP match implementation has a list of such things and goes and
>>> finds them to turn them back into the non-primitive bound things.
>>> That's why it works with posns.
>>>
>>> Something better could be done, but for now you could add it to the white list.
>>>
>>> Jay
>>>
>>> On Mon, Oct 31, 2011 at 8:45 PM, Robby Findler
>>> <robby at eecs.northwestern.edu> wrote:
>>>> Oh, I see why. 'color' is bound using define-primitive in order to
>>>> cooperate with the beginner language (and so that 'color' can be a
>>>> constructor). But doing that interferes with the usual information
>>>> bound by a struct that match picks up.
>>>>
>>>> I'm not sure what the right way to resolve this is.
>>>>
>>>> Robby
>>>>
>>>> On Mon, Oct 31, 2011 at 9:39 PM, Robby Findler
>>>> <robby at eecs.northwestern.edu> wrote:
>>>>> Is make-color coming from 2htdp/image? I see that's not working (not
>>>>> sure why yet).
>>>>>
>>>>> Robby
>>>>>
>>>>> On Mon, Oct 31, 2011 at 9:34 PM, Adam Shaw <adamshaw at cs.uchicago.edu> wrote:
>>>>>> Thanks! That still doesn't work for color:
>>>>>>   match: color does not refer to a structure definition
>>>>>> although it does work with my own custom color struct:
>>>>>> (define-struct clr (r g b))
>>>>>> (match (make-clr 1 2 3)
>>>>>>   [(struct clr (r g b)) (* r g b)])
>>>>>>   - Adam
>>>>>> On Oct 31, 2011, at 9:26 PM, Jay McCarthy wrote:
>>>>>>
>>>>>> One of the branches of the pattern language is
>>>>>>
>>>>>> | (struct id (pattern ...))
>>>>>>
>>>>>> Your pattern should be
>>>>>>
>>>>>> (struct color (r g b))
>>>>>>
>>>>>>
>>>>>> _________________________________________________
>>>>>>  For list-related administrative tasks:
>>>>>>  http://lists.racket-lang.org/listinfo/users
>>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Jay McCarthy <jay at cs.byu.edu>
>>> Assistant Professor / Brigham Young University
>>> http://faculty.cs.byu.edu/~jay
>>>
>>> "The glory of God is Intelligence" - D&C 93
>>>
>>
>
>
>
> --
> Jay McCarthy <jay at cs.byu.edu>
> Assistant Professor / Brigham Young University
> http://faculty.cs.byu.edu/~jay
>
> "The glory of God is Intelligence" - D&C 93
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users



-- 
sam th
samth at ccs.neu.edu



Posted on the dev mailing list.