Re: [racket-users] Messing with 2htdp/image & universe, got a weird problem

2016-04-10 Thread wesley bitomski
I had just remembered that I forgotten the attachment. After further
messing about, I figured that 100 cars provided the best balance of
ridiculousness and smoothness.

Enjoy!

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


gravity.rkt
Description: Binary data


Re: [racket-users] Messing with 2htdp/image & universe, got a weird problem

2016-04-10 Thread wesley bitomski
Thanks for the advice all!

I did re-read the code and realized that it's really not all that
descriptive. So I tore through it, made better data definitions, commented
the code and profiled it (basically seeing how much time it took to execute
each statement); and discovered that my simulation was poorly written.

First, yeah, "auto". The bodies were meant to look like cars from the
top-down (and since "car" is a useful function in Racket, i decided on
"auto" for the struct instead). This is rectified by composing some
rectangles into a vague car-shape and mashing it into a bitmap% with the
"pict->bitmap" procedure in the "pict" library, but that's a rather useless
optimization but it at least made the "auto"s look like automobiles and
render quick enough to show hundreds rather than a handful.

But the bad part was this little bugger in "step-auto", Daniel was right, I
wasn't using floating-point maths, which turned out to be much faster than
symbolic maths (the rational numbers and such). Putting that ".0" after the
"1" was enough to let me render one car at a reasonable speed. When I
made everything floating-point and used the unsafe ops for such things I
was able to render more. However, I got to 200 when I changed the nature of
the simulation.

I went with a massless simulation: meaning that I considered the change in
direction more important than the actual mass of the car * cursor * G. What
this does is a very unreal animation of cars dancing around the cursor that
moves rather naturally. Attached is the final product of that work.

Thanks guys for the encouragement!

On Sun, Apr 10, 2016 at 1:35 PM 'John Clements' via Racket Users <
racket-users@googlegroups.com> wrote:

>
> > On Apr 10, 2016, at 8:19 AM, Wesley Bitomski 
> wrote:
> >
> > Attached is some source code I've been playing with. I'm trying to come
> up with an approximate simulation of gravity between a very massive (but
> inertia-less) mouse cursor and a handful of semi-massless circles.
> >
> > For a test, I'm only simulating a single body. This world program will
> render the first few frames, and then stop rendering while the updates just
> keep ticking away.  I have no idea why this is happening, and I'm hoping
> that somebody could point out what I'm doing wrong (aside from the
> displayln's, which I know will slow it up some).
>
> I’m not entirely sure what you’re doing wrong, but I’d be willing to bet
> that if you put together a good set of data definitions, purpose
> statements, and test cases, you’d find the problem!
>
> John Clements
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Racket Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/racket-users/GxUi38K07Os/unsubscribe.
> To unsubscribe from this group and all its topics, 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] Messing with 2htdp/image & universe, got a weird problem

2016-04-10 Thread Daniel Prager
Hi Wesley

Some tips:

   1. Your use of random with two args is incorrect: create a (random-range
   a b) function to express your intent.
   2. The slow-down is because you're using unlimited precision arithmetic.
   Try using 1.0 instead of 1 to get floating point.
   3. Instrument your code to give info about state: e.g. in your
   (displayln)s. #:transparent is your friend.
   4. Write some tests to help check your math / express intended behavior.

Dan

-- 
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] Racket change button% coordinates(X and Y axis)

2016-04-10 Thread Jens Axel Søgaard
2016-04-10 17:18 GMT+02:00 Theodor Berza :

> I have a button in a frame and when I change the vert-margin and
> horiz-margin in the code the button doesn't change it's location but rather
> the frame gets smaller or larger.
>
...

> Someone suggested me to create a vertical-panel that has 2 rows of
> horizontal panels, the height of the first horizontal panel determining the
> Y-coordinates and the width of the smaller panel in the second horizontal
> panel determining the X-coordinates of the button.
>

That'd be me. I have added a code example:

http://stackoverflow.com/a/36519013/23567

The purpose of this project is to make a GUI Builder where the user drags
> buttons on a frame and the position of the cursor changes in the code the X
> and Y axis. This would be impossible with building 3 panels for each button
> in a frame that has for example 20 buttons.
>

In that case I see why your are not fond of the solution above.


> Is there a way to add the X and Y coordinates in code without doing hacks?
>

There is a pasteboard% that can be used to place snips at arbitrary
coordinates.
The gui components aren't snips though. That requires that you define your
own snips.
You will need to make a snip type for each gui component.
That is a snip-pane%, snip-panel% etc.

