Re: [racket-users] Re: Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Luke Miles
My 1000 numbers were so small that they weren't reliable.

Change the `num-runs-per-f` and experiment yourself, if you'd like.
The code is attached.

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


map-once.rkt
Description: Binary data


[racket-users] Re: Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Luke Miles
I timed all these with `sqr` on a list of 1 `(random)`.

Luke's (my) first one:
cpu time: 4706 real time: 4699 gc time: 3673

Luke's second one:
cpu time: 5401 real time: 5393 gc time: 4136

Jon's first one:
cpu time: 9734 real time: 9728 gc time: 8007

Jon's second one (tested on a vector of course):
cpu time: 1198 real time: 1195 gc time: 883

Jens' first one:
cpu time: 5622 real time: 5618 gc time: 4800

Jens' second one:
cpu time: 4393 real time: 4391 gc time: 3935


I thought Jens' second one would be faster. The vector's results are promising.

-- 
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] Fast way to map over a list many times, changing ONE element each time?

2015-06-19 Thread Luke Miles
Say I have a list ls and I want to produce a list of
lists where the i'th list has the i'th element of ls tripled,
but all other elements are the same.

e.g. '(3 5 7) = '((9 5 7) (3 15 7) (3 5 21))

What is a fast way to do this?


I could do a loop with appending.
(define (map-once f ls)
  (let M ([sooner null] [later ls])
(if (null? later) null
  (cons (append sooner (list (f (car later))) (cdr later))
(M (append sooner (list (car later))) (cdr later))

- (map-once sqr '(4 5 6))
'((16 5 6) (4 25 6) (4 5 36))

Unfortunately, this is very slow  messy.
I have to do 2 big appends for every element is the return list.


Here is a cleaner-looking, but still slow way:
(define (list-set ls i new-val)
  (let-values ([(sooner later) (split-at ls i)])
(append sooner (list new-val) (cdr later

(define (map-once f ls)
  (for/list ([i (in-naturals)]
 [elm (in-list ls)])
(list-set ls i (f elm


I'm thinking a good implementation might use continuations somehow?

Maybe of vector-set (without the exclamation point) existed, I could use it?

-- 
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: OK to post Redex and HtDP questions here?

2015-06-13 Thread Luke Miles
I don't post here a whole lot, but
From the description of this mailing list:
This is the right place for discussion of nearly all Racket issues.
So I'd say yeah.

-- 
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: Get list of all predefined identifiers for use in vim syntax highlighting

2015-06-02 Thread Luke Miles
To provide some closure:

-The generator provided by Jens completely worked.
 I set up vim to have one color  indentation for keywords,
 and another color  indentation for builtins.

-The ambiguity brought up by Greg has shown not to be a problem.
 I only touched racket/base, as I nearly exclusively use it.
 The reader's distinction between keywords and builtins
 is good enough for me.

-Eventually, it would be nice to have keywords  builtins
 determined by the #lang line and any calls to require.
 However, I'm not sure if this is possible/practical in vim.

-- 
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] strange bug with racket/gui

2015-06-02 Thread Luke Miles
2 questions.


First, when the the attached code is run, `send` throws an error because `dc`
still has the value of void.

Strangely, if I execute the below line in the REPL after the code has run,
the rectangle is successfully displayed.
(send dc draw-rectangle 30 20 10 40)

Why is `dc` still void inside the code but not in the REPL afterwards?


Second, I have some *bad* code in the attached file:
(define canvas (void))
(define dc (void))
(new canvas% [parent frame]
 [paint-callback
   (λ (c d)
 (set! canvas c)
 (set! dc d))])
I couldn't find a direct way to get `dc` and `canvas`, and I didn't want to put
my entire code in the function that paint-callback calls.

Is there a more straightforward way to get these values?

Thanks!
-Luke

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


graphics-2.rkt
Description: Binary data


[racket-users] Get list of all predefined identifiers for use in vim syntax highlighting

2015-06-01 Thread Luke Miles
For those who like to write their racket code in vim, the plugin 
https://github.com/wlangstroth/vim-racket is pretty essential.

Unfortunately, it is outdated and many of the new predefined identifiers (e.g. 
set-add!) are not highlighted.

I added a few of these in my personal settings, but it would be nice to have a 
text file with every special form and every function listed.

Is this list floating around somewhere? If not, is there an easy way to 
generate it?

-- 
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] Get list of all predefined identifiers for use in vim syntax highlighting

2015-06-01 Thread Luke Miles
Thank you very much, Jens. This appears to be all the functions. Do you know of 
anything for special forms? This would include for, for/and, define-values, 
etc...

On Monday, June 1, 2015 at 11:09:31 AM UTC-4, Jens Axel Søgaard wrote:
 Hi Luke,
 
 
 This script generates a large list of keywords. It was used to generate the 
 keywords for the Github highlighter.
 
 
 https://github.com/soegaard/racket-highlight-for-github/blob/master/generate-keywords.rkt
 
 
 
 /Jens Axel
 
 
 
 
 2015-06-01 17:07 GMT+02:00 Luke Miles rashrep...@gmail.com:
 For those who like to write their racket code in vim, the plugin 
 https://github.com/wlangstroth/vim-racket is pretty essential.
 
 
 
 Unfortunately, it is outdated and many of the new predefined identifiers 
 (e.g. set-add!) are not highlighted.
 
 
 
 I added a few of these in my personal settings, but it would be nice to have 
 a text file with every special form and every function listed.
 
 
 
 Is this list floating around somewhere? If not, is there an easy way to 
 generate it?
 
 
 
 --
 
 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...@googlegroups.com.
 
 For more options, visit https://groups.google.com/d/optout.
 
 
 
 
 
 -- 
 
 -- 
 Jens Axel Søgaard

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