Re: [racket] match in Advanced Student?

2011-10-31 Thread Jay McCarthy
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 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 lang

Re: [racket] match in Advanced Student?

2011-10-31 Thread Robby Findler
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

Re: [racket] match in Advanced Student?

2011-10-31 Thread Jay McCarthy
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 Findle

Re: [racket] match in Advanced Student?

2011-10-31 Thread Robby Findler
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

Re: [racket] match in Advanced Student?

2011-10-31 Thread Adam Shaw
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

Re: [racket] match in Advanced Student?

2011-10-31 Thread Robby Findler
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 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 stru

Re: [racket] match in Advanced Student?

2011-10-31 Thread Adam Shaw
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 w

Re: [racket] match in Advanced Student?

2011-10-31 Thread Jay McCarthy
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 wrote: > Since pattern matching has been a topic of discussion lately -- I'm trying > to get simple pattern matching

Re: [racket] match in Advanced Student?

2011-10-31 Thread Adam Shaw
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 wou

[racket] get-slides-as-picts dimensions

2011-10-31 Thread Jon Rafkind
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 ru

Re: [racket] match in Advanced Student?

2011-10-31 Thread Prabhakar Ragde
On 10/31/11 3:42 PM, Shriram Krishnamurthi wrote: I found this confusing when I first encountered it -- the patterns are at the TOP of the page (but not linked from the match docs). Scroll to the top and look for "pattern" in the BNF. Thanks, Shriram. That plus the Guide entry will probably do

Re: [racket] set! racket behaviour

2011-10-31 Thread Dan Grossman
I also found it counterintuitive that #lang racket (define x 0) (set! x 1) works, but moving the set! out of the module and into the REPL does not. But Dave has pointed to the exact line in the Guide that makes this clear: A module-level definition is mutable only if there is a set! for it in th

Re: [racket] match in Advanced Student?

2011-10-31 Thread Shriram Krishnamurthi
I found this confusing when I first encountered it -- the patterns are at the TOP of the page (but not linked from the match docs). Scroll to the top and look for "pattern" in the BNF. On Mon, Oct 31, 2011 at 3:16 PM, Jay McCarthy wrote: > http://docs.racket-lang.org/htdp-langs/advanced.html > >

Re: [racket] match in Advanced Student?

2011-10-31 Thread Jay McCarthy
http://docs.racket-lang.org/htdp-langs/advanced.html On Mon, Oct 31, 2011 at 1:00 PM, Prabhakar Ragde wrote: > Is there a written description (suitable for students) of which patterns are > legal for `match' in Advanced Student, or do I have to dig into the > implementation and then write one mys

[racket] match in Advanced Student?

2011-10-31 Thread Prabhakar Ragde
Is there a written description (suitable for students) of which patterns are legal for `match' in Advanced Student, or do I have to dig into the implementation and then write one myself? Thanks. --PR _ For list-related administrative tasks: http:

Re: [racket] set! racket behaviour

2011-10-31 Thread Neil Van Dyke
Parameters are very useful. See: http://docs.racket-lang.org/reference/parameters.html Neil Van Dyke wrote at 10/31/2011 01:06 PM: jkaczo...@aol.pl wrote at 10/31/2011 12:58 PM: Of course, I realize, that redefinition of the variables is not good (functional) programming style but sometimes i

Re: [racket] set! racket behaviour

2011-10-31 Thread Neil Toronto
You could also make your intentions more explicit using #lang racket (define counter (box 0)) In the REPL, you would then do (set-box! counter (add1 (unbox counter))) Neil T On 10/31/2011 11:20 AM, David Vanderson wrote: I think you are running into the issue described here: http

Re: [racket] set! racket behaviour

2011-10-31 Thread Erich Rast
Doesn't really answer your question, but why not use something like this instead: (define inc (let ((counter 0)) (lambda () (set! counter (add1 counter)) counter))) Best, Erich On Mon, 2011-10-31 at 12:58 -0400, jkaczo...@aol.pl wrote: > Hi, > > I’m using DrRacket. > In an e

Re: [racket] set! racket behaviour

2011-10-31 Thread David Vanderson
I think you are running into the issue described here: http://docs.racket-lang.org/guide/module-set.html "Along the same lines, when a module contains no set! of a particular identifier tha

Re: [racket] set! racket behaviour

2011-10-31 Thread Neil Van Dyke
jkaczo...@aol.pl wrote at 10/31/2011 12:58 PM: Of course, I realize, that redefinition of the variables is not good (functional) programming style but sometimes it's necessary. Is there a possibility of such modifications without changing language? You might wish to use a parameter, like in th

[racket] set! racket behaviour

2011-10-31 Thread jkaczorek
Hi, I’m using DrRacket. In an edit window I have written: #lang racket (define counter 0) I’m pressing “Run” button and next, in a command line, after running a command: (set! counter (add1 counter)) I receive a message “set!: cannot modify a constant: counter” The problem can be resolved by

Re: [racket] FFI & pointers

2011-10-31 Thread Matthew Flatt
At Sat, 29 Oct 2011 14:32:42 +0400, Aleksei Pastutsan wrote: > I try to use computer vision library with racket. > > ;; API > (define libhighgui (ffi-lib "libhighgui" '("2.1" "4"))) > (define-cpointer-type _cv-capture) > > ;; /* start capturing frames from camera: index = camera_index + > domain_

[racket] FFI & pointers

2011-10-31 Thread Aleksei Pastutsan
I try to use computer vision library with racket. ;; API (define libhighgui (ffi-lib "libhighgui" '("2.1" "4"))) (define-cpointer-type _cv-capture) ;; /* start capturing frames from camera: index = camera_index + domain_offset (CV_CAP_*) */ ;; CVAPI(CvCapture*) cvCreateCameraCapture( int index );

Re: [racket] Text% and editor-canvas% typewriter scrolling

2011-10-31 Thread Matthew Flatt
I'm sure you could implement this with your own canvas and `editor-admin%' classes. It may be possible to implement this with the existing `editor-canvas%' class, but probably not. If `scroll-to' in `editor-canvas%' could really be overridden, for example, that might get close; the layer at which