Adam Shaw | 1 Nov 2011 03:21
Favicon

Re: match in Advanced Student?

Since pattern matching has been a topic of discussion lately -- I'm trying to get simple pattern matching to work in Adv. Student -- for example this expression:

(match (make-color 1 2 3)
  [(make-color r g b) (* r g b)])

gets this response 

  match: expected a pattern, but found a part

I would appreciate an explanation or a pointer to how I can understand this. Thanks.

 - A dam
<div>
<div>Since pattern matching has been a topic of discussion lately -- I'm trying to get simple pattern matching to work in Adv. Student -- for example this expression:</div>
<div><br></div>
<div>(match (make-color 1 2 3)</div>
<div>&nbsp; [(make-color r g b) (* r g b)])</div>
<div>
<div><br></div>
<div>gets this response&nbsp;</div>
<div><br></div>
<div>&nbsp; match: expected a pattern, but found a part</div>
<div><br></div>
<div>I would appreciate an explanation or a pointer to how I can understand this. Thanks.</div>
<div><br></div>
<div>&nbsp;- A
 dam</div>
</div>
</div>
Jay McCarthy | 1 Nov 2011 03:26
Picon
Gravatar

Re: match in Advanced Student?

One of the branches of the pattern language is

|	 	(struct id (pattern ...))

Your pattern should be

(struct color (r g b))

On Mon, Oct 31, 2011 at 8:21 PM, Adam Shaw <adamshaw <at> cs.uchicago.edu> wrote:
> Since pattern matching has been a topic of discussion lately -- I'm trying
> to get simple pattern matching to work in Adv. Student -- for example this
> expression:
> (match (make-color 1 2 3)
>   [(make-color r g b) (* r g b)])
> gets this response
>   match: expected a pattern, but found a part
> I would appreciate an explanation or a pointer to how I can understand this.
> Thanks.
>  - Adam
> _________________________________________________
>  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

_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users
Adam Shaw | 1 Nov 2011 03:34
Favicon

Re: match in Advanced Student?

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))

<div>Thanks! That still doesn't work for color:<div><br></div>
<div>&nbsp; match: color does not refer to a structure definition</div>
<div><br></div>
<div>although it does work with my own custom color struct:</div>
<div><br></div>
<div>
<div>(define-struct clr (r g b))</div>
<div>(match (make-clr 1 2 3)</div>
<div>&nbsp; [(struct clr (r g b)) (* r g b)])</div>
<div><br></div>
<div>&nbsp; - Adam</div>
<div><br></div>
<div>
<div>On Oct 31, 2011, at 9:26 PM, Jay McCarthy wrote:</div>
<br class="Apple-interchange-newline"><blockquote type="cite"><div>One of the branches of the pattern language is<br><br>|<span class="Apple-tab-span">	</span> <span class="Apple-tab-span">	</span>(struct id (pattern ...))<br><br>Your pattern should be<br><br>(struct color (r g b))<br>
</div></blockquote>
</div>
<br>
</div>
</div>
Robby Findler | 1 Nov 2011 03:39
Gravatar

Re: match in Advanced Student?

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
>

_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users
Adam Shaw | 1 Nov 2011 03:44
Favicon

Re: match in Advanced Student?

It's the same error with or without. Here's the error:

match: color does not refer to a structure definition

Here are two complete source files (no teachpacks), running Adv. Student, DrRacket 5.1.3.

;; begin file 1
(match (make-color 1 2 3)
  [(struct color (r g b)) (+ r g b)])

;; begin file 2
(require 2htdp/image)
(match (make-color 1 2 3)
  [(struct color (r g b)) (+ r g b)])

On Oct 31, 2011, at 9:39 PM, Robby Findler wrote:

Is make-color coming from 2htdp/image? I see that's not working (not
sure why yet).

Robby

<div>It's the same error with or without. Here's the error:<div><br></div>
<div>match: color does not refer to a structure definition</div>
<div><br></div>
<div>Here are two complete source files (no teachpacks), running Adv. Student, DrRacket 5.1.3.</div>
<div><br></div>
<div>
<div>;; begin file 1</div>
<div>(match (make-color 1 2 3)</div>
<div>&nbsp; [(struct color (r g b)) (+ r g b)])</div>
</div>
<div><br></div>
<div>;; begin file 2</div>
<div>
<div>(require 2htdp/image)</div>
<div>(match (make-color 1 2 3)</div>
<div>&nbsp; [(struct color (r g b)) (+ r g b)])</div>
</div>
<div>
<div>
<div><br></div>
<div>On Oct 31, 2011, at 9:39 PM, Robby Findler wrote:</div>
<br class="Apple-interchange-newline"><blockquote type="cite"><div>Is make-color coming from 2htdp/image? I see that's not working (not<br>sure why yet).<br><br>Robby<br>
</div></blockquote>
</div>
<br>
</div>
</div>
Robby Findler | 1 Nov 2011 03:45
Gravatar

Re: match in Advanced Student?

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
>>
>

_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users
Jay McCarthy | 1 Nov 2011 03:48
Picon
Gravatar

Re: match in Advanced Student?

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

_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users
Robby Findler | 1 Nov 2011 04:02
Gravatar

Re: match in Advanced Student?

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
>

_________________________________________________
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users
Jay McCarthy | 1 Nov 2011 04:41
Picon
Gravatar

Re: match in Advanced Student?

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
Matthew Flatt | 1 Nov 2011 13:20
Picon
Favicon
Gravatar

Re: get-slides-as-picts dimensions

At Mon, 31 Oct 2011 17:53:40 -0600, Jon Rafkind wrote:
> I hacked up this short program to fade between slides. It seems to
> work well (although it won't work for animations) but I'm wondering
> how to get rid of the hard coded size constraints (640, 480). I just
> want to generate slides that would be the normal size they would have
> looked like if I was running x.rkt.

A slide in Slideshow is always drawn as 1024 by 768 (and that size is
scaled to fit the actual screen size).


Gmane