/Jens Axel

-- 
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] Messing with 2htdp/image & universe, got a weird problem

2016-04-10 Thread 'John Clements' via Racket Users

> On Apr 10, 2016, at 8:19 AM, Wesley Bitomski  
> wrote:
> 
> Attached is some source code I've been playing with. I'm trying to come up 
> with an approximate simulation of gravity between a very massive (but 
> inertia-less) mouse cursor and a handful of semi-massless circles.
> 
> For a test, I'm only simulating a single body. This world program will render 
> the first few frames, and then stop rendering while the updates just keep 
> ticking away.  I have no idea why this is happening, and I'm hoping that 
> somebody could point out what I'm doing wrong (aside from the displayln's, 
> which I know will slow it up some).

I’m not entirely sure what you’re doing wrong, but I’d be willing to bet that 
if you put together a good set of data definitions, purpose statements, and 
test cases, you’d find the problem!

John Clements


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


signature.asc
Description: PGP signature


[racket-users] Re: Problem with # and mutable lists

2016-04-10 Thread Joan Martin
Sorry, now with attachment. 

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


wumpus 5.rkt
Description: Binary data


[racket-users] Re: Problem with # and mutable lists

2016-04-10 Thread Joan Martin
Thank you very much,
but although I changed else expresion, Racket sometimes returns same 
warning(but now with #f instead of #).

But when I click Run again (sometimes twice or more) it returns what I want. 
That´s the strangest thing.

Could it be an error in Racket settings?

I attach my code, maybe I miss someting else.(please ignore auxiliary 
procedures, warning appears while running (set-traps) and of course set-symbol! 
)

-- 
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: Problem with # and mutable lists

2016-04-10 Thread Gustavo Massaccesi
The most literal translation is

#lang racket
(define select-room (lambda (number rooms)
  (let loop ((l (mcar rooms)))
(if (not (null? l))
(if (= (mcar(mcar l)) number)
(mcar l)
(loop (mcdr l)))
(void)  ;<-- explicit "else" branch

You can replace (void) with whatever you want to signal that nothing
is found, like 'not-found, but the more idiomatic versions is to
return #f.

(define select-room (lambda (number rooms)
  (let loop ((l (mcar rooms)))
(if (not (null? l))
(if (= (mcar(mcar l)) number)
(mcar l)
(loop (mcdr l)))
#f  ;<-- explicit "else" branch

It's not possible to return "nothing", you must return something, like
(void) or #f or 'not-found. When you are going to ignore the result,
it's better to return (void), but if you want to signal that something
is not found it's better to return #f, or raise an error. (Actually,
you can return "nothing", but let's hide that under the carpet for few
months, because it doesn't play nice with most racket code.)

But now set-symbol has to check that traps is not #f:

(define set-symbol!
  (lambda (symbol number_of_room)
(let ((traps (mcdr(select-room number_of_room environment
  (if traps
 (set-mcdr! traps (mcons symbol (mcdr traps)))
 (void ;<-- explicit "else" branch

Here, it's better to return (void) because you are going to ignore the
result, and set-mcdr! returns also (void). The default printer ignore
voids results and prints "nothing", so (void) will be better here.

(I renamed set-symbol as set-symbol!, because the name of most
functions that mutate their argument have bang. It's not a rule, only
a style recommendation.)

A more idiomatic version use when, unless, and and or, but I'm triying
to make the minimal changes to your code.

Gustavo



On Sun, Apr 10, 2016 at 11:30 AM, Joan Martin  wrote:
> Thank for your answer,
> but how should I change the procedure and ged rid of Racket warning?
> I cant figure it out.
>
> --
> 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] Messing with 2htdp/image & universe, got a weird problem

2016-04-10 Thread Wesley Bitomski
Attached is some source code I've been playing with. I'm trying to come up with 
an approximate simulation of gravity between a very massive (but inertia-less) 
mouse cursor and a handful of semi-massless circles.

For a test, I'm only simulating a single body. This world program will render 
the first few frames, and then stop rendering while the updates just keep 
ticking away.  I have no idea why this is happening, and I'm hoping that 
somebody could point out what I'm doing wrong (aside from the displayln's, 
which I know will slow it up some).

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


gravity.rkt
Description: Binary data


[racket-users] Racket change button% coordinates(X and Y axis)

2016-04-10 Thread Theodor Berza
I have a button in a frame and when I change the vert-margin and horiz-margin 
in the code the button doesn't change it's location but rather the frame gets 
smaller or larger.

This is the code:

(require racket/gui/base)

(define frame (new frame% [label "GUI BUILDER"]
  [width 300]
  [height 400]
  [style '(no-resize-border)]))

(send frame show #t)

(define msg (new message% [parent frame]
  [label "Text"]))

(new button% [parent frame]
 [label "Generate button code"]
 [vert-margin 200]   
 [horiz-margin 480]
 [callback (lambda (button event)
 (send msg set-label "Changed"))])



Someone suggested me to create a vertical-panel that has 2 rows of horizontal 
panels, the height of the first horizontal panel determining the Y-coordinates 
and the width of the smaller panel in the second horizontal panel determining 
the X-coordinates of the button.

The purpose of this project is to make a GUI Builder where the user drags 
buttons on a frame and the position of the cursor changes in the code the X and 
Y axis. This would be impossible with building 3 panels for each button in a 
frame that has for example 20 buttons.

Is there a way to add the X and Y coordinates in code without doing hacks?

-- 
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] why `read` vs. `read-syntax`?

2016-04-10 Thread Matthew Flatt
At Sun, 10 Apr 2016 07:49:19 -0700, Matthew Butterick wrote:
> 1) When, if ever, is the `read` of a #lang invoked by Racket?

That happens if you use `read` on a file that starts `#lang`.

In that case, the `read-accept-reader` parameter must be set, as in

 (parameterize ([read-accept-reader #t])
   (call-with-input-file* "m.rkt" read)) ; where "m.rkt" starts `#lang`


> 2) What's an example of a situation where `read` would want to be more than 
> `(syntax->datum (read-syntax ...))`?

I don't have a good example. Although the base `read` function supports
graph constructions that are not supported by `read-syntax` --- because
graph support seems worthwhile for data and not for code --- I don't
think that would explain why a `#lang` reader would need to support it.


> 3) Or, is this one of those distinctions that lingers for backward 
> compatability (with what, I would not know)

Yes, it's a kind of backward compatibility to preserve a connection
between `read` and programs.

-- 
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] why `read` vs. `read-syntax`?

2016-04-10 Thread Matthew Butterick
The docs describe the relationship this way: "In `read-syntax` mode, the result 
is always a syntax object ... wrapped around the sort of datum that `read` mode 
would produce." [1]

Along those lines, I've yet to see a #lang where the `read` amounts to more 
than wrapping `read-syntax` with `syntax->datum`. For instance [2].

Moreover, in the implementation of a #lang, I've found that the `read` 
definition can be omitted without any (apparent) ill effects.

Thus the questions:

1) When, if ever, is the `read` of a #lang invoked by Racket?

2) What's an example of a situation where `read` would want to be more than 
`(syntax->datum (read-syntax ...))`?

3) Or, is this one of those distinctions that lingers for backward 
compatability (with what, I would not know)



[1] http://docs.racket-lang.org/reference/reader.html

[2] http://docs.racket-lang.org/guide/hash-lang_reader.html

-- 
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: Problem with # and mutable lists

2016-04-10 Thread Joan Martin
Thank for your answer,
but how should I change the procedure and ged rid of Racket warning?
I cant figure it out.

-- 
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: Problem with # and mutable lists

2016-04-10 Thread Joan Martin
Dne neděle 10. dubna 2016 13:29:43 UTC+2 Joan Martin napsal(a):
> Hello, 
> I try to write a programme (a game), where I use lots of mutable lists (named 
> environment).Something like this:
> (define environment 
>  (mcons (mcons  (mcons 1 (mcons (mcons 2(mcons 5(mcons 8 '('() ))
> (mcons  (mcons 2 (mcons (mcons 1(mcons 3(mcons 10 '( '() ))
>   ..
>   '() ))
> It should represent a 2D dekadedron.
> And for easy manipulation I wrote a procedure: select-room and set-symbol.
> 
> (define select-room (lambda (number rooms)
>   (let loop ((l (mcar rooms)))
> (if (not (null? l))
> (if (= (mcar(mcar l)) number)
> (mcar l)
> (loop (mcdr l)) )
> (define set-symbol
>   (lambda (symbol number_of_room)
> (let ((traps (mcdr(select-room number_of_room environment))  ))
>   (set-mcdr! traps (mcons symbol (mcdr traps))  
> 
> I use it without problems : (select-room 2 environment) in this case.
> But when I use it in another procedure (for example: set-symbol), sometimes 
> Racket returns this:
> 
>   mcdr: contract violation;;(mcdr in let in set-symbol)
>   expected: mpair?
>   given: #;;(returned by select-room ?)
> 
> In Racket documentation I found : " # is returned by most forms and 
> procedures that have a side-effect and no useful result."
> 
> But for me it REALLY has useful result. It´s really strange it appears only 
> sometimes. And select-room returns a mutable list, so I´m really confused.
> 
> I would be glad for any help.
> 
> Thanks 
> Joan

I learn Scheme and compiling in Racket with language Pretty Big isn´t problem.

Select-room should be iterative procedure - it goes through list. 
(null? l) tells it is at the end of the list and it returns nothing, because I 
don´t have second else expresion in IF. 


-- 
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] Problem with # and mutable lists

2016-04-10 Thread Benjamin Greenman
On Sun, Apr 10, 2016 at 7:29 AM, Joan Martin  wrote:

> I use it without problems : (select-room 2 environment) in this case.
> But when I use it in another procedure (for example: set-symbol),
> sometimes Racket returns this:
>
>   mcdr: contract violation;;(mcdr in let in set-symbol)
>   expected: mpair?
>   given: #;;(returned by select-room ?)
>

This problem may be because your first if-statement in select-room is
missing an else branch.



>
> In Racket documentation I found : " # is returned by most forms and
> procedures that have a side-effect and no useful result."
>

These functions return # because the useful result is usually the
argument you passed the procedure in the first place. The example below
uses set-mcar! to update a list -- the useful result is the original list,
not the result of set-mcar!

#lang racket/base

(define lst (mcons 1 (mcons 2 '(

(displayln lst)
;; (1 2)

(set-mcar! lst 3)

(displayln lst)
;; (3 2)

-- 
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] Problem with # and mutable lists

2016-04-10 Thread Pierpaolo Bernardi
On Sun, Apr 10, 2016 at 1:29 PM, Joan Martin  wrote:
> Hello,
> I try to write a programme (a game), where I use lots of mutable lists (named 
> environment).Something like this:
> (define environment
>  (mcons (mcons  (mcons 1 (mcons (mcons 2(mcons 5(mcons 8 '('() ))
> (mcons  (mcons 2 (mcons (mcons 1(mcons 3(mcons 10 '( '() ))
>   ..
>   '() ))
> It should represent a 2D dekadedron.
> And for easy manipulation I wrote a procedure: select-room and set-symbol.
>
> (define select-room (lambda (number rooms)
>   (let loop ((l (mcar rooms)))
> (if (not (null? l))
> (if (= (mcar(mcar l)) number)
> (mcar l)
> (loop (mcdr l)) )

In Racket this doesn't even compile. So I assume you must be using
some other programming language.

Anyway, what does this function return when (null? l) ?

If you had used Racket, it would have shown you immediately where's the problem.

-- 
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] Problem with # and mutable lists

2016-04-10 Thread Joan Martin
Hello, 
I try to write a programme (a game), where I use lots of mutable lists (named 
environment).Something like this:
(define environment 
 (mcons (mcons  (mcons 1 (mcons (mcons 2(mcons 5(mcons 8 '('() ))
(mcons  (mcons 2 (mcons (mcons 1(mcons 3(mcons 10 '( '() ))
  ..
  '() ))
It should represent a 2D dekadedron.
And for easy manipulation I wrote a procedure: select-room and set-symbol.

(define select-room (lambda (number rooms)
  (let loop ((l (mcar rooms)))
(if (not (null? l))
(if (= (mcar(mcar l)) number)
(mcar l)
(loop (mcdr l)) )
(define set-symbol
  (lambda (symbol number_of_room)
(let ((traps (mcdr(select-room number_of_room environment))  ))
  (set-mcdr! traps (mcons symbol (mcdr traps))  

I use it without problems : (select-room 2 environment) in this case.
But when I use it in another procedure (for example: set-symbol), sometimes 
Racket returns this:

  mcdr: contract violation;;(mcdr in let in set-symbol)
  expected: mpair?
  given: #;;(returned by select-room ?)

In Racket documentation I found : " # is returned by most forms and 
procedures that have a side-effect and no useful result."

But for me it REALLY has useful result. It´s really strange it appears only 
sometimes. And select-room returns a mutable list, so I´m really confused.

I would be glad for any help.

Thanks 
Joan

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