[racket-users] Time of hash-ref when the key is (not) found

2016-08-11 Thread Gustavo Massaccesi
I have these strange times in a microbenchmark that compares the time
to run hash-ref when the key is in the hash and when it is not there:

;---
#lang racket/base
(define hash0 #hash((0 . #t)))
(define hash1 #hash((1 . #t)))

(for ([rep (in-range 5)])
  (display "h0: ")
  (time
   (for ([i (in-range 1000)])
 (hash-ref hash0 0 #f))
   (void))

  (display "h1: ")
  (time
   (for ([i (in-range 1000)])
 (hash-ref hash1 0 #f))
   (void))
)
;---

Typical run times, sorted by cpu time

found:
h0: cpu time: 3775 real time: 3798 gc time: 0
h0: cpu time: 3900 real time: 3936 gc time: 0
h0: cpu time: 3916 real time: 4009 gc time: 0
h0: cpu time: 3947 real time: 4006 gc time: 0
h0: cpu time: 3978 real time: 4096 gc time: 0

not found:
h1: cpu time: 2278 real time: 2270 gc time: 0
h1: cpu time: 2293 real time: 2360 gc time: 0
h1: cpu time: 2434 real time: 2462 gc time: 0
h1: cpu time: 2449 real time: 2506 gc time: 0
h1: cpu time: 2589 real time: 2682 gc time: 0

The "not found" version is 40% faster. I tried a few variation with
small hashes and I got similar results.

I expected that both have roughly the same time (or that the "found"
version were slightly faster).

Gustavo

-- 
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] Mixin questions

2016-08-11 Thread Robby Findler
Although, with these two particular interfaces, there is no single
class that implements both. You would instead have two separate mixins
that would communicate by calling each others methods.

Robby


On Thu, Aug 11, 2016 at 12:09 PM, Daniel Feltey  wrote:
> If you want to inherit from both the frame and the tab in the mixin you
> would write something like:
>
> (mixin
>   (drracket:unit:frame<%>
>drracket:unit:tab<%>)
>   ()
>   ;; body
>   ...)
>
> In this case the mixin will only work on classes that implement both the tab
> and the frame interfaces, and you can now inherit methods from each
> interface.
>
> In general the 'mixin' form takes two lists of interfaces: the first are
> those that arguments to the mixin must implement, the second are those that
> the result of applying the mixin must implement.
>
> Hope this helps,
> Dan
>
>
>
> On Thursday, August 11, 2016, Normal Loone  wrote:
>>
>> Does that mean, I can not use inherit on tab% here? Because that's my
>> problem I need functions from both classes but I can only inherit from one,
>> the other always results in runtime errors.
>>
>> Is there a way to use more from-interfaces than just one? The they it's
>> worded suggested that you can use more than one parent interface.
>>
>> Like mainly, I want to use the function (current-tab) in frame% to figure
>> out the opened tab and acquire the file name it is referencing. And then in
>> tab% i want to override the function (break-callback) to print the filename
>> out when ever a program is cancelled (for some reason break-call is a
>> function in tab whereas execute-call is a function in frame...)
>
> --
> 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] Mixin questions

2016-08-11 Thread Daniel Feltey
If you want to inherit from both the frame and the tab in the mixin you
would write something like:

(mixin
  (drracket:unit:frame<%>
   drracket:unit:tab<%>)
  ()
  ;; body
  ...)

In this case the mixin will only work on classes that implement both the
tab and the frame interfaces, and you can now inherit methods from each
interface.

In general the 'mixin' form takes two lists of interfaces: the first are
those that arguments to the mixin must implement, the second are those that
the result of applying the mixin must implement.

Hope this helps,
Dan


On Thursday, August 11, 2016, Normal Loone > wrote:

> Does that mean, I can not use inherit on tab% here? Because that's my
> problem I need functions from both classes but I can only inherit from one,
> the other always results in runtime errors.
>
> Is there a way to use more from-interfaces than just one? The they it's
> worded suggested that you can use more than one parent interface.
>
> Like mainly, I want to use the function (current-tab) in frame% to figure
> out the opened tab and acquire the file name it is referencing. And then in
> tab% i want to override the function (break-callback) to print the filename
> out when ever a program is cancelled (for some reason break-call is a
> function in tab whereas execute-call is a function in frame...)

-- 
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: Problems when compiling Racket from source on ARM

2016-08-11 Thread Rene Schöne
> Follow these steps:
> - Remove the old git repo.
> - Delete every file installed by racket within ~/.local.
> - rm -rf "~/.racket/6.*"
> - mkdir -p "~/.local/bin"
> - export PATH="$PATH:~/.local/bin"
> - git clone --depth 1 --single-branch 
> https://github.com/racket/racket.git racket-git
> - cd racket-git
> - copy the patch
> - patch -p1 -i racket-arm-unwind.patch
> - cd racket/src
> - ./configure --enable-shared --prefix="~/.local" --enable-libffi
> - make
> - make install
> - raco pkg install --auto main-distribution (or any other raco package)

Great, it worked. Many thanks again.

-- 
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] Iterating through a list more than one at a time

2016-08-11 Thread Greg Hendershott
Yes. Also each slice is a sequence. So you could do all the usual
things to it. Including but not limited to using another `for` form,
applying it to afunction, or destructuring it using `match` and
friends.

In these examples I included an extra, "leftover" element to make sure
it was handled:

#lang racket

(define data '(("foo") ("bar")  ("baz")  ("jaz") ("quux") ("glug")
("EXTRA")))

(for/list ([slice (in-slice 2 data)])
  (for/list ([x slice])
x))

(for/list ([slice (in-slice 2 data)])
  (apply list slice))

(for/list ([slice (in-slice 2 data)])
  (match slice
[(list x y) (list x y)]
[(list x)   (list x)]))

All eval to:

'((("foo") ("bar")) (("baz") ("jaz")) (("quux") ("glug")) (("EXTRA")))

-- 
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: Mixin questions

2016-08-11 Thread Normal Loone
Does that mean, I can not use inherit on tab% here? Because that's my problem I 
need functions from both classes but I can only inherit from one, the other 
always results in runtime errors. 

Is there a way to use more from-interfaces than just one? The they it's worded 
suggested that you can use more than one parent interface.

Like mainly, I want to use the function (current-tab) in frame% to figure out 
the opened tab and acquire the file name it is referencing. And then in tab% i 
want to override the function (break-callback) to print the filename out when 
ever a program is cancelled (for some reason break-call is a function in tab 
whereas execute-call is a function in frame...) 

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