[racket-users] Pixelated results from pict->bitmap

2017-07-13 Thread Philip McGrath
Bitmaps created using pict->bitmap look pixelated to me on screen (on Mac
OS in "Retina" mode, which I suspect might be relevant). I initially
discovered this when using picts as labels for message% instances like this:

#lang racket/gui

(require pict)

(define f
  (new frame%
   [label "Example"]))

(new message%
 [parent f]
 [label (pict->bitmap (disk 100))])


(new canvas%
 [parent f]
 [style '(transparent)]
 [min-width 100]
 [min-height 100]
 [paint-callback (λ (c dc)
   (draw-pict (colorize (disk 100) "green")
  dc
  0
  0))])
(send f show #t)


The black disk in the above is pixelated for me, while the green one drawn
on a canvas looks normal.

I also noticed as I was writing this that evaluating (pict->bitmap (disk
100)) in the DrRacket REPL produces a pixelated result compared to
evaluating (disk 100).

Is there either a way to avoid this in general, or else a recommended way
to do the equivalent of using picts for message% labels in particular? (I
suppose I could subclass canvas% …)

Thanks,
Philip

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Struggling with writing array generator function

2017-07-13 Thread Vasily Rybakov
Well, actually that will be nested vectors, I just used list as example.

I thought about storing arrays as one-dimentional vectors, but it makes hard to 
work with literal arrays. If I use nested vectors, then I can write something 
like:

(matrix-* A #[#[1 2 3] #[4 5 6]])

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Struggling with writing array generator function

2017-07-13 Thread Vasily Rybakov
Daniel, thank you for your response!

It really helped. I've focuded too much on recursion and tried to put nested 
array generation into it, without realizing that I can use external loop.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Struggling with writing array generator function

2017-07-13 Thread Daniel Prager
Hi Vasily

Since you insist ... ;-)

The main issue is how to reduce the number of args with each step of the
recursion: looks like a job for curry!

Here's one way to do it:

(define (generate-array n f)
  (for/list ([i 3])
(if (= n 1)
(f i)
(generate-array (sub1 n) ((curry f) i)

(generate-array 1 (lambda (i) 10))
(generate-array 1 (lambda (i) i))
(generate-array 2 (lambda (i j) (+ (* 10 i) j)))

A more robust version would introspect the number of arguments to f and
drop the need for an explicit n.
Also should guard against the n = 0 case.

Dan

On Fri, Jul 14, 2017 at 6:07 AM, Vasily Rybakov 
wrote:

> On Thursday, July 13, 2017 at 9:30:44 PM UTC+2, Daniel Prager wrote:
> > It's straightforward to design a recursive macro with similar intent,
> but different surface syntax:
> >
> > (generate-array (i) 10)
> > (generate-array (i) i)
> > (generate-array (i j) (+ (* 10 i) j))
> >
> >
> > Dan
>
>
> Thanks for the answer, but I really need to pass generating function to it.
>
> I know that expended recursion shiuld look something like this (for
> examples of functions of 1, 2 and 3 arguments):
>
> ((lambda (f) (build-vector 3 (lambda (x) (f x (lambda (i) i))
> ((lambda (f) (build-vector 3 (lambda (x) (build-vector 3 (lambda (y) (f x
> y)) (lambda (i j) (+ i j)))
> ((lambda (f) (build-vector 3 (lambda (x) (build-vector 3 (lambda (y)
> (build-vector 3 (lambda (z) (f x y z (lambda (i j k) 10))
>
>
> But I don't know how to make such a recursion, that will produce this
> expansions.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Struggling with writing array generator function

2017-07-13 Thread Neil Van Dyke
(If this is for a school assignment, and the following comments are 
confusing, please disregard them.  The comments might make a school 
assignment harder than it's supposed to be.)


Are you sure you want your n-dimensional arrays to be implemented as 
nested Racket lists?


What about a 1-dimensional Racket vector representation?  Very simple 
arithmetic turns an n-dimensional index into a 1-dimensional index into 
the vector.


This is how lower-level languages often lay out fixed n-dimensional 
arrays in contiguous bytes/words of memory.


https://en.wikipedia.org/wiki/Row-_and_column-major_order

If you're doing high-performance numeric work, you can even lay out 
native number arrays in ways that let you use super-fast specialized CPU 
instructions on them.  But that might be counterproductive for your 
immediate Racket needs.  But the flat vector is still a valid thing to 
do in Racket.


Reasons you might not want to do a flat vector is if you have sparse 
arrays that are very large, or you have sharing between arrays or parts 
of the same array.


--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Re: Struggling with writing array generator function

2017-07-13 Thread Vasily Rybakov
My current approach is to try to make recursion that will expand into somethig 
like this (for generator functions that accepts 1, 2 and 3 arguments 
respectively):

(define (bv func)
  (build-vector 3 func))

((lambda (f) (bv (lambda (x)
   (f x generator)

((lambda (f) (bv (lambda (x)
   (bv (lambda (y)
 (f x y)) generator)

((lambda (f) (bv (lambda (x)
   (bv (lambda (y)
 (bv (lambda (z)
   (f x y z generator)

; Curried version

((lambda (f) (bv (lambda (x)
   (f x (curry generator))

((lambda (f) (bv (lambda (x)
   (bv (lambda (y)
 ((f x) y)) (curry generator))

((lambda (f) (bv (lambda (x)
   (bv (lambda (y)
 (bv (lambda (z)
   (((f x )y) z (curry generator))

Can you help me with making recursion that expands like this?

Or it is wrong approach, and I should try something different?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Struggling with writing array generator function

2017-07-13 Thread Vasily Rybakov
On Thursday, July 13, 2017 at 9:30:44 PM UTC+2, Daniel Prager wrote:
> It's straightforward to design a recursive macro with similar intent, but 
> different surface syntax:
> 
> (generate-array (i) 10)
> (generate-array (i) i)
> (generate-array (i j) (+ (* 10 i) j))
> 
> 
> Dan


Thanks for the answer, but I really need to pass generating function to it.

I know that expended recursion shiuld look something like this (for examples of 
functions of 1, 2 and 3 arguments):

((lambda (f) (build-vector 3 (lambda (x) (f x (lambda (i) i))
((lambda (f) (build-vector 3 (lambda (x) (build-vector 3 (lambda (y) (f x 
y)) (lambda (i j) (+ i j)))
((lambda (f) (build-vector 3 (lambda (x) (build-vector 3 (lambda (y) 
(build-vector 3 (lambda (z) (f x y z (lambda (i j k) 10))


But I don't know how to make such a recursion, that will produce this 
expansions.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Struggling with writing array generator function

2017-07-13 Thread Daniel Prager
It's straightforward to design a recursive macro with similar intent, but
different surface syntax:

(define-syntax generate-array
  (syntax-rules ()
[(_ (i) exp) (for/list ([i 3]) exp)]
[(_ (i j...) exp) (for/list ([i 3]) (generate-array (j...) exp))]))

(generate-array (i) 10)
(generate-array (i) i)
(generate-array (i j) (+ (* 10 i) j))

Dan

On Fri, Jul 14, 2017 at 4:52 AM, Vasily Rybakov 
wrote:

> I need to write function generete-array:
>
> (define (generate-array num-dimensions generator)
>...)
>
> such that it generate num-dimensions array (each dimension is of size 3)
> and uses generator function to produce elements of array (generator accepts
> num-dimensions arguments and returns number; each element is equal to the
> result of passing its indices to generator).
>
> So
>
> (generate-array 1 (lambda (i) 10)) => '(10 10 10)
>
> (generate-array 1 (lambda (i) i)) => '(0 1 2)
>
> (generate-array 2 (lambda (i j) (+ (* 10 i) j))) =>
>   => '((0 1 2) (10 11 12) (13 14 15))
>
> and so on...
>
> I think it should use recursion, because I don't know in advance the
> number of dimensions, but I can't figure out how to do it and where I
> should begin with.
>
> Any advice on which path to take for wrighting this function will be
> helpful.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Daniel Prager*
Agile/Lean Coaching, Innovation, and Leadership
Profile: skillfire.co/dan
Startups: youpatch.com , skillfire.co
Twitter: @agilejitsu 
Blog: agile-jitsu.blogspot.com
Linkedin: au.linkedin.com/in/danielaprager

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Struggling with writing array generator function

2017-07-13 Thread Vasily Rybakov
I need to write function generete-array:

(define (generate-array num-dimensions generator)
   ...)

such that it generate num-dimensions array (each dimension is of size 3) and 
uses generator function to produce elements of array (generator accepts 
num-dimensions arguments and returns number; each element is equal to the 
result of passing its indices to generator).

So

(generate-array 1 (lambda (i) 10)) => '(10 10 10)

(generate-array 1 (lambda (i) i)) => '(0 1 2)

(generate-array 2 (lambda (i j) (+ (* 10 i) j))) => 
  => '((0 1 2) (10 11 12) (13 14 15))

and so on...

I think it should use recursion, because I don't know in advance the number of 
dimensions, but I can't figure out how to do it and where I should begin with.

Any advice on which path to take for wrighting this function will be helpful.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Running code at shutdown

2017-07-13 Thread Sam Tobin-Hochstadt
You probably want to look at
http://docs.racket-lang.org/reference/Exiting.html for the
exit-handler or executable-yield-handler, or for a more general
system, plumbers: http://docs.racket-lang.org/reference/plumbers.html

Sam

On Thu, Jul 13, 2017 at 9:50 AM, David Storrs  wrote:
> Short form:  How can I define a block of code such that it will run
> immediately before the program ends?
>
> What I'm trying to achieve: Make my testing module (which is not rackunit)
> check whether or not the expected number of tests ran.  I'd also like to
> know the answer to the 'run at program shutdown' question for general use.
>
>
> Long form:
>
> Perl has two special forms, BEGIN{} and END{}, which run at compile time and
> progam-shutdown time respectively.  Racket's macro system more than fills
> the role of BEGIN, but what would the equivalent be for END?  The relevant
> semantics of END{} are:
>
> * You can put it anywhere you want in a file, although it typically goes
> either at top or bottom.
>
> * You can have as many of them as you want.
>
> * Each compilation unit (module, main script, etc) can have its own.
>
> * END blocks are executed in LIFO order based on when they were seen during
> compilation.
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Running code at shutdown

2017-07-13 Thread David Storrs
Short form:  How can I define a block of code such that it will run
immediately before the program ends?

What I'm trying to achieve: Make my testing module (which is not rackunit)
check whether or not the expected number of tests ran.  I'd also like to
know the answer to the 'run at program shutdown' question for general use.


Long form:

Perl has two special forms, BEGIN{} and END{}, which run at compile time
and progam-shutdown time respectively.  Racket's macro system more than
fills the role of BEGIN, but what would the equivalent be for END?  The
relevant semantics of END{} are:

* You can put it anywhere you want in a file, although it typically goes
either at top or bottom.

* You can have as many of them as you want.

* Each compilation unit (module, main script, etc) can have its own.

* END blocks are executed in LIFO order based on when they were seen during
compilation.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Questions on HtDP 2e, Ex. 356

2017-07-13 Thread Jens Axel Søgaard
> I hope this is heading in the right direction.

Looks fine to me.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Re: Boot To Racket

2017-07-13 Thread Daniel Brunner
Hey,

just to add another idea:

> 
> Don't be scared away from coding your own Scheme from scratch.  A whole
> lot of them got started that way, because it's easy to code your own (If
> you borrow existing approaches for garbage collection and evaluation
> with tail calls), then do something different with it.  In your case,
> you're implementing Scheme on bare metal, and can see how that can
> accommodate Scheme.  

Maybe (really a big maybe because I do not know enough details to tell
if it is possible) it's worth to get Chez Scheme
(http://www.scheme.com/) to "boot" on your device. As far as I know Chez
has several backends for different machine types and operating systems
(https://cisco.github.io/ChezScheme/release_notes/v9.4/release_notes.html).
I tried it on Linux/FreeBSD on x86_64 but there is a LinuxARM version as
well.

There is an ongoing project by Matthew Flatt to rewrite Racket on top of
Chez (https://github.com/racket/racket7). So if you manage to get your
device to "boot to Chez" you may get Racket running in Chez somewhere in
the future.

Best wishes,
Daniel

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.