Re: [racket-users] slideshow -> google slides?

2020-08-06 Thread Gustavo Massaccesi
From
https://www.joelonsoftware.com/2008/02/19/why-are-the-microsoft-office-file-formats-so-complicated-and-some-workarounds/
about the old formats:

> *These are binary formats, so loading a record is usually a matter of
just copying (blitting) a range of bytes from disk to memory, where you end
up with a C data structure you can use. There’s no lexing or parsing
involved in loading a file. Lexing and parsing are orders of magnitude
slower than blitting.*

Probably an old .ppt is difficult to write, but a .pptx is probably just a
bunch of .xml compressed with .tar.gzip or zip, and a fancy extension. (I
didn't try myself, but I remember to have read something like that.)

I used a few times the trick to just write a html file with a few of the
custom properties of Office and send it as a .xls or .doc . It works,
better than I expected.

Gustavo




On Thu, Aug 6, 2020 at 7:58 PM 'John Clements' via Racket Users <
racket-users@googlegroups.com> wrote:

> Has anyone here developed a reasonable workflow for exporting slideshow
> presentations to google slides? It appears that google slides cannot import
> PDFs or SVGs. It looks like it has support for importing PPT files,
> unsurprisingly, but AFAIK slideshow won’t export ppt files. I have no idea
> how nasty the PPT format is.
>
> Right now I’m looking into PDFelement, a mac program, but I’d love to hear
> about other options.
>
> Thanks!
>
> John
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/7a2b8538-91f9-45e2-9006-5e8047d39973%40mtasv.net
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9MiPXjH2Gf6R0Q5tL8aYBsJ%2BTe7eKf5w217JXwmMpZYyQ%40mail.gmail.com.


Re: [racket-users] Re: Racket CS release plan

2020-08-01 Thread Gustavo Massaccesi
The human friendly version of the bytecode is explained in
https://docs.racket-lang.org/raco/decompile.html?q=decompile#%28mod-path._compiler%2Fdecompile%29
. The human friendly version looks similar to the expanded version of a
program that you get with the Macro Debugger (when the macros are not
hidden), but without the syntax scopes and with a few additional quirks.
(Note that the bytecode production has a few additional steps after
expansion, for example inlining, constant propagation and folding.)

The disk version is more compact, but IIRC it is not documented.

Gustavo


On Sat, Aug 1, 2020 at 3:50 PM George Neuner  wrote:

> Hi Matthew,
>
> On 8/1/2020 2:01 PM, Matthew Flatt wrote:
> > At Sat, 01 Aug 2020 03:56:36 -0400, George Neuner wrote:
> > > On Fri, 31 Jul 2020 20:20:05 -0700 (PDT),
> > > "wanp...@gmail.com"
> > >  wrote:
> > >
> > > >I noticed that the size of the CS version is 244% compare to BS
> > > >version. Wondering why it became so large. Does that mean Chez Scheme
> > > >runtime/vm 100 MB larger than the original one?
> > > >
> > > >Racket Mac OS X
> > > >  64-bit Intel 116.7 MB SHA1:
> 521b5a264afcfb3f390afacc682987268f650a25
> > > >
> > > >Racket CS Mac OS X
> > > >  64-bit Intel 285.8 MB SHA1:
> 060f311fc6621c5797a62f98b743499fa4277793
> > > >
> > > >https://pre-release.racket-lang.org/
> > >
> > >
> > > The CS version compiles to native code rather than portable bytecode,
> > > so pretty much everything in the distribution is somewhat larger.  It
> > > adds up quickly.
> >
> > That's still the best explanation I have, but I also think there must
> > be something more to it.
> >
> > For example, the Chez Scheme boot files in uncompressed form add up to
> > about 8 times the size of compiled Racket BC executable, but Chez
> > Scheme doesn't have 8 times the functionality of the Racket BC
> > executable (so it should have 8 times as much machine code). The
> > machine code generated by Chez Scheme for its boot files is less
> > compact than machine code generated by GCC or LLVM for Racket BC's
> > implementation --- but, again, I don't think it's a factor of 8. So,
> > I'm optimistic that I've so far overlooked something that can make a
> > big difference.
> >
> > I've concentrated more on understanding the difference in the run-time
> > memory footprints, and the difference there is not nearly so large.
> > Racket CS now sometimes has a smaller memory footprint than Racket BC
> > (e.g., peak memory use for a distribution build).
> >
> > Matthew
>
> I don't know details of the Racket bytecode, but I'm assuming that it is
> a mix of simpler operations that map directly to one or a few native
> instructions, and more complex operations that compile to (the
> equivalent of) a small function.  Probably some of these functions can
> be inlined, but I expect there still would be some that can't.
>
> To understand the difference in code size, you would need to look at the
> lengths of bytecode instructions vs their native code equivalents, and
> account for instances of those operations that can be inlined and for
> calls to the functions for operations that can't.
>
>
> As I said above, I don't know details of Racket bytecode, but a lot of
> virtual machines use 8 or 16 bit opcodes and (allowing for immediate
> operands) have average instruction lengths of 3..4 bytes. Contrast this
> with, e.g., x86-64 code in which the average instruction is 5..6 bytes
> [larger if many instructions require length prefixes (e.g., 32-bit ops
> in 64-bit code)].  The difference can add up very quickly.
>
> George
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/c3324f5f-19cd-1e0f-3d83-08787474bede%40comcast.net
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9My_paizR3P_XWLkRshPmj4hy0m%2B%3DZ0mrjt-p9uXTdtYQ%40mail.gmail.com.


Re: [racket-users] Possible bug in vector-cas!

2020-05-30 Thread Gustavo Massaccesi
Does your computer have exactly 8 cores (or subcores or whatever is the
official name of that hardware feaure)?

What happens if you use 7 futures instead of 8?

What happens if you use 9 (or 100) futures instead of 8?

Gustavo

PS: I don't know the low level details of the implementation of the
futures, but my guess is that in your example there is a main thread(?) and
8 futures, so you are running 9 things in 8 cores, and there is a race
condition and if you are unlucky it can cause a the program to block.





On Sat, May 30, 2020 at 1:12 PM Dominik Pantůček <
dominik.pantu...@trustica.cz> wrote:

> Hello Racketeers,
>
> it didn't take long before I hit another strange behavior when
> extensively using futures. The setup is relatively simple: I am
> processing a large fxvector/flvector and I am processing it on a
> line-by-line basis (the vectors themselves are width*height in nature).
> To avoid races I setup a (make-vector height #f) to serve as a vector of
> locks. Locking is simple:
>
> (let lloop ()
>   (when (not (vector-cas! locks y #f #t))
> (lloop)))
>
> .. do something ...
>
> (vector-set! locks y #f)
>
> Of course, the code in question is in 8 futures on my CPU and they are
> scheduled in parallel pretty consistently.
>
> Most of the time it works fine, but sometimes it just hangs with
> multiple CPU cores being utilized at 100% (I assume they are in the
> busy-wait "lloop").
>
> The problem is I cannot isolate a minimal working example from that. The
> code in question is about 3000 LoC and the issue expresses itself only
> in about 1 in 30 times just after the program has started. The GUI
> thread is running and there are lots of flonum operations and lots of
> thrown away flonum results (meaning GC gets triggered quite often).
>
> Also I cannot trigger the same issue with unsafe-vector*-cas! - I'll
> look into the differences in the source.
>
> I see this with latest Racket 3m.
>
> Any suggestions how to approach finding the source of the problem are -
> as always - very welcome.
>
>
> Cheers,
> Dominik
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/0e6de88c-1d39-38fa-ea69-2043c4f4071b%40trustica.cz
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9Mw3Txxe6h%2BrCBsLExoRTEg%2Bs1kPk07WOq_r43ncFE6%3Dg%40mail.gmail.com.


Re: [racket-users] Questions about working on DrRacket and gui

2020-05-06 Thread Gustavo Massaccesi
I´m not sure if you are writing your own list of known symbols or if you
are reusing a list of known symbols that DrRacket is using for something
else.

Gustavo

On Wed, May 6, 2020 at 9:25 AM Dexter Lagan  wrote:

>   If that can help, I narrowed down the delay to new files only, after
> typing a known symbol only. When opening an existing file, no matter what I
> type in, no delay. If I start a fresh DrRacket, I can type anything in the
> definitions window with no delay. The delay only happens if I type a known
> function name, for example ‘define’. If I type ‘defind’, there’s no delay.
> The delay also appears in Scheme mode, and with background expansion
> disabled. No delay in Text mode, which makes sense.
>
>
>
>   I’m currently looking at the definitions-text from unit.rkt, to see
> where’s the hook that detects symbols. I have the day off, and I’m enjoying
> this very much.
>
>
>
> Cheers,
>
>
>
> Dex
>
>
>
> *From:* Robby Findler 
> *Sent:* Tuesday, May 5, 2020 6:18 PM
> *To:* Gustavo Massaccesi 
> *Cc:* Dexter Lagan ; Matthew Flatt <
> mfl...@cs.utah.edu>; Racket Users 
> *Subject:* Re: [racket-users] Questions about working on DrRacket and gui
>
>
>
>
>
>
>
> On Tue, May 5, 2020 at 10:36 AM Gustavo Massaccesi 
> wrote:
>
> I try to encourage people to participate, but be careful because this task
> is probably too big for a first contribution. GUI is difficult, DrRacket
> has a lot of moving parts, and opening DrRacket inside DrRacket is possible
> but weird.
>
>
>
>
>
> +1
>
>
>
> I think the guess of Matthew is correct, it´s a problem with the blue
> arrow with the docs. There is no pause while you type numbers but when you
> type a letter or +-*/... there is a pause of 1 or 2 seconds.
>
>
>
> I didn't see the code but my guess is that the docs are loaded lazily in a
> thread and when DrRackets see something like an identifier it waits until
> the thread is ready. It would be nice if the blue arrow is disabled until
> the docs are completely loaded lazily. I think Robby can tell if I'm
> correct and how hard is to fix this.
>
>
>
>
>
> Definitely sounds like an extremely actionable hypothesis to investigate
> and, if it turns out to be correct, I guess it should be a simple matter of
> programming to do what you're suggesting.
>
>
>
> Robby
>
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9PF-YBGF3zfOPiVawzN7HLRYihO3t8VL50vdog141ZfAQ%40mail.gmail.com.


Re: [racket-users] Questions about working on DrRacket and gui

2020-05-05 Thread Gustavo Massaccesi
I try to encourage people to participate, but be careful because this task
is probably too big for a first contribution. GUI is difficult, DrRacket
has a lot of moving parts, and opening DrRacket inside DrRacket is possible
but weird.

I think the guess of Matthew is correct, it´s a problem with the blue arrow
with the docs. There is no pause while you type numbers but when you type a
letter or +-*/... there is a pause of 1 or 2 seconds.

I didn't see the code but my guess is that the docs are loaded lazily in a
thread and when DrRackets see something like an identifier it waits until
the thread is ready. It would be nice if the blue arrow is disabled until
the docs are completely loaded lazily. I think Robby can tell if I'm
correct and how hard is to fix this.

Gustavo


On Fri, May 1, 2020 at 5:10 PM Matthew Flatt  wrote:

> At Fri, 1 May 2020 16:59:22 +0200, Dexter Lagan wrote:
> >   I'd like to download DrRacket's source and profile it, say to improve
> > scrolling performance or track this post-startup lock-up :
>
> Does the start-time delay happen if you just type a number and hit
> return, as opposed to typing an identifier? If not, the delay is
> probably in loading documentation as triggered the first time DrRacket
> sees an identifier to look up.
>
> > - Do I need to download the entire Racket tree in order to build
> DrRacket?
>
> You can start with minimal Racket and install DrRacket, as Sorawee
> said, but be aware that installing DrRacket will pull in most of a
> normal Racket distribution, anyway.
>
> > - Is the DrRacket's built-in profiler solid enough to handle profiling
> > DrRacket itself?
>
> Running DrRacket inside of DrRacket is not likely to give you useful
> information for something like scrolling, because DrRacket shares the
> GUI instance with programs that it runs.
>
> Running DrRacket with `raco profile` is more promising. It doesn't work
> as easily as it should, partly because DrRacket wants to be in control,
> and partly because `raco profile` doesn't deal with the custodian being
> changed or waiting for a GUI program to exit. But I was able to run it
> by supplying this wrapper program to `raco profile`:
>
>  #lang racket/base
>  (require racket/gui/base)
>
>  (define c (make-custodian))
>  (define done (make-semaphore))
>
>  (parameterize ([current-custodian c])
>(parameterize ([exit-handler
>(lambda (v)
>  (semaphore-post done)
>  (custodian-shutdown-all c))])
>  (define e (make-eventspace))
>  (parameterize ([current-eventspace e])
>(queue-callback (lambda ()
>  ;; here's where we finally start DrRacket
>  (dynamic-require 'drracket #f))
>
>  (sync done)
>
>
> > - Modules in DrRacket's repo don't always have very telling names. Is
> there
> > a document describing what each module does?
>
> There's nothing like that, as far as I know.
>
> > - If I make a change to a source file on my system, yet somebody else
> > modifies the same file on their local system. Say both of our changes are
> > accepted by whoever manages commits, how will accepted changes to the
> code
> > merged?
>
> We use Git, which provides good tools for merging changes.
>
> >   Also, say I have a suggestion regarding how DrRacket handles compiling
> > standalone executables, do I still need to create an issue on its Github?
> > For work I compile to standalone all day long, and I really wish DrRacket
> > didn't zip the resulting file (it would be better to have the .exe file
> in
> > an automatically created /bin or /output folder). Zipping the file takes
> > time, and I have to unzip it each time, which takes more time, this piles
> > up when done every few minutes, all day long. I could use raco exe, but
> I'd
> > rather stay in DrRacket, and I'm sure many people would rather have the
> > default behavior to not zip, just to have single responsibility on the
> > compile function.
>
> That sounds plausible for many cases. (In some cases, depending on the
> platform and the program, there are unavoidably multiple output files.)
>
> >  One last questions: I have encountered differences in the behavior of
> > macros between the REPL, a launcher and a standalone executable for
> > distribution. Is there a document outlining the deeper differences
> between
> > these three ways of executing Racket code?
>
> I think you're probably encountering differences in how the namespace
> and module registry is set up for `eval` and/or `dynamic-require`.
>
> Maybe you've already seen these, but if not, they're good starting
> points:
>
>   https://docs.racket-lang.org/guide/reflection.html
>
>   https://docs.racket-lang.org/raco/exe.html
>   (especially paragraphs 3 through 6 about modules)
>
>
> --
> 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] Code Jam

2020-03-30 Thread Gustavo Massaccesi
Code Jam is in a few days, but Racket is not available :(.

Anyone know how difficult is to add a new language to the list? (Probably
for 2021.)

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9Pg0A1AP5-tc0pWHjHhqkwO-k2U%2BfGMtS57-NKx0P7S7Q%40mail.gmail.com.


Re: [racket-users] How do I just run the type checker?

2020-02-26 Thread Gustavo Massaccesi
Another solution: If you are inside DrRacket, you can use the button "Check
Syntax".

Gustavo

On Fri, Feb 21, 2020 at 2:13 PM Marc Kaufmann 
wrote:

> Hi,
>
> the way I currently check my web server is by simply running `racket
> server.rkt` on the command line. However, this also launches the server,
> which I usually do want to, but not always. So is there a way to run just
> the type checker -- plus all the compile-time stuff that needs to happen
> for this -- without anything else? The best I have managed is to put the
> most time-consuming commands that I run into `(module+ main ...)`, but that
> still does more than than just run the type checker.
>
> Secondly, is it possible to somehow speed up subsequent type checks by
> caching something before?
>
> Cheers,
> Marc
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/b8922e9a-524f-4c2d-b716-c857914e7107%40googlegroups.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9OqF9x8E8Uqn1PvSuy2UhBV4z8E%2BmbJ60agt5kAOMvzJQ%40mail.gmail.com.


Re: [racket-users] how to adapt BC code for Racket CS?

2020-02-23 Thread Gustavo Massaccesi
Some minor remarks:

On Sun, Feb 23, 2020 at 9:58 AM Matthew Flatt  wrote:

> [Replying to three messages]
>
> At Sat, 22 Feb 2020 08:05:28 -0800, Matthew Butterick wrote:
> > 1) As a package maintainer with zero exposure to Chez Scheme, how do I
> start
> > to optimize for Racket CS? Are there certain patterns and idioms from BC
> that
> > should be systematically eradicated?
>
> No. For most Racket users, you should *not* try to optimize for Racket
> CS, and Racket CS should just do the right thing.
>
>
I agree, 99.9% of the time just write nice idiomatic code and hope the
optimizer will do the right thing.




> > But my understanding is that Chez’s optimizer is much more
> > sophisticated than Racket BC’s.
>
> I wouldn't characterize it that way. If anything, Racket BC is more
> sophisticated and aggressive than Chez Scheme on high-level
> optimizations, especially around type reconstruction and cross-module
> optimizations. (For Racket CS, Gustavo added a type-reconstruction pass
> to Chez Scheme, and schemify handles cross-module optimization.)
>
> Chez Scheme's advantages are more on the back end: register allocation,
> calling conventions, and continuation management.
>

About the type recovery part: RacketCS can get the type information from
more primitives than RacketBC.
It was very handy that Chez Scheme had a list with the signatures of all
the primitives.
On the other hand, RacketCS still doesn't have some tricks like
(bitwise-and  )  ==>





> > At the very least, I’d expect it to be able to identify that `v`
> > is never used here and simplify it to this:
> >
> > (let loop ([i 0])
> >   (define j (add1 i))
> >   (if (< j N)
> >   (loop j)
> >   i))
>
> None of Racket BC, Racket CS, or Chez Scheme by itself will optimize
> away the unused loop argument. That kind of interprocedural dead-code
> elimination is out of reach for the current compilers, except to the
> degree that inlining turns them into intraprocedural questions.
>

I'm more optimistic, and I think that detecting that an argument is unused
and deleting it is not so difficult, at east in thigh loops. It is similar
to the lifting of closures that is already done.
If this pattern is common enough, I think this can be added in a week as an
independent pass (that's like a month of wall clock time :) ).
(This is one of the advantages of RacketCS. It's much easier to write
complex transformations. Writing this in the traditional Racket is
theoretical possible, but it would be more difficult.)
(It would be better to add it as part of cp0 or as part of cptypes, or as
part of a more complete pass about loops. So don't expect to see this in a
month.)



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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9OWgHMDs%3DV0LXv%2BCp2jnH241VuFjPH%2BfF7TpupXu2m4%2BQ%40mail.gmail.com.


Re: [racket-users] Strange error in racket 7.5

2020-01-25 Thread Gustavo Massaccesi
It is an internal function of the math package
https://github.com/racket/math/blob/cdc64390f1e7b75de9575a91f0ec3a31f7878530/math-lib/math/private/bigfloat/mpfr.rkt#L587that
is used to show bigfloats.

I can't reproduce the error in Windows, but it doesn't look like an error
that is platform dependent. Are you running this in DrRacket or in the
command line? Any unusual configuration?

Is the code available? Can you send a minimized example? Try to remove as
much as you can (including all the secret sauce if it is an internal
project). Any example that shows the error would be very helpful, but if
you can reduce the example to a hundred of lines it would be nice. And
shorter examples are better, even if the code makes no sense.

Gustavo


On Sat, Jan 25, 2020 at 9:34 AM greadey  wrote:

> Hi there,
>
> I am running racket 7.5 on GhostBSD 20.01, I am getting a strange error
> running a file which previously ran OK on FreeBSD 12.
>
> ../../../../local/share/racket/collects/racket/pretty.rkt:478:8:
> bigfloat-custom-write: undefined;
>  cannot reference an identifier before its definition.
>
> What I cannot understand is that big-float-custom-write is not listed in
> the documentation.  Does anyone have any ideas what might be causing this?
>
> Cheers,
>
> greadey
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/37641b85-9d6b-4d29-9f35-bb35e99c5c99%40googlegroups.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9M1qKcFcRh_eegRb4hyikm45Kzsm2MRRMgJCnK5xePbOA%40mail.gmail.com.


Re: [racket-users] scribble defproc looses parenthesis

2019-09-21 Thread Gustavo Massaccesi
It looks like an error to me. I made a bug report in
https://github.com/racket/scribble/issues/211 because it is easy to track
the problem there.

You can subscribe to the issue to get any update, or I can try to remember
to post any (big) update here.

Gustavo

On Sat, Sep 14, 2019 at 2:05 PM Jos Koot  wrote:

> Hi
>
>
>
> File bug.rkt
>
>
>
> #lang racket
>
> (define (make-proc) (λ (x (y #f)) (void)))
>
> (provide make-proc)
>
>
>
> File bug.scrbl
>
>
>
> #lang scribble/manual
>
>
>
> @(require
>
>   scribble/core
>
>   scribble/eval
>
>   racket
>
>   "bug.rkt"
>
>   (for-label racket "bug.rkt")
>
>   (for-syntax racket))
>
> @(defmodule "bug.rkt" #:packages ())
>
> @defproc[((make-proc ) (x any/c) (y any/c #f)) any/c]{blah blah}
>
>
>
> Renders:
>
>
>
>  (require "bug.rkt")
>
>
>
> ((make-proc *x* [*y*]) → any/c ççç  here a parenthesis is missing.
>
>   *x* : any/c
>
>   *y* : any/c = #f
>
> blah blah
>
>
>
> I suppose this is a bug.
>
> Best wishes, Jos
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CAL6KNi3KZtRRBjp9%3D8NpvOqtQz-FBU4cw-_f9OkhsQW4K0owDQ%40mail.gmail.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9Mc73nR7Wyjfm8iuB9gvit-k3bve5KG0Sx6%2B9uv3tNiRg%40mail.gmail.com.


Re: [racket-users] Re: The case, and a proposal, for elegant syntax in #lang racket2

2019-08-22 Thread Gustavo Massaccesi
 [I remember an old discussion about this, but I can't find the message.]
For small number of clauses, case is expanded to a bunch of if. When there
are more than ¿12? it may be use a hash table or binary search. It has a
few tricks:

https://github.com/racket/racket/blob/master/racket/collects/racket/private/case.rkt

Gustavo

On Thu, Aug 22, 2019 at 3:38 PM George Neuner  wrote:

>
> On 8/21/2019 3:25 PM, Jon Zeppieri wrote:
> > Racket's `case` is an implementation of this approach:
> > http://scheme2006.cs.uchicago.edu/07-clinger.pdf
> >
> > It is not significantly complicated by `else`. And that approach was
> > created in the context of Scheme, which leaves the return value
> > unspecified when none of the tests are successful. That seems like it
> > should offer more opportunities for optimization, but I don't think
> > this approach is any less efficient when the unsuccessful result is
> > specified as # (as it is in Racket) than when it is not.
> >
> > - Jon
>
> Thanks for the pointer!
>
> 'case' in Scheme is an interesting challenge for compilation because it
> can involve dispatching on multiple types, each having its own
> comparison ordering.  I would hope that Racket leverages generic table
> searches where possible - depending on the use, generating a complete
> static dispatch routine everywhere can result in explosive growth of the
> code.  [Not that I've seen this happen, but I haven't had occasion to
> experiment in Racket with extremely large or complicated 'case'
> constructs.]
>
> George
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/a8dd208d-dd3f-a2a7-3d20-3c1027932ac9%40comcast.net
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9PvohKnSZwsnF8gn8hOKejQMpCCVWVPiNmZuQOjO2Odzw%40mail.gmail.com.


Re: [racket-users] Re: The case, and a proposal, for elegant syntax in #lang racket2

2019-08-21 Thread Gustavo Massaccesi
The expander in racket adds something equivalent to
[else (void)]
if there is no else clause. (Try an example with the Macro Stepper.) So an
explicit else clause would not change the speed of the programs.

In some cases the compiler can prove that the else part is not necessary
and drop it, Also, I think that the compiler in RacketCS can notice that it
has no side effects and also drop it if the result is ignored (but I'm not
100% sure).

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9OsXr%3DYxKxPFcKC-sCK-JuATDWR4b6NpxHooVsirj6aQw%40mail.gmail.com.


Re: [racket-users] detecting a recursive call?

2019-08-09 Thread Gustavo Massaccesi
If you don't want to use the package or you want other criteria for
stooping, I think the correct way to do this are continuation marks, but an
easier but more inefficient way is using a parameter (so it is thread safe).

;-
#lang racket
(define recursion-level (make-parameter 0))

(define (f x)
  (sleep (* .1 (random)))
  (cond
[(<= (recursion-level) 5)
 (parameterize ([recursion-level (add1 (recursion-level))])
   (displayln (list (recursion-level) x))
   (f (* x 2)))]
[else
 (displayln (list "too many recursions" x))]))

(thread (lambda () (f 10)))
(f 1)
; -

Gustavo

On Fri, Aug 9, 2019 at 2:03 PM Sam Tobin-Hochstadt 
wrote:

> This is possible -- the central trick is to maintain information about
> the call stack separately, perhaps by using continuation marks.
>
> We (mostly Phil Nguyen) recently built a tool that does this. If you
> take your program, install the "termination" package, and then add:
>
> (require termination)
> (begin/termination (recur1 0))
>
> you get this error message:
>
> possible-non-termination: Recursive call to `#` has
> no obvious descent on any argument
> - Preceding call:
>   * 1st arg: 3
> - Subsequent call:
>   * 1st arg: 6
>
> We have a paper, here: https://arxiv.org/abs/1808.02101 which goes
> into detail about how it works. The source code is here:
> https://github.com/philnguyen/termination
>
> Sam
>
> On Fri, Aug 9, 2019 at 11:58 AM Kees-Jochem Wehrmeijer
>  wrote:
> >
> > Hi,
> >
> > I'm wondering whether it's possible for a function to detect whether
> it's being called by itself, possibly indirectly. I want to use this to
> prevent endless loops and generate different results in these situations.
> For example, imagine I have the following functions:
> >
> > (define (foo loc)
> >   (list
> >(cons loc 'a)
> >(cons (+ loc 1) 'b)
> >(cons (+ loc 2) 'c)))
> >
> > (define (combine a b)
> >   (lambda (loc)
> > (append (a loc) (b (+ loc 3)
> >
> > So I can do:
> > > ((combine foo foo) 0)
> > => '((0 . a) (1 . b) (2 . c) (3 . a) (4 . b) (5 . c))
> >
> > Now, let's say I have these recursive definitions:
> >
> > (define (recur1 loc)
> >   ((combine foo recur2) loc))
> >
> > (define (recur2 loc)
> >   (recur1 loc))
> >
> > Defined in this way, a call to (recur1 0) loops endlessly. I would like
> it too return something like
> > > (recur1 0)
> > => '(0 . a) (1 . b) (2 . c) (loop 0))
> >
> > So I was thinking if I could make it work if I could do something like:
> > (define (recur1 loc)
> >   (if (in-recursive-call?)
> >   (list (cons 'loop 0))
> >   ((combine foo recur2) loc)))
> >
> > Is that something that's possible? Is there a better way to do what I
> want?
> >
> > Thanks,
> > Kees
> >
> > --
> > 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.
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/292977cf-7800-453f-9d4b-b6a1ee525287%40googlegroups.com
> .
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/CAK%3DHD%2Bb0odK1qfox9Ah2umLqKxUhas_GTJUv95Avm536g9ybGg%40mail.gmail.com
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAPaha9MPK2A5jBD4GVmtOZrSjb24tDD6-WQKPBCPuSe_Yiq6Fw%40mail.gmail.com.


Re: [racket-users] The case, and a proposal, for elegant syntax in #lang racket2

2019-07-16 Thread Gustavo Massaccesi
I always imagined racket2 as racket with a few minor backward incompatible
changes, for example make `length` generic, drop `struct`, remove
guarantees about freshness of results. I.E. Most of
https://github.com/racket/racket/wiki/Racket2  I also don't like that
`syntax-property` is used to get and to set the properties but I doubt it's
a common opinion.

Perhaps I'm overestimating the changes, but this looks like a new language.
Why not use another name?

Also, it would be nice to have a rough timeline. 5 years?

Gustavo



On Sun, Jul 14, 2019 at 2:44 PM Christopher Lemmer Webber <
cweb...@dustycloud.org> wrote:

> The context of this email is the proposal by Matthew Flatt that we move
> to an easier-to-accept surface syntax for #lang racket2.
>
> Matthew Flatt has heard more than enough from me of concern about this
> proposal.  But I should indicate that I'm highly sympathetic to the
> goal.  I would like to lay out the following observations:
>
>  - The challenge with s-expressions is largely in anxiety with something
>that looks extremely alien.  I suspect there's more fear from
>instructors than students in encountering a lisp syntax; my
>experience is that introducing someone who doesn't know differently
>to a parenthetical syntax isn't scary for them, and they tend to like
>it.  But people who have *started out* with experience in a non-lispy
>language tend to find it scary.
>
>  - Nonetheless, assumptions that various math operators should be infix
>is understandable because that's what people see today.
>
>  - I am indeed very for growth in the community, though my main interest
>in growth is in seeing a wider diversity of participants than just
>raw numbers.  Obviously other peoples' mileage may vary.
>
>  - We are at serious risk in this pivot of losing some key things:
>
>- Many communities I have been in that have undertaken such a large
>  pivot to increase popularity expend enormous energy in the move to
>  the new thing, and in that process, the project actually collapses.
>  What I'm trying to say is that a pivot is a gamble; we should
>  calculate our odds carefully.  (Indeed, the first thing I thought
>  when I heard that this might happen was, did I make a mistake in
>  shifting my work to Racket?  It is unlikely I would have come to
>  Racket if there wasn't an equivalent amount of elegance.)
>
>- I'm not sure if I could have understood Racket Week with a syntax
>  that didn't have the elegance of s-expressions.  This is not to say
>  that *no* syntax can have that level of elegance where things can
>  be so clear, however.
>
> IIRC Matthew's proposal for "#lang racket2" was something like the
> following:
>
>  a) function(args ...) should work.
>  b) infix is necessary for math, such as 3 + 4
>  c) parentheses should be possible for grouping
>
> The weird thing about the last one being that this is already kind of
> true in s-expressions, but by ~default this also results in application.
>
> Let me add one more suggested design goal:
>
>  - the new syntax should must not be significantly less elegant than
>s-expressions.
>
> Is there a way to achieve this?  I actually think the best path forward
> is to have a surface syntax that actually maps completely to
> s-expressions, which is in fact universal that it can work with *any*
> s-expression syntax.
>
> I would suggest starting with Wisp as the basis for examining this:
>
>   https://dustycloud.org/blog/wisp-lisp-alternative/
>   https://srfi.schemers.org/srfi-119/srfi-119.html
>
> Sweet-expressions may also be an alternative to explore.  However, I
> think Wisp is a more elegant base; it can transform *any* wisp code into
> s-exp code.  Not discussed in my blogpost about Wisp is that it also
> supports infix via {3 + 4}.  So ok, now we have that.  And we can still
> group:
>
>   {3 + {8 + 4}}
>
> So that's points b) and c), but we don't have a) yet.  Could we add it?
>
> I think we can extend wisp with one thing and get everything we want: if
> you have func(arg1 arg2 arg3) where the parenthesis comes *immediately*
> after the symbol, that is rewritten to (func arg1 arg2 arg3).  I will
> call this version ~Wisp.
>
> With all this, observe the following code rewritten from Scheme to ~Wisp:
>
>   (define (rgb-maker mk)
> (lambda (sz)
>   (vc-append (colorize (mk sz) "red")
>  (colorize (mk sz) "green")
>  (colorize (mk sz) "blue"
>
>   define rgb-maker(mk)
> lambda(sz)
>   vc-append(colorize(mk(sz) "red")
> colorize(mk(sz) "green")
> colorize(mk(sz) "blue"))
>
> Here is another chunk of code, taken from HTdP2:
>
>   (and (or (= (string-length "hello world")
>   (string->number "11"))
>(string=? "hello world" "good morning"))
>(>= (+ (string-length "hello world") 60) 80))
>
> To:
>
>   and(or({string-length("hello world") = 

Re: [racket-users] From HtDP to Racket

2019-04-26 Thread Gustavo Massaccesi
There is a TOC at the beginning of the post, but I'd add a link to the next
post at the end. Something like:

  "Next article in the series: From HtDP to Racket. Racket (2): only-in,
rackunit, test submodules"

I'd put one at the very end and other just before the code.

Gustavo

PS: As other user said, it would be good to explain once what BSL, ISL, ...
are.



On Thu, Apr 18, 2019 at 1:08 PM Luis Sanjuán 
wrote:

> The last month or so we all read some interesting posts about the
> convenience of examples or docs to facilitate the transition from other
> languages to Racket (from Python to Racket, from R to Racket, ...). Then I
> thought about another non-Racket languages that no one mention, if I recall
> well, for which such examples would be more than helpful, *SL languages ;)
>
> Of course, The Realm is there, but more examples would be beneficial, I
> guess. I have written something along these lines on my blog:
>
>
> https://los-pajaros-de-hogano.blogspot.com/2019/04/from-htdp-to-racket-isbn-extraction-in.html
>
> It might be full of inaccuracies or even errors. So comments, fixes, or
> suggestions are welcomed.
>
> --
> 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] Defeating Racket’s separate compilation guarantee

2019-04-24 Thread Gustavo Massaccesi
We can extract an feature request from the end of the post:

Make the module that define `set` a cross-phase persistent module, so all
the phases can share the `set`s.

Gustavo




On Sun, Apr 21, 2019 at 7:41 AM Alexis King  wrote:

> Hello all,
>
> I just published a blog post on defeating Racket’s separate compilation
> guarantee. While I don’t imagine such a thing is actually a good idea, I
> think the path to getting there is interesting anyway, and it touches lots
> of different parts of the Racket system. For those who are interested, the
> blog post is available here:
>
>
> https://lexi-lambda.github.io/blog/2019/04/21/defeating-racket-s-separate-compilation-guarantee/
>
> Comments welcome,
> Alexis
>
> --
> 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] Program aborts except when there are no previously compiled .zo files

2019-04-12 Thread Gustavo Massaccesi
It would be good if you can share a link to the code. It is difficult to
guess where is the problem is with this information. Is there an online
public repository with the code?

If not, can you make a minimized version without all the classified/secret
parts of the code? With a version of the code that we can run, it's
(sometimes) easier to understand where the error is.

If possible reduce the code as much as possible, remove whatever is not
used. But ensure that the reduced version still has the same problem. This
reduction is not 100% necessary, but it reduces the debugging time a lot.
Also, it helps to remove the secrets parts.

Gustavo




On Fri, Apr 12, 2019 at 10:08 AM Dmitry Pavlov  wrote:

> Hello,
>
> My program demonstrates an unexpected behavior
> depending on how I run it.
>
>
> $ 
>
> $ racket program.rkt
> 
>
> $ raco make program.rkt
> 
>
> $ racket program.rkt
> read: bad syntax `#fx'
>in: compiled/subprogram.mylang.zo
>context...:
> "/path/to/myprogram.rkt": [running body]
> temp37_0
> for-loop
> run-module-instance!125
> perform-require!78
>
>
> Now, in DrRacket:
>
>  on myprogram.rkt works fine if I uncheck the
> "populate compiled directories" option.
>
> When I check the "populate compiled directories" option,
> or when there are compiled directories previously
> populated, DrRacket aborts, printing a message
>
> "about to suspend in atomic mode"
>
> regardless of whether I turn debugging on or off.
>
>
> The program (require)s another module written
> in a different non-sexp #lang with a special fancy
> compiler.
>
> Racket 7.2, Linux x64.
>
> Also tried on OS X: same behavior only DrRacket
> does not abort, but gives the same '#fx' error instead.
>
>
> Can I provide any more information to help determining
> what is the problem?
>
>
> Best regards,
>
> Dmitry
>
> --
> 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] The distribution of numbers returned by (random)

2019-04-03 Thread Gustavo Massaccesi
The implementation is tricky, but you can understand the distribution
looking at this "alternative" implementation:

(define (myrandom)
#;(/ (+ (random 4294967087) 1) (+ 4294967087 1))
(* (+ (random 4294967087) 1) 2.328306549295728e-10))

[it may have a tiny rounding difference]

Gustavo

Implementation for the current version of Racket (written in C)
https://github.com/racket/racket/blob/master/racket/src/racket/src/newrandom.inc

Implementation a version of Racket in the future (not next version)
(written in Scheme)
https://github.com/racket/racket/blob/master/racket/src/cs/rumble/random.ss




On Tue, Apr 2, 2019 at 2:14 PM  wrote:

> Hello everyone,
>
> The specification of `random` function with zero arguments is only that a
> random inexact real numbers between 0 and 1 is generated. I have two quick
> questions about it,
>
> 1. Will all random inexact real numbers between 0 and 1 be eventually
> generated?
> 2. What's the distribution of the numbers generated? Uniformity is a
> little bit ambiguous here because it can mean either each floating-point
> number gets equal chance to be generated or its probability is proportional
> to the interval where real numbers get rounded to it.
>
> Thanks,
> Shaobo
>
> --
> 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] Can someone help me solve a raco mystery?

2019-03-23 Thread Gustavo Massaccesi
 > 2) The error seems to happen on computers where I am switching some
package
> in the dependency graph from a catalog installation to a github repo
installation.
>  I'm not sure if this could contribute to raco deciding that two packages
with the
> same name are actually different and, for some reason, trying to update
them both.


I have no clue about what is happening here, but this part sounds
promising. For debugging, you can modify the in the file
pkg/private/install.rkt the function format-deps near
https://github.com/racket/racket/blob/master/racket/collects/pkg/private/install.rkt#L128
so it shows all the fields of the pkg-desc instead of showing only the name.

The definition is
(struct pkg-desc (source type name checksum auto? extra-path))

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] How to fix typos in documentation?

2019-03-11 Thread Gustavo Massaccesi
I just want to clarify that if someone finds an error in the docs or a bug,
it's perfectly fine to just send a bug report:

* Inside Racket: Go to the menu > About > Submit Bug Report ...

* In Github: Submit an "Issue"

Please include enough information to reproduce the bug. For example for a
typo in the docs, I like a link to the online page of the documentation
where the typo was found, so it's completely obvious where the error is.

Someone will read the report, and make the correction. (It may take a few
month, until the next release, for the change to be visible in the online
docs.) After fixing the error, I like to reply with a link the commit that
fix the error. You can read the commit and try to understand which file was
modified, and perhaps next time send a pull request with the fix.

In the long run, it's better if you can send a pull request as discussed in
the previous messages, but every bug report with enough information is very
useful.

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] Re: nested for loops and suggested alternatives

2019-02-10 Thread Gustavo Massaccesi
To understand the problem, it will be useful to understand the difference
between

-- (make-vector 5 (make-vector 5))
-- (build-vector 5 (lambda (_) (build-vector 5 (lambda (_) 0
-- (for/vector ([_ 5]) (for/vector ([_ 5]) 0))

Gustavo

On Sun, Feb 10, 2019 at 7:24 AM  wrote:

> Yes, this was the problem. I now have results that match the output from
> R. I've updated the gist with your line for the correct way to create a
> vector of vectors. I will have to spend some more time to understand the
> make-vector behavior. Perhaps my thinking is too constrained by my R
> experience where many functions are "vectorized"? I guess the part that was
> confusing me (and still is) is why make-vector worked as expected (by me)
> for my inner vector but not my outer vector. Thanks!
>
>
> On Sunday, February 10, 2019 at 12:42:53 AM UTC-8, Alex Harsanyi wrote:
>>
>> This line looks suspicious:
>>
>>  (define results (make-vector years (make-vector (vector-length
>> fecundity) 0)))
>>
>> The "(make-vector (vector-length fecundity) 0)" expression will create a
>> single vector, than it creates the outer vector will all elements pointing
>> to it.  It is not a matrix, but a "column" vector where each element is
>> referencing the same row vector.  This means that if you update an element
>> in one of the rows, the same value will "appear" in all other rows. The
>> only row that is different is the first one which you initialize in the
>> line:
>>
>> (vector-set! results 0 (make-vector (vector-length fecundity) 10))
>>
>> What you probably want is a vector of vectors, which can be built like
>> this
>>
>> (define results (for/vector ([index (in-range years)]) (make-vector
>> (vector-length fecundity) 0)))
>>
>> Alex.
>>
>>
>>
>> On Sunday, February 10, 2019 at 3:40:42 PM UTC+8, travis.h...@gmail.com
>> wrote:
>>>
>>> Hi All,
>>>
>>> I'm an R programmer that has recently started learning Racket. I decided
>>> to start by trying to create a simple age-structured population model. In
>>> R, I would initialize a matrix and use nested for loops to move through the
>>> elements of the matrix and propagate the population forward through time.
>>> For my first attempt in Racket (
>>> https://gist.github.com/hinkelman/3ee6115cdd7f0a4c8f1672b7d8df5c27), I
>>> used for* to loop through a vector of vectors. The code in that gist
>>> doesn't quite work. There is apparently something wrong with how I'm using
>>> vector-set! such that "rows" in my vector of vectors are being updated
>>> prematurely. I would greatly appreciate it if someone could point out what
>>> I'm doing wrong there. I'm also interested in suggestions for alternative
>>> approaches because it seems unlikely that I have written this code in
>>> idiomatic Racket.
>>>
>>> Thanks,
>>>
>>> Travis
>>>
>>> P.S. If it is helpful, here is a gist (
>>> https://gist.github.com/hinkelman/d5b8414b0c6383057d7846509a724bbf)
>>> with the R code that I was trying to write in Racket.
>>>
>> --
> 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] Re: updated Racket-on-Chez status

2019-02-05 Thread Gustavo Massaccesi
 I have been trying a few variations of the code. It would be nice to have
a test branch that use only the data in the repository. I used some fake
data instead.

For the tests, I used the function *get-mean-max-bounds*
https://github.com/alex-hhh/ActivityLog2/blob/master/rkt/data-frame/meanmax.rkt#L409
with this data

  (define fake-data2
(for/list ([_ (in-range 1000)])
  (if (< (random) .01)
 (vector #f #f)
 (vector (- (random) .5) (- (random) .5)

so, I tested with

  (time (get-mean-max-bounds fake-data2))



*** The main time improvement was changing
  (for ([b bavg] #:when (vector-ref b 1))
...)
to
  (for ([b (*in-list* bavg)] #:when (vector-ref b 1))
...)

This increase the speed to the double or more. In the microbenchmark, the
new duration is the 40%-50% of the original duration.

IIUC, in all functions you know the type of sequence of the arguments, so
my advice is to add in-list or in-vector to each and every for in the whole
file (or project).

This is a good general recommendation. With in-list or in-vector or
in-range, the generated code is very efficient. Without them, the code has
to create a generic object to track the iteration, and the code is much
slower.


*** I tried eliminating the set! and using for/fold instead. The problem is
that the code is slower :(. In general it's better to avoid mutable
variables, but in this case removing them makes the program slower. We
should take a look at the internal code of Racket and try to fix it,
because in a perfect world the version without set! should be faster.
Meanwhile, keep the current version...


*** I tried replacing the for and set! with an explicit loop. Something like
 (let loop ([bavg bavg] [min-x #f] [max-x #f]  [min-y #f] [max-y #f])
   ...)

With this change, there is an additional 5% improvement in the speed, but
the legibility is reduced too much. So this is better than the version with
for and in-list, but I recommend to keep the legible version.


*** I tried replacing the initial value of min-x and friends with +inf.0,
and removing the if in the updates. I'm convinced this is a good idea, but
the change in speed is negligible.




In conclusion, try adding as much in-list, in-vector and in-range as you
can.

Gustavo




On Thu, Jan 31, 2019 at 9:58 AM Alex Harsanyi 
wrote:

>
> On Thursday, January 31, 2019 at 9:23:39 AM UTC+8, Matthew Flatt wrote:
>>
>> > I would be happy to help you identify where the performance degradation
>> > between Racket 7.1 and CS is when running these tests.
>>
>> Small examples that illustrate slowness in a specific subsystem are
>> always helpful. I can't always make the subsystem go faster right away,
>> but sometimes.
>>
>>
> I timed some key functions in my application to understand which parts of
> Racket CS are slow.  I did a write-up in the Gist listed below, but the
> result seems to be that even functions that run Racket only code with no IO
> or calls into C libraries run slower in Racket CS.  Code that calls into
> the database library to run SQL insert queries runs significantly slower.
> The only things which were faster in Racket CS were one "Racket only"
> function, `df-histogram` and a function which retrieved data from an SQL
> query, `df-read/sql`
>
> https://gist.github.com/alex-hhh/1ebc1c83b68ee4620a70fc30d2caa6a3
>
> Alex.
>
> --
> 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] Python's append vs Racket's append and helping novices understand the implications

2019-02-04 Thread Gustavo Massaccesi
For some reason, the Racket vs Python performance is a question that arise
from time to time in Hacke News (like 2 or 3 times per year). Last time I
asked if it was possible to add a direct comparison in The Computer
Language Benchmarks Game and the owner/maintainer added that page. The
results are in
https://benchmarksgame-team.pages.debian.net/benchmarksgame/faster/racket-python3.html
[Standard disclaimer: The results change from program to program, so take
this comparison only as a guide.]

A short version of the results is that:
* in 6 of the programs Racket is much faster
* in 1 of the programs Racket is faster
* in 2 of the programs there is almost a tie
* in 1 of the programs Racket is slower

Some programs in Racket need parallelization, so the results may improve in
the future. [I didn't look too carefully at the programs in Python.]

My unofficial takeaway, not completely backed by the benchmarks, is that
* For numeric programs Racket is (may be) 5 to 20 times faster than Python
* For programs with too many stings and hashes, the speed is almost the
same.



Also, there was an old thread about translating the classic Norvig's
spelling correction from Python to Racket, without changing the structure
of the implementation too much and using idiomatic code.
https://groups.google.com/forum/#!topic/racket-users/u0Ua1kTUSKw After a
few attempts, the final version in Racket was a 30% slower. I didn't follow
this too much after the discussion, so I don't know if there is a smaller
or bigger difference using the current versions. (Also, I think we never
tried to make is fast as possible, with the same algorithms, but changing
the implementation as much as it was necessary.)

Gustavo

On Sun, Feb 3, 2019 at 7:38 PM Matthias Felleisen 
wrote:

>
> Agreed!
>
>
>
> On Feb 3, 2019, at 4:43 PM, Robby Findler 
> wrote:
>
> It seems like a great addition to the performance section of the guide.
>
> Robby
>
> On Sun, Feb 3, 2019 at 3:35 PM Matthias Felleisen 
> wrote:
>
>>
>> 1. I think this is a great start for a generic introduction to data
>> structures. Someone should integrate Jens’s short table:
>>
>>
>> https://stackoverflow.com/questions/27584416/in-racket-what-is-the-advantage-of-lists-over-vectors/27589146#27589146
>>
>>
>>
>> 2. I think language-to-language documents serve a different role, but
>> your document could be cited from there.
>>
>> The point of say “From Python to Racket” would be to show how
>> comprehensions translate or how classes work 1-1. And yes, it would also
>> explain that Racket calls something a list that does __not___ at all
>> correspond to a list.
>>
>> The corresponding Java write-up would be quite different again. In that
>> case, we would be dealing with people who might not know more than classes
>> and methods. But they might actually know proper design and might know that
>> it calls for recursion (hidden in classes and interfaces). In Racket, that
>> works even better than in Java. Plus it would need to say something brief
>> about types.
>>
>> And R would be an entirely different story.
>>
>> — Matthias
>>
>>
>>
>>
>>
>> On Feb 2, 2019, at 11:37 PM, Alex Harsanyi 
>> wrote:
>>
>>
>> I put together some notes about available data structures in Racket, with
>> some performance considerations.  It needs more work, but perhaps it can be
>> used as a starting point and it can be added to the Racket wiki, if/when
>> others consider it adequate:
>>
>> https://gist.github.com/alex-hhh/3cc5690a7f9c74543dab6c11344e6202
>>
>> I didn't write a "Python to Racket" guide, because I don't really know
>> enough about Python to write such a document, and I also think that a more
>> generic document is simpler to maintain and can be used by people who come
>> from other languages as well.
>>
>> I also tried to keep the document short, the aim being to provide a
>> competent programmer who is new to Racket with a 5 minute overview to its
>> data structures and some links to the starting points in the
>> documentation.  We can add things to it, but I think it is better to keep
>> it short rather than comprehensive in this case -- after all, there is the
>> Racket Guide and Racket Reference and these documents contain all the
>> details.  Perhaps new documents can be added to the wiki, exploring other
>> topics in more detail.
>>
>> I did not mention `ralist` because (1) I have no experience with it, but
>> more importantly (2) the package is not part of the Racket distribution and
>> has to be installed separately.  I don't it reflects well on Racket if we
>> tell people to install a separate package if they want an efficient
>> container...  I have no experience with `ralist`, but if it is indeed a
>> good data structure and it has a potentially wide usage, it should be
>> included in the default Racket installation.
>>
>> Alex.
>>
>> On Sunday, February 3, 2019 at 7:00:10 AM UTC+8, Matthias Felleisen wrote:
>>>
>>>
>>>
>>> Racket needs *you*. Please.
>>>
>>> The proper approach is to 

Re: [racket-users] Collections and data structures wishlist?

2019-01-24 Thread Gustavo Massaccesi
I also like the idea of a contract like "tuple/c", perhaps with a more
rackety name.

Gustavo

On Wed, Jan 23, 2019 at 12:02 PM Greg Hendershott 
wrote:

> >> - A separation between using lists as homogeneous collections and using
> lists as fixed-size tuples. So there'd be a separate `tuple?` data type
> that's structurally equivalent to a list but meant to be used differently.
> For example, `(list/c number?)` would mean a list of many numbers, but
> `(tuple/c number?)` would mean a tuple of size 1 containing a number.
> >
> > "It is better to have 100 functions operate on one data structure than
> 10 functions on 10 data structures.”
> http://www.cs.yale.edu/homes/perlis-alan/quotes.html
> > "It is better to have 100 transducers operate on one data structure
> interface than 10 functions on 10 data structures.” Rich Hickey, History of
> Clojure
>
> Well also, I thought `list/c` already means "tuple"?
>
> (listof number?) is a list of many numbers.
> (list/c number?) is a list of one number.
>
>
> I think it's within the Racket spirit to make a little #lang for
> certain audiences or projects. At some org, "tuple/c" might be a
> helpful alias. Or, for some other team, it's not, and in fact even
> "list/c" is redefined to raise an error, "Please use structs instead
> of ad hoc tuples."
>
> --
> 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] hackernews

2018-12-17 Thread Gustavo Massaccesi
I agree that it would be much better to write good blog posts about Racket.
They don't need to be fantastic, they don't need to be better than the
documentation, they only has to be interesting. I usually prefer post with
one or two big relevant graph (or photos when there is hardware involve), I
like images. (It doesn't have to be very interesting, sometimes an article
is more interesting than what you expect)

Have you recently solved some interesting problem (using Racket)? It's
better if it's a real life problem, but a nice toy problem can be
interesting too.

Sometimes translating an interesting article to Racket can be a good idea,
if the translation shows some unique feature, like a smart use of macros or
a library that are not available in other languages.

(Don't post too often. Unless you are very good writing, you can't write
more than one interesting article per week(/month(/year)).)

---

The problem of going to HN to write comments about Racket is that the
community has a lot of unwritten rules. (No jokes. No kittens. No
astroturfing/sockpupet/meatpupets. No onliners. [1] . No voting rings. No
asking for votes in other platforms.)

There is no problem if an article gets popular and the author goes to the
site to answer the questions. The unwritten rules are not too strict and
they don't apply if the author can give some interesting relevant answers
and more information. *Don't be afraid of answering questions there.*

Some types of bad comments:

* photobomb unrelated threads with a reference to Racket. (For example, in
an article about regular expression in PHP, posting "Racket has two types
of regular expressions").

* astroturfing comments (For example in an article about something in
Racket, posting "I use it too and it is fantastic" [there is also an
unwritten rule about too many exclamation marks].)

* fake questions in unrelated articles (like "I wonder if it possible to
write this in Racket?")

* "Why didn't they use Racket instead?" "Why don't they rewrite this in
Racket?" ([bonus negative points if it is another Scheme-like language])

Gustavo


[1] You can write onliners in HN, but it's very difficult to write good
onliners. It's much easier to add more information and more context. Jokes
are also legal, but it must be a very good original joke, so better avoid
jokes.




On Sat, Dec 15, 2018 at 1:48 PM Peter Schmiedeskamp 
wrote:

> I’m probably guilty of already being part of this task-force. To add, I
> wonder if there’d be value in some longer, blog-form replies to interesting
> HackerNews queries.
>
> For example, someone was extolling the virtues of some new system for
> building and packaging simple GUI apps for Linux using Python. I’ve poked
> around with the GUI and packaging facilities of Racket enough to feel like
> Racket has a pretty good story to tell, at least for smaller cross-platform
> apps. A short blog showing the end-to-end creation of a small GUI app, with
> emphasis on showing the symbiosis of the GUI library and the excellent raco
> packaging and distribution facilities would be a great “reply” to such an
> article on HN.
>
> I wonder if there's a way that these use cases could at least be
> collected... maybe as an RFB—Request For Blog. Time is always at a premium,
> but I could imagine picking off a blog post here and there even though I’m
> a decidedly rank novice Racketeer.
>
> Maybe there’s already a list somewhere? Maybe RFBs could be a section of
> the Racket Blog?
>
> Best,
> Peter
>
> --
> 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.
>

On Sat, Dec 15, 2018 at 1:48 PM Peter Schmiedeskamp 
wrote:

> I’m probably guilty of already being part of this task-force. To add, I
> wonder if there’d be value in some longer, blog-form replies to interesting
> HackerNews queries.
>
> For example, someone was extolling the virtues of some new system for
> building and packaging simple GUI apps for Linux using Python. I’ve poked
> around with the GUI and packaging facilities of Racket enough to feel like
> Racket has a pretty good story to tell, at least for smaller cross-platform
> apps. A short blog showing the end-to-end creation of a small GUI app, with
> emphasis on showing the symbiosis of the GUI library and the excellent raco
> packaging and distribution facilities would be a great “reply” to such an
> article on HN.
>
> I wonder if there's a way that these use cases could at least be
> collected... maybe as an RFB—Request For Blog. Time is always at a premium,
> but I could imagine picking off a blog post here and there even though I’m
> a decidedly rank novice Racketeer.
>
> Maybe there’s already a list somewhere? Maybe RFBs could be a section of
> the Racket Blog?
>
> Best,
> Peter
>
> --
> You received this 

Re: [racket-users] minor doc change proposal?

2018-11-29 Thread Gustavo Massaccesi
This function is a already defined in a few libraries and it is called
`true?` for example in
https://docs.racket-lang.org/predicates/index.html?q=true#%28def._%28%28lib._predicates%2Fmain..rkt%29._true~3f%29%29

I think that `not-false?` is easier to understand, but `true?` is more
idiomatic.

Gustavo




On Thu, Nov 29, 2018 at 3:11 PM 'John Clements' via Racket Users <
racket-users@googlegroups.com> wrote:

> This stack overflow post
>
>
> https://stackoverflow.com/questions/53543191/what-is-the-different-between-filter-and-filter-map/53545115#53545115
>
> … is written by someone confused by the documentation for `filter-map`. I
> went and read the documentation, and *I* was confused for about 30 seconds.
> I eventually proposed rewriting the existing
>
> Returns (filter (lambda (x) x) (map proc lst ...)), but without building
> the intermediate list.
>
> to
>
> Returns (filter not-false? (map proc lst ...)), but without building the
> intermediate list, where not-false? can be defined as (lambda (x) x).
>
> This text is kludgier, but I think that the use of (lambda (x) x) as
> “not-false?” is idiomatic and confusing. And yes, I realize that this
> suggestion probably applies to many places in the docs. Maybe I should just
> propose adding `not-false?` as a library function, defined as (lambda (x)
> x)….
>
>
> John
>
>
>
> --
> 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] cons-specific optimizations?

2018-11-28 Thread Gustavo Massaccesi
 The last example should be

(when (and (list? l) (pair? l))
  (let ([x (cdr l)])
(list? x)  ;==> #t
))

Gustavo

Technical note: The optimizer wants to be sure that (cdr l) is safe before
asserting that x is a list?. It should be ok to mark x as a list?, because
if there is an error the inner code will not be run anyway. I'll try to
remember why I made this, and send a PR if necessary.



On Wed, Nov 28, 2018 at 6:36 PM Gustavo Massaccesi 
wrote:

> Some additional comments about this subject.
>
> A big difference is that in Chez Scheme the cons are mutable, and that
> makes it almost impossible to make any optimization with the lists at the
> Chez Scheme level.
>
> With the current Racket implementation there are a few reductions at
> compile time for the lists, for example
>
> (car (list 1 2 3)) ; ==> 1
>
> (when (list? l)
>   (let ([x (cdr l)])
> (list? x)  ;==> #t
> ))
>
> The optimizer "understands" lists, but it doesn't understand custom
> structs that have are list like nesting.
>
> Also, there was an attempt to implement the mcons using a struct instead
> of a special construction, but some programs were too slow with the
> modification, so it was never merged.
> https://github.com/racket/racket/pull/1316
>
> Gustavo
>
>
>
>
>
> On Wed, Nov 28, 2018 at 3:26 PM Matthew Flatt  wrote:
>
>> Right. An alternative would be to set decide eagerly, but `list?` tests
>> are infrequent relative to pair constructions.
>>
>> Then again, a function like `list` can and does set the "is a list" bit
>> eagerly and cheaply on newly allocated pairs.
>>
>> At Wed, 28 Nov 2018 18:16:31 +0100, Robby Findler wrote:
>> > Also "don't know yet".
>> >
>> > Robby
>> >
>> > On Wed, Nov 28, 2018 at 6:15 PM Alexis King 
>> wrote:
>> >
>> > > > On Nov 28, 2018, at 07:15, Matthew Flatt 
>> wrote:
>> > > >
>> > > > Yes, that's special handling for pairs in the sense that the
>> > > > traditional Racket implementation takes advantage of leftover bits
>> in a
>> > > > pair object, and it uses two of them for "is a list" and "not a
>> list".
>> > > >
>> > > > Racket-on-Chez doesn't have the extra bits to work with, so "is a
>> list"
>> > > > and "not a list" information is recorded separately in an
>> `eq?`-based
>> > > > hash table.
>> > >
>> > > Why does keeping track of “is a list” and “not a list” require two
>> bits?
>> > > It seems like a pair either is or is not a list, so one bit of
>> information
>> > > would be sufficient. Are there situations where the system can
>> neither be
>> > > sure that something is or is not a list? Circular lists, or something
>> like
>> > > that?
>> > >
>> > > (This is not really important, of course, I’m just curious.)
>> > >
>> > > Alexis
>> > >
>> > > --
>> > > 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.
>>
>> --
>> 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] cons-specific optimizations?

2018-11-28 Thread Gustavo Massaccesi
Some additional comments about this subject.

A big difference is that in Chez Scheme the cons are mutable, and that
makes it almost impossible to make any optimization with the lists at the
Chez Scheme level.

With the current Racket implementation there are a few reductions at
compile time for the lists, for example

(car (list 1 2 3)) ; ==> 1

(when (list? l)
  (let ([x (cdr l)])
(list? x)  ;==> #t
))

The optimizer "understands" lists, but it doesn't understand custom structs
that have are list like nesting.

Also, there was an attempt to implement the mcons using a struct instead of
a special construction, but some programs were too slow with the
modification, so it was never merged.
https://github.com/racket/racket/pull/1316

Gustavo





On Wed, Nov 28, 2018 at 3:26 PM Matthew Flatt  wrote:

> Right. An alternative would be to set decide eagerly, but `list?` tests
> are infrequent relative to pair constructions.
>
> Then again, a function like `list` can and does set the "is a list" bit
> eagerly and cheaply on newly allocated pairs.
>
> At Wed, 28 Nov 2018 18:16:31 +0100, Robby Findler wrote:
> > Also "don't know yet".
> >
> > Robby
> >
> > On Wed, Nov 28, 2018 at 6:15 PM Alexis King 
> wrote:
> >
> > > > On Nov 28, 2018, at 07:15, Matthew Flatt  wrote:
> > > >
> > > > Yes, that's special handling for pairs in the sense that the
> > > > traditional Racket implementation takes advantage of leftover bits
> in a
> > > > pair object, and it uses two of them for "is a list" and "not a
> list".
> > > >
> > > > Racket-on-Chez doesn't have the extra bits to work with, so "is a
> list"
> > > > and "not a list" information is recorded separately in an `eq?`-based
> > > > hash table.
> > >
> > > Why does keeping track of “is a list” and “not a list” require two
> bits?
> > > It seems like a pair either is or is not a list, so one bit of
> information
> > > would be sufficient. Are there situations where the system can neither
> be
> > > sure that something is or is not a list? Circular lists, or something
> like
> > > that?
> > >
> > > (This is not really important, of course, I’m just curious.)
> > >
> > > Alexis
> > >
> > > --
> > > 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.
>
> --
> 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] Racket-on-Chez snapshots

2018-10-01 Thread Gustavo Massaccesi
I think that is is possible to add an unofficial CS target to
travis-racket (https://github.com/greghendershott/travis-racket) using
something similar to https://github.com/racket/racket/pull/2266 . For
now it will be slow because it will have to install a normal Racket,
ChezScheme and recompile everything. But in the future it may use the
racket-cs installer.

Gustavo


Gustavo


On Mon, Oct 1, 2018 at 12:31 PM Matthew Flatt  wrote:
>
> That's a good idea. It won't happen this week, but maybe it can happen
> in November or so.
>
> At Mon, 1 Oct 2018 10:21:46 -0500, Philip McGrath wrote:
> > Would it be feasible and useful to start building Racket-on-Chez snapshots
> > along with the other variants at https://pre.racket-lang.org? In light of
> > the promising outlook for Chez replacing the current Racket VM in the
> > relatively near future, I would be interested in starting to include it in
> > my CI tests. (I wish I 'd thought of this question yesterday.)
> >
> > If so, my vote would be for the executables in a Racket-on-Chez snapshot to
> > be named `racket ...` rather than `racketcs ...` to minimize special-casing
> > in scripts
> >
> > -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.
>
> --
> 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] Re: Question about Racket design philosophy: returning (void)

2018-04-12 Thread Gustavo Massaccesi
For debuging I like

  (define (show x)
(display x)
x)

  (define (noshow x)
x)

For example in

  (define (average x)
(/ (+ (car x) (show (cdr x))) 2))

noshow is useful to turn on/off them fast.

But this is different from the convension of << in the streams of C, that
return the stream instead of the value, something like

  (<< (<< cout "Hello ") "Word!")

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] Another pkgs badge improvement, re needing documentation

2018-03-26 Thread Gustavo Massaccesi
Just to repeat an idea of the mail of Jay McCarty ...

I usualy work with minimal ammount of packages (probably 20, most of them
installed because other packages require them).This is a very small
instalation that can be recompiled quite fast and use very litle memory.

If I add some of the packages that have documentation, they install also
all the scrible code, and a lot of packages (I don't remember the number,
probably 50 or 100) that are much bigger and slow to recompile.

So a package without docs inside is a huge win for small instalations.

Gustavo



On Mon, Mar 26, 2018 at 4:16 PM, Jay McCarthy 
wrote:

> On Mon, Mar 26, 2018 at 3:11 PM, Neil Van Dyke 
> wrote:
> > Philip McGrath wrote on 03/26/2018 02:15 PM:
> >>
> >>  "foo"/"foo-lib"/"foo-doc"/"foo-test" package groups, which seem to be
> a
> >> prominent part how the Racket package system is used in practice.
> >
> >
> > Is a convention of breaking up code packages into separate lib/doc/test
> > packages a good thing, or is it usually done because (theories):
> >
> > 1. people saw it mentioned in package system docs, and/or saw an example
> of
> > it, and assumed it was a recommended practice;
>
> I assume that people do it because they see the team that produces
> DrRacket, the GUI, etc doing it.
>
> > 2. it is to mitigate actual space/time problems (e.g., "I don't want to
> > build docs when I deploy", "I don't want to compile anything on my little
> > router") that could better be handled by the right simple tools support,
> > while keeping the packages and package model clean and simple; or
>
> It is necessary to make "minimal" packages and to have a "minimal"
> install. I think the main use case is that documentation is likely to
> include a picture, which will be generated by plot or one of the many
> drawing systems, and then including documentations means that a
> headless server now needs all the GUI tools.
>
> > 3. there is perceived pressure from large and monolithic packages (e.g.,
> a
> > small use ends up working with lots of linearly-scaled bytes of package,
> and
> > the documentation portion of those bytes is wrongly blamed, rather than
> the
> > sheer amount of code stuff), but some of those monolithic packages might
> > better be decomposed into smaller and more flexible topical packages
> (rather
> > than lib/doc/test)?
>
> My opinion is that many existing packages can be divided up in the way
> you suggest.
>
> > Just checking that this is on the best practical path, since, in some
> > regards, we aren't stuck legacy like some are.  The Racket package system
> > was redone from scratch rather recently, and not saddled with 25 years of
> > engineering debt like some other packages systems for distros and
> languages.
> > We also have the advantage that code in Racket packages can use the
> > flexibility of the language for modularity purposes that otherwise might
> put
> > more burden on a package system.  We still have opportunity to have the
> > package system be fairly clean and simple, and to save the rare
> > bulk/complexity for high-value features (e.g., versioning, stripping).
>
> My original hope was that we could have tools to automatically produce
> test-less/doc-less/etc-less editions of packages from a single source,
> but figuring out what to include/not-include is pretty hard in Racket
> and it turns out that making these sorts of separating decisions by
> the author is pretty much exactly what the package system provides
> for.
>
> Jay
>
> --
> -=[ Jay McCarthy   http://jeapostrophe.github.io]=-
> -=[ Associate ProfessorPLT @ CS @ UMass Lowell ]=-
> -=[ Moses 1:33: And worlds without number have I created; ]=-
>
> --
> 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] Does Racket offer anything for implementing a language with its own GC that could manage GPU memory?

2018-02-15 Thread Gustavo Massaccesi
> Also I forgot to note that I also want my language to have indentation
> sensitive syntax. Would that be doable in Racket?

It's possible (but I never tried it). In the official distribution there
are a few languages implemented in Racket that doesn't look like Racket at
all. For example https://docs.racket-lang.org/algol60/index.html and
https://docs.racket-lang.org/honu/index.html . I also remember a recent
talk by Mathew Flatt about how to implement a non standard language (with
princess and castles ...) but I can't find a link now.

Gustavo


On Sun, Feb 11, 2018 at 2:19 PM, Marko Grdinic  wrote:

> Also I forgot to note that I also want my language to have indentation
> sensitive syntax. Would that be doable in Racket?
>
> --
> 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] Re: Confirming when garbage collection runs

2017-12-21 Thread Gustavo Massaccesi
I'm not sure if this is the exact answer to your question, but I hope it helps.

This program shows the content of the two vectors, (i.e.
) but when the first vector is
freed it displays "goodbye" in the middle of the sequence. So you can
see when it was released.

You can modify it to peek what job-queue is doing.

Gustavo

(PS: If you use a "list" instead of a "vector", you will get a weird
result, because the head of the list is released as soon as possible,
but the tail is not released until later.)

;--
#lang racket

; force some randoms garbage collections
(void (thread
   (lambda ()
 (let loop ()
   (sleep (random 1 3))
   (collect-garbage)
   (loop)

; make a will executor to see when something is freed
(define the-executor (make-will-executor))
(void (thread
   (lambda ()
 (let loop ()
   (will-execute the-executor)
   (loop)
(define (remember-to-say-goodbye v)
  (will-register the-executor
 v
 (lambda (x) (display "goodbye"

; display, but wait a moment
(define (display/slow x)
  (sleep .2)
  (display x))

; make a vector that says goodbye when freed
(define (make-polite-vector l v)
  (let ([ret (make-vector l v)])
(remember-to-say-goodbye ret)
ret))

;main program
(void (thread
   (lambda ()
 (for ([x (make-polite-vector 20 0)])
   (display/slow x))
 (for ([x (make-vector 20 1)])
   (display/slow x)

;--


On Wed, Dec 13, 2017 at 3:57 PM, David Storrs  wrote:
> Sorry, bumped 'send' by mistake
>
> Imagine I do this:
>
> (struct fruit (num))
> (define (foo) (make-list 1 (fruit 7)))
> (define (bar) (map (compose add1 fruit-num) (foo)))
>
> (submit-job! (thunk (bar)))
>
> I think that the above is roughly equivalent to doing this:
>
> (thread (thunk (bar) (sleep )))
>
> If I'm understanding things correctly, the structs that were created
> in (foo) will be up for garbage collection when (bar) exits, even
> though the worker thread continues to run.  Is that right?
>
> --
> 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] strange behaviour of procedure partitions

2017-11-12 Thread Gustavo Massaccesi
I can reproduce this error in
Welcome to DrRacket, version 6.11 [3m].
Language: racket [custom]; memory limit: 2048 MB.

but only if I use this configuration:

[X] No debugging or profiling

[   ] Populate compiled directories (I didn't try enabling this)
[??] Preserve stacktrace (error with or without this option)
[X] Enforce constant definitions

Gustavo



On Sun, Nov 12, 2017 at 6:57 PM, Jos Koot  wrote:
> I have downloaded and installed "Welcome to DrRacket, version
> 6.11.0.2--2017-11-12(b54ea8c5b1/a) [3m].",
> but the problem still remains.
> I have Windows 7 premium home.
> Thanks, Jos
>
> 
> From: Jens Axel Søgaard [mailto:jensa...@soegaard.net]
> Sent: zondag 12 november 2017 21:21
> To: Jos Koot; Racket Users
> Subject: Re: [racket-users] strange behaviour of procedure partitions
>
>
> søn. 12. nov. 2017 kl. 19.54 skrev Jos Koot :
>>
>> Hi
>>
>> In the definitions window of DrRacket:
>>
>> #lang racket
>> (require (only-in math/number-theory partitions))
>> (partitions 0)
>> (partitions 0)
>>
>> Runs ok,
>> but after running,
>> typing (partitions 0) in the interactions window
>> gives the following error:
>>
>> define-values: assignment disallowed;
>>  cannot re-define a constant
>>   constant: lifted.0
>
>
> Have you tried it in a version of Racket using the new expander?
>
> Just a hunch based on: https://github.com/racket/datalog/issues/6
>
>
>> The error does not show up when I comment out
>> the two lines (partitions 0) in the definitions window
>> and rerun before typing (partitions 0) in the interactions window.
>> I suppose this is a bug.
>>
>> The error does not occur when replacing
>> #lang racket
>> by
>> #lang typed/racket
>>
>> It is very well possible that I don't correctly require
>> from a typed module into an untyped one.
>> Should be possible, no?
>>
>> Thanks, Jos
>>
>> --
>> 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.
>
> --
> --
> 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.

-- 
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: Decision Tree in Racket - Performance

2017-07-27 Thread Gustavo Massaccesi
I was convinced that case-lambas were much slower.

I made some tests, but I replaced first/rest with car/cdr beause it's
much faster. Also I repeated the call 1000 times. I got almost 1/2
second of difference.

opt cpu time: 12266 real time: 12264 gc time: 0
acc cpu time: 11750 real time: 11745 gc time: 0
opt cpu time: 12266 real time: 12272 gc time: 0
acc cpu time: 11734 real time: 11737 gc time: 0
opt cpu time: 12250 real time: 12264 gc time: 0
acc cpu time: 11734 real time: 11749 gc time: 0

For comparison, if I divide the difference by 1000 I get 1/2
millisecond of difference. So the difference between the version with
and without an optional argument is something like 94.5 vs 94.0
(totally impossible to notice) instead of 281 vs 94 as I wrote in my
previous email.

Gustavo


On Thu, Jul 27, 2017 at 10:36 PM, Robby Findler
 wrote:
> `first` and `rest` need to check if the input is a list (a linear-time
> but memoized test), whereas `car` and `cdr` check only if the inputs
> are `pair?`s, and match-define uses unsafe operations, doing the pair
> check only once.
>
> I see from raco demod that match-define does not generate very
> beautiful code, which leads me to this version (which is what I think
> match-define should have expanded into). It seems to be about 4x
> faster on my computer.
>
> #lang racket
> (require racket/unsafe/ops)
> (define (as)
>   (build-list 100 (λ (n) (random 100
> (define (bs)
>   (build-list 100 (λ (n) (random 100
>
> (define (z as bs [acc 0])
>   (cond
> [(or (null? as) (null? bs))
>  acc]
> [else
>  (match-define (cons this-a more-as)
>as)
>  (match-define (cons this-b more-bs)
>bs)
>  (z more-as more-bs (+ acc (* this-a this-b)))]))
>
> (let ([as (as)]
>   [bs (bs)])
>   (collect-garbage)
>   (collect-garbage)
>   (collect-garbage)
>   (time (for ([i (in-range 10)])
>   (z as bs
>
> (define (z2 as bs [acc 0])
>   (cond
> [(or (null? as) (null? bs))
>  acc]
> [else
>  (define this-a (car as))
>  (define more-as (unsafe-cdr as))
>  (define this-b (car bs))
>  (define more-bs (unsafe-cdr bs))
>  (z2 more-as more-bs (+ acc (* this-a this-b)))]))
>
> (let ([as (as)]
>   [bs (bs)])
>   (collect-garbage)
>   (collect-garbage)
>   (collect-garbage)
>   (time (for ([i (in-range 10)])
>   (z2 as bs
>
>
>
> Robby
>
> On Thu, Jul 27, 2017 at 8:27 PM, Philip McGrath
>  wrote:
>> `match-define` seems to be the real source of the speedup for me:
>>
>> #lang racket
>>
>> (define (as)
>>   (build-list 100 (λ (n) (random 100
>> (define (bs)
>>   (build-list 100 (λ (n) (random 100
>>
>> (define (f as bs [acc 0])
>>   (if (or (null? as) (null? bs))
>>   acc
>>   (f (rest as) (rest bs) (+ acc (* (first as) (first bs))
>>
>> (let ([as (as)]
>>   [bs (bs)])
>>   (collect-garbage)
>>   (collect-garbage)
>>   (collect-garbage)
>>   (time (f as bs)))
>>
>>
>>
>> (define (g as bs)
>>   (let g ([as as]
>>   [bs bs]
>>   [acc 0])
>> (cond
>>   [(or (null? as) (null? bs))
>>acc]
>>   [else
>>(match-define (cons this-a more-as)
>>  as)
>>(match-define (cons this-b more-bs)
>>  bs)
>>(g more-as more-bs (+ acc (* this-a this-b)))])))
>>
>>
>> (let ([as (as)]
>>   [bs (bs)])
>>   (collect-garbage)
>>   (collect-garbage)
>>   (collect-garbage)
>>   (time (g as bs)))
>>
>> (collect-garbage)
>> (collect-garbage)
>> (collect-garbage)
>>
>> (define (z as bs [acc 0])
>>   (cond
>> [(or (null? as) (null? bs))
>>  acc]
>> [else
>>  (match-define (cons this-a more-as)
>>as)
>>  (match-define (cons this-b more-bs)
>>bs)
>>  (z more-as more-bs (+ acc (* this-a this-b)))]))
>>
>> (let ([as (as)]
>>   [bs (bs)])
>>   (collect-garbage)
>>   (collect-garbage)
>>   (collect-garbage)
>>   (time (z as bs)))
>>
>> ; timed at the command line
>> ;cpu time: 242 real time: 241 gc time: 0
>> ;2452993452
>> ;cpu time: 21 real time: 21 gc time: 0
>> ;2450414634
>> ;cpu time: 22 real time: 22 gc time: 0
>> ;2450010495
>>
>> -Philip
>>
>> On Thu, Jul 27, 2017 at 8:22 PM, Matthias Felleisen 
>> wrote:
>>>
>>>
>>> On Jul 27, 2017, at 9:18 PM, Matthew Flatt  wrote:
>>>
>>> I don't think optional arguments are all that slow.
>>>
>>>
>>>
>>> This isn’t just Matthew’s opinion. Vincent’s feature-specific profiler
>>> could not detect a significant impact of optional or keyword arguments. (See
>>> Compiler Construction paper, London 2014 I think)
>>>
>>> --
>>> 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 

Re: [racket-users] Re: Decision Tree in Racket - Performance

2017-07-27 Thread Gustavo Massaccesi
Functions with optional arguments are slow. They are expanded to a
case-lambda and an if. This version with an auxiliary function is
faster:


#lang racket

(define as (build-list 100 (λ (n) (random 100
(define bs (build-list 100 (λ (n) (random 100


(define (f/opt as bs [acc 0])
  (if (or (null? as) (null? bs))
  acc
  (f/opt (rest as) (rest bs) (+ acc (* (first as) (first bs))

(collect-garbage)
(collect-garbage)
(collect-garbage)
(time (f/opt as bs))


(define (f/acc as bs acc)
  (if (or (null? as) (null? bs))
  acc
  (f/acc (rest as) (rest bs) (+ acc (* (first as) (first bs))

(define (f/no-acc as bs acc)
  (f/acc as bs 0))

(collect-garbage)
(collect-garbage)
(collect-garbage)
(time (f/no-acc as bs 0))

;cpu time: 281 real time: 268 gc time: 0
;2447735069
;cpu time: 94 real time: 93 gc time: 0
;2447735069

Gustavo

On Thu, Jul 27, 2017 at 10:07 PM, Jon Zeppieri  wrote:
> You can get better performance out of the recursive function by using
> car/cdr instead of first/rest; first/rest require their arguments to
> be lists, whereas car/cdr require theirs to be pairs, which is a lot
> cheaper to check. Also, using an optional argument (in a loop,
> especially) makes a difference.
>
> Even so, for/sum wins, because it uses ops like unsafe-car and
> unsafe-cdr, which it can do safely, since it first establishes that
> it's working with a list (and then doesn't have to check again).
>
> - Jon
>
> On Thu, Jul 27, 2017 at 8:55 PM, Daniel Prager
>  wrote:
>> Revised to collect garbage before each timing shows the recursive function
>> isn't too bad (but not great):
>>
>> cpu time: 405 real time: 404 gc time: 0
>> 2452578471
>>
>> cpu time: 368 real time: 368 gc time: 0
>> 2452578471
>>
>> cpu time: 50 real time: 50 gc time: 0
>> 2452578471
>>
>> cpu time: 194 real time: 195 gc time: 75
>> 2452578471
>>
>>
>> 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.

-- 
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: Decision Tree in Racket - Performance

2017-07-27 Thread Gustavo Massaccesi
I agree with the in-list explanation, but I want to remark a few details.

>> I don't really understand the (in-list ...) thing. This seems to be internal 
>> magic to me.

`in-list` is not a function, it's a macro that looks like a function.
`for` is another macro (that doesn't look like a function). But in
Racket the macros are not just straightforward text substitution, they
can do a lot of things. Most are simple, but some macros are very
complex. For example `for` can examine some additional information
stored in `in-list` and write very efficient code. I.e. magic, a lot
of magic, but you can write your own magical `in-something`. The
details are in https://docs.racket-lang.org/reference/for.html but
it's not easy so I recommend reading it later after playing more with
the simple macros.

I looked at your solution with vectors. I think that vectors are not
slower than lists, moreover, they should be slightly faster, but
sometimes I guess wrong. The problem with your implementation is that
it creates a lot of intermediate lists. For example in
   (apply + (map (lambda (class-label) ...) class-labels)
The intermediate list must be allocated and free after use, the values
are scattered in memory so it may be slower to use them.

Also, the compiler can write more efficient code for the + in (+ x y)
than for the + in (apply + ...).

The solution of Daniel use (for/sum ...) instead of (apply + (map ...)).

There are a few places that can be rewritten. My recommendation for
fast code is to try to avoid allocations when possible.

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] Re: Decision Tree in Racket - Performance

2017-07-26 Thread Gustavo Massaccesi
I read the solution of Daniel Prager and I have a few minor changes.

* First I added a test that repeats `build-tree` 20 times, so the run
time is approximately 1-2 seconds. This is not necessary, but times
smaller than 1 second are sometimes not reliable. I'm using:
;---
(random-seed 12345)
(define data2 (shuffle banknote-data))
(time
 (void
  (build-tree (take data2 274) 5 10)))
(time
 (for ([i (in-range 20)])
   (build-tree (take data2 274) 5 10)))
;---



* Second I modified the split function so it is usable in Windows and
Linux. I'm using:
(string-split s #rx"\r?\n")
I'm almost sure this is not the best method to write portable code.
Any recommendation?



* The most important change is to add `in-list` everywhere, i.e. replace
(for/sum ([split splits])  ...)
with
(for/sum ([split (in-list splits)])  ...)

I'm not sure that all of them are necessary. The `for` clauses without
`in-list` are nice because they are very generic and can iterate over
a lot of different data types. The problem is that they create a
auxiliary sequence and use the methods of the sequence to iterate, so
they are slower than expected. If you use `in-list`, the `for` is
expanded to code that is specific to lists and is almost as efficient
as the hand coded version like (let loop ([l my-list]) ...) and
sometimes better.

Most of the times you can use the generic version and use the code
with any data type for free, but in the spots where you need fast code
remember to use in-range, in-list, in-vector, ... (For the version
that uses vectors for internal representation, you should probably use
in-vector. I didn't look at the code.)

Before this change a typical run time of the test is
   cpu time: 157 real time: 165 gc time: 0
   cpu time: 3390 real time: 3393 gc time: 63  (20 times)

After this change a typical run time of the test is
   cpu time: 62 real time: 61 gc time: 0
   cpu time: 1266 real time: 1277 gc time: 62 (20 times)

Gustavo

PS: I made a PR with these changes in github.

-- 
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] IO in racket is painful

2017-07-21 Thread Gustavo Massaccesi
IIRC the previous discussion, one way to fix this problem is to make a
package that can parse strings easily using a C like format, like the
expected in the contests. Something like

#lang racket
(require compatibility/scanf)

(let-values ([(x y) (scanf "%d %d" (read-line))])
  (display (+ x y)))

It's not very idiomatic, but it may be helpful for this particular use.

IIRC another problem is that in the contest you are not allowed to
install the packages you wish, you can only use the default
installation. But I think that the idea is not to allow everything in
the default installation.


So my proposal is to add another installation mode for Racket

* minimal: Only the core and some minimal packages
* main: The normal set of packages, (only idiomatic) batteries included.
* community (new): everything in the ring 1, including the kitchen
sink. With a minimal curation and a minimal baseline of features (like
no breaking the installation). (And a compatible license.) The
packages may disappear/change/reappear from version to version. All
the additional packages may be experimental/unstable/unsuported.

Is this acceptable in a competition?
Is this acceptable as another "official" Racket distribution?

Gustavo



On Fri, Jul 21, 2017 at 4:35 PM, Brian Mastenbrook
 wrote:
> On 07/21/2017 12:49 PM, Matthias Felleisen wrote:
>>
>>
>>> On Jul 21, 2017, at 1:56 AM, Sorawee Porncharoenwase
>>>  wrote:
>>>
>>> Sorry for reviving an old thread. As someone who did a lot of programming
>>> competition in the past, I can totally see why IO in Racket is difficult. As
>>> mark.engelberg said, the goal is to solve as many problems as possible.
>>> After the competition is over, it's over. No one is going to care about
>>> maintainability or good coding practice if it makes coding slower.
>>
>>
>> Which is why I think programming competitions are a direct attempt to
>> undermine computer science and computer-science education.
>>
>> Having said that, if you want to use Racket for competitions, you and Mark
>> Engelberg should get together and produce a high-utility IO library. We can
>> then include it in the distribution.
>
>
> Just as a counterpoint, I have this kind of ad-hoc parse-this-produce-that
> problem all the time in the "real" world. When the logic of the problem is
> sufficiently complex I'll swallow the overhead of doing it in Racket, or
> I'll use Perl to transform the input into something I can read in Racket. It
> would be nice to have an I/O library that made it easy, but I don't have any
> specific thoughts about how to do that.
>
> I don't think computer science education should ignore this kind of problem
> though. It's very important to teach students how to solve problems
> methodically with a design recipe, how to collaborate with others, and how
> to reason about their programs. But it's also important that programmers
> (and also or even especially those who don't program for a living) be
> comfortable with using the machine to solve or automate the solution to
> one-off problems that would otherwise require a lot of manual fiddling with
> data. Being fluent with this kind of programing gives people the confidence
> they need to solve smaller problems or explore potential solutions to large
> problems in an unstructured manner before tackling the methodical, "right"
> solution.
>
> --
> Brian Mastenbrook
> br...@mastenbrook.net
> https://brian.mastenbrook.net/
>
>
> --
> 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] R7RS implementation's installation

2017-06-27 Thread Gustavo Massaccesi
(Just guessing) Do you have a proxy in the university? Can you install
other packages that are not part of the main distribution, for example
https://pkgs.racket-lang.org/package/cond-strict ?

Gustavo

On Thu, Jun 22, 2017 at 6:44 PM, Jean-Michel HUFFLEN
 wrote:
>Dear Racket developers,
>
>On my personal computer, I successfully installed the package for the
> nonofficial implementation of R7RS in Racket.
>
>But I didn't this operation at my university, the answer is
>
> https://... proxy web incorrect address
>
>I searched the documentation but I don't see how I could fix this
> problem? Can someone help me? Many thanks in advance,
>
> J.-M. Hufflen
>
>
> 
> This message was sent using IMP, the Internet Messaging Program.
>
> --
> 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] intensional equality and unit tests

2017-02-21 Thread Gustavo Massaccesi
I'm not sure if this changed. To get a #t with equal? you can add
#:transparent . But be careful because #:transparent is more powerful
than what I expected. For example, it makes available the constructor
of the struct.


#lang racket

(define-struct foo (a b))
(make-foo 3 4)   ; ==> #
(equal? (make-foo 3 4)
(make-foo 3 4))  ; ==> #f

(define-struct foo/tr (a b) #:transparent)
(make-foo/tr 3 4); ==> #
(equal? (make-foo/tr 3 4)
(make-foo/tr 3 4))   ; ==> #t

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] Racket v6.8

2017-01-25 Thread Gustavo Massaccesi
Is it possible to offer to run the migrate process automatically
during the setup? I guess most users (i.e. me) expect and want it.

It would be also useful to check that the user had at least installed
one package in the previous version. For multiuser installations,
perhaps also offer to migrate the packages when DrRacket starts for
the first time.

Gustavo

On Wed, Jan 25, 2017 at 9:53 AM, Matthew Flatt  wrote:
> There's a `raco pkg migrate` command that should do what you want. The
> same functionality is in DrRacket's "File" -> "Package Manager..." ->
> "Copy from Version".
>
> At Wed, 25 Jan 2017 09:25:52 +0100, Konrad Hinsen wrote:
>> As with every new Racket release, I wonder if there is a straightforward
>> way to install all the packages I have installed under 6.7. Something like
>>
>>./6.8/raco pkg install `./6.7/raco pkg show -u`
>>
>> except that it 1) it works and 2) it handles packages from all sources,
>> not just the official catalog.
>>
>> I'll probably end up hacking something like that myself, but I wonder if
>> somebody has already done it?
>>
>> Konrad.
>
> --
> 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] Narrow radix of string->number.

2017-01-04 Thread Gustavo Massaccesi
I'm still worried about bignums. So I borrowed the idea of Mathew of
splitting the number in 1/2/3 digits chucks, but I use fixnum chunks.
For each fixnum chunk I calculate the string representation as usual,
but as most of the calculations involve only fixnum, then It's x4
faster for bignums.

It's slightly slower for the DrRacket distribution and fixnums and (5%-10%).

The code assumes that a 9 is a fixnum, this is true for 32 and
64 bit's racket. (In case Racket is ported in the future to a 16 bits
platform, the code is still correct but slower.)

DrRacket distribution of numbers
number->string cpu time: 4907 real time: 4898 gc time: 77
number->string* cpu time: 3703 real time: 3701 gc time: 0
number->string** cpu time: 6782 real time: 6777 gc time: 16
number->string*** cpu time: 3797 real time: 3796 gc time: 16

Always N=123 (10 times less calls)
number->string cpu time: 859 real time: 846 gc time: 0
number->string* cpu time: 1688 real time: 1676 gc time: 31
number->string** cpu time: 672 real time: 673 gc time: 0
number->string*** cpu time: 1796 real time: 1800 gc time: 0

Always N=1234567890123456789012345678901234567890 (10 times less calls)
number->string cpu time: 5625 real time: 5623 gc time: 0
number->string* cpu time: 102125 real time: 102100 gc time: 403
number->string** cpu time: 750 real time: 748 gc time: 15
number->string*** cpu time: 26343 real time: 26337 gc time: 95

Gustavo

;Here is ony the code of the new function and benchmarks
;I'm not happy with the names of the auxiliary functions.

(define (number->string***/fixed N short-size trim)
  (define str (make-string short-size #\0))
  (let loop ([N N] [i short-size])
(cond
  [(zero? N)
   (if trim
   (substring str i short-size)
   str)]
  [else
   (define q (quotient N 10))
   (define r (remainder N 10))
   (define d (integer->char (+ r (char->integer #\0
   (string-set! str (- i 1) d)
   (loop q (- i 1))])))

(define (number->string***/bignum/list N tail)
  (define-values (q r) (quotient/remainder N (expt 10 9)))
  (cond
[(zero? q)
 (cons (number->string***/fixed r 9 #t) tail)]
[else
 (number->string***/bignum/list q (cons (number->string***/fixed r
9 #f) tail))]))

(define (number->string*** N)
  (cond
[(fixnum? N)
 (cond
   [(< N 10)
(string (integer->char (+ (char->integer #\0) N)))]
   [(< N (expt 10 9))
(number->string***/fixed N 9 #t)]
   [else
(apply string-append (number->string***/bignum/list N '()))])]
[else
 (apply string-append (number->string***/bignum/list N '()))]))

;(define-syntax-rule (test-it id ...) ...)

(define iterations 5)

(define-syntax-rule (time-it id ...)
  (begin
(define numbers (for/list ([i (in-range 1000)])
  (sample/drr)))
(begin
  (collect-garbage)
  (time
   (for* ([x (in-range iterations)]
  [n (in-list numbers)])
 (id n))
   (printf "~a " 'id))) ...))

(time-it number->string number->string* number->string** number->string***)

(define-syntax-rule (time-it-N N id ...)
  (begin
(begin
  (collect-garbage)
  (time
   (for* ([x (in-range (* 100 iterations))])
 (id N))
   (printf "~a " 'id))) ...))

(time-it-N 123 number->string number->string* number->string**
number->string***)
(time-it-N 1234567890123456789012345678901234567890 number->string
number->string* number->string** number->string***)
;---


On Sun, Jan 1, 2017 at 8:01 PM, Robby Findler
 wrote:
> I'm skeptical of an unbounded cache.
>
> If we go by the sample from DrRacket's start up, then we don't really
> need a cache to do better than the built-in number->string. Below is
> some code that takes the version I had earlier with what I understood
> to be Gustavo's suggestions and then just does better on the fixnums
> between 0 and 9. I then changed the random inputs to sample from the
> distribution that DrRacket demonstrated and you won't be surprised to
> learn that this does better than having a cache. Below is the code.
>
> I also tried to collect the arguments to number->string during
> rebuilding all of the .zo files. Of the first 2.3 million calls about
> 99.5% of them were exact integers between 0 and 9 so probably this is
> the only optimization we need to do. (My sampling method turned out to
> be noisy, tho, but I don't think it affects the results.)
>
> ... unless someone comes up with some other benchmark or app we care about?
>
> Robby
>
> #lang racket
> (require (for-syntax syntax/parse))
>
> (define-syntax (mk-sample stx)
>   (syntax-parse stx
> [(_ (value:exact-nonnegative-integer
> occurrences:exact-nonnegative-integer) ...)
>  (define-values (cond-clauses count)
>(for/fold ([other-cases '()]
>   [so-far 0])
>  ([value (in-list (syntax->list #'(value ...)))]
>   [occurrences (in-list (syntax->list 

Re: [racket-users] Narrow radix of string->number.

2016-12-29 Thread Gustavo Massaccesi
I'm not too worried about a x4 slowdown in number->string because I
don't expect it to be in a tight loop, but it would be nice that it
were faster.

I made some tests. (You must change the 100 to number-to-convert in
your sample program.)

I made a new function number->string**, replacing
(define-values (q r) (quotient/remainder N 10))
with
(define q (quotientr N 10))
(define r (remainder N 10))

The problem is that quotient/remainder is very slow for fixnums (IIRC
it can be JIT-inlined).


I increased the number of iterations x10, so the run time is a few seconds:
(define iterations 1000) ; x10 of original number
(define number-to-convert 123)
cpu time: 1734 real time: 1740 gc time: 0   ;number->string
cpu time: 7234 real time: 7258 gc time: 0   ;number->string*
cpu time: 3578 real time: 3580 gc time: 31  ;number->string**

So the new function is only x2 times slower. Perhaps tweaking it for
fixnums can get a 10% or 20% increase of speed.


But for bignum the story is totally different. Here I used the
original number of iterations because everything is much slower.
(define iterations 100) ; original number
(define number-to-convert 1234567890123456789012345678901234567890)
cpu time: 1125 real time: 1128 gc time: 16   ;number->string
cpu time: 14828 real time: 14818 gc time: 94   ;number->string*
cpu time: 20735 real time: 20736 gc time: 222  ;number->string**

The new function is even slower. But both functions are very slow
(x15) in comparison with the C version.

(Note: To compare the times remember to consider the x10 factor in the
iterations, for example the run time of the original C function is
proportional to 1734 vs 11250, as expected it's faster for the
fixnum.)

Gustavo



On Wed, Dec 28, 2016 at 5:41 PM, Robby Findler
 wrote:
> I started with Ryan's code from `~r` and tried to emulate some special
> cases I see the C code (and didn't worry about negative numbers) and
> ended up with something 4-5x slower than the C code version. :(  Code
> follows.
>
> Robby
>
> #lang racket
> (define (number->string* N)
>   (cond [(zero? N)
>  (string #\0)]
> [else
>  (let* ([short-size 10]
> [str (make-string short-size)])
>(let loop ([N N] [digits null] [i short-size])
>  (cond
>[(zero? N)
> (if (<= i 0)
> (if (null? digits)
> str
> (string-append (apply string digits) str))
> (substring str i short-size))]
>[else
> (define-values (q r) (quotient/remainder N 10))
> (define d (integer->char (+ r (char->integer #\0
> (cond
>   [(<= i 0)
>(loop q (cons d digits) i)]
>   [else
>(string-set! str (- i 1) d)
>(loop q '() (- i 1))])])))]))
>
> (module+ test
>   (require rackunit)
>   (check-equal? (number->string* 1234567890987654321)
> (number->string 1234567890987654321))
>   (for ([x (in-range 1000)])
> (check-equal? (number->string* x )
>   (number->string x
>
> (define iterations 100)
> (define number-to-convert 123)
>
> (collect-garbage)
> (time
>  (for ([x (in-range iterations)])
>(number->string 100)))
>
> (collect-garbage)
> (time
>  (for ([x (in-range iterations)])
>(number->string* number-to-convert)))
>
> --
> 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] Narrow radix of string->number.

2016-12-27 Thread Gustavo Massaccesi
I think it better to extend the radix of `string->number` and
`number->string` to 2...36(inclusive) for now, and take more time to
think about bigger ranges.

I'm not sure about a good convention for a bigger radix, like 60.
(number->string 100 60 #:symbols '("01" "02" ... "59") #:separator ":")
(number->string 100 60 #:symbols "0123...9ABC...Zabc...z!\"#$%&/()=...")

Gustavo


By the way, the output of `number->string` for fractions is both
obvious and unexpected

(number->string (/ 1000 3) 8) ;=> "1750/3"
(number->string (/ 1 64) 8) ;=> "1/100"

I think it needs an explicit example in the documentation.


On Tue, Dec 27, 2016 at 6:57 PM, Robby Findler
 wrote:
> The main thing I worry about is that there are standard conventions
> that we're missing from other language families. Would someone mind
> investigating a few other, popular languages to see what they do so
> that can be taken into account? And perhaps pointing to the docs or
> showing some example code? (If we don't like what they do, we don't
> have to do it that way, but gratuitous difference seems unwise.)
>
> Robby
>
>
> On Tue, Dec 27, 2016 at 3:54 PM, Vincent St-Amour
>  wrote:
>> I don't see any reason why not, and it doesn't seem (by the discussion)
>> that anyone is strongly against.
>>
>> Would you be interested in submitting a pull request to extend
>> `string->number`? You'd probably want to extend `number->string` as
>> well, and possibly others.
>>
>> Vincent
>>
>>
>>
>> On Thu, 22 Dec 2016 05:51:06 -0500,
>> Dmitry Igrishin wrote:
>>>
>>> >> Why restricting it to 36?
>>> >
>>> >
>>> > I guess that the original poster implied 10 digits + 26 Latin letters for
>>> > notation.
>>> True. And this notation is used in standard numeric conversion
>>> functions in C, C++ and Common Lisp. So, I think it's reasonable to
>>> use it in Racket.
>>>
>>> --
>>> 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.
>
> --
> 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] Re: Operations that create objects

2016-12-16 Thread Gustavo Massaccesi
Two examples:

#lang racket

(define (create-function-that-show-number n)
  (display "*")
  (lambda ()
(displayln n)))

;Create the function
(define f7 (create-function-that-show-number 7))
;Use it
(displayln "Hello")
(f7)
(displayln "World!")

;---
;Something more complex

;Create and store the functions in a vector
(define v (vector (create-function-that-show-number 2)
  (create-function-that-show-number 1)
  (create-function-that-show-number 0)
  (create-function-that-show-number 6)))
;Select one of them at random
(define r (vector-ref v (random 4)))
;Use it
(r)

;Gustavo


On Fri, Dec 16, 2016 at 2:15 PM, Jan Hondebrink  wrote:
> Thank you so much. This is extremely helpful and instructive.
>
> One thing I don't understand: how do you call or access an inner function
> after its outer function has completed?
>
> On Fri, Dec 16, 2016 at 5:41 AM, George Neuner  wrote:
>>
>> On Thu, 15 Dec 2016 06:03:54 -0800 (PST), NeverTooOldToCode
>>  wrote:
>>
>> >Racket Reference section 1.1.5 states: "Operations that create
>> >objects, such as vector, add to the set of objects" followed
>> >by a nice and instructive step-by-step evaluation example.
>> >Further on, lambda is used as another example of an operation
>> >creating an object.
>> >
>> >How can I tell which operations create objects?
>>
>> It is safe to assume that most operations will create new objects.  If
>> you're just beginning to learn the language, it isn't something you
>> need to worry about yet.
>>
>>
>> Racket is in the Lisp family of languages: most types of data are
>> "boxed".  Boxed data is stored in an object on the heap, together with
>> a "tag" that describes the type of the data.  Variables in your
>> program will contain references (pointers) to boxed values.
>>
>> Racket does not distinguish between the boxed object and the reference
>> to it.  Any time you try to look at the reference, you see the data
>> inside the box instead.  In this way Racket is _not_ like other
>> languages in which pointers and/or references can examined and/or
>> manipulated separately.
>>
>> The above is a bit simplistic: some types like characters and small
>> integers are "immediate" - stored directly in variables (or list
>> nodes, array slots, structure fields, etc.).  But it is safe to assume
>> that *most* types of data will be an object on the heap.
>>
>>
>> When you get to the point of needing to optimize programs for speed,
>> Racket does offer typed vectors and arrays which store numeric values
>> unboxed.  There is also a typed version of Racket which tries to
>> eliminate boxing data as much as is possible.
>>
>>
>>
>> Explaining why lambda creates an object is a bit more complicated.
>>
>> Lisp family languages, including Racket, support the concept of
>> "nested" functions: in other words, they permit functions to be
>> declared inside the scope of other functions.
>> [If you're familar with Algol or Pascal, etc., in general the nested
>> functions in Racket will act very similarly.]
>>
>> Inner functions can access local variables of the outer functions that
>> enclose them.  This type of access is known as "non-global,
>> non-local", usually shortened in the literature to just "non-local".
>> It requires having a way to locate the variables that belong to the
>> enclosing functions.
>>
>> Now, Racket also is in the Scheme language family.  In Scheme,
>> functions are "1st class", which means that they may create and return
>> new functions, be stored in data structures, be passed as arguments to
>> other functions, etc.
>>
>> In particular, Scheme - and Racket - allows the creation of inner
>> functions that persist and can be called *after* their outer functions
>> have completed.
>>
>> Executing a function requires not just its code, but also external
>> data needed by the function: it's so-called "environment".  In many
>> languages, the environment consists only of global data and arguments
>> passed directly to the function - but the environment of an inner
>> function includes local variables of enclosing outer functions.
>>
>> If an inner function is to persist after its enclosing outer function
>> has completed, the local variables of the outer function must *also*
>> persist.
>>
>> To accomplish this, lambda creates an object called a "closure".  The
>> closure contains data defined by the outer function(s) that is needed
>> by the inner function, together with a pointer to the code of the
>> inner function.  The closure, being an object itself, can be
>> referenced by other data structures, passed as an argument, etc.
>>
>> Closures permit functions to have persistent private data.  By sharing
>> closures, multiple functions can share data without the data being
>> defined globally.
>>
>>
>> If this sounds quite like the objects in your favorite OO language ...
>> well, it *is*.  The major 

Re: [racket-users] Predictable random...so to say

2016-12-02 Thread Gustavo Massaccesi
I suggest to use the current-pseudo-random-generator, because otherwise the
shuffle/seed will change globally the random sequence of all the program.
For example:

;---
#lang racket

;; shuffle/seed : list? integer -> list?
(define (shuffle/seed lst seed)
  (random-seed seed)
  (shuffle lst))

(define a-list (list 1 2 3 4 5 6 7 8 9 10))

(shuffle/seed a-list 0) ;=> '(3 4 9 8 5 1 10 7 6 2)
(random) ;=> 0.5029567011201275
(shuffle/seed a-list 0) ;=> '(3 4 9 8 5 1 10 7 6 2)
(random) ;=> 0.5029567011201275
(shuffle/seed a-list 1) ;=> '(3 2 1 8 5 10 4 7 6 9)
(random) ;=> 0.1591727701267079
(shuffle/seed a-list 1) ;=> '(3 2 1 8 5 10 4 7 6 9)
(random) ;=> 0.1591727701267079

(define (shuffle/temp/seed lst seed)
  (parameterize ([current-pseudo-random-generator
(make-pseudo-random-generator)])
(random-seed seed)
(shuffle lst)))

(shuffle/temp/seed a-list 0) ;=> '(3 4 9 8 5 1 10 7 6 2)
(random) ;=> 0.9636171831359096 (may change)
(shuffle/temp/seed a-list 0) ;=> '(3 4 9 8 5 1 10 7 6 2)
(random) ;=> 0.6541579154005383 (may change)
(shuffle/temp/seed a-list 1) ;=> '(3 2 1 8 5 10 4 7 6 9)
(random) ;=> 0.679958229286436  (may change)
(shuffle/temp/seed a-list 1) ;=> '(3 2 1 8 5 10 4 7 6 9)
(random) ;=> 0.22302974490220356 (may change)
;---

[Note: shuffle/temp/seed is a horrible name. I used a different name to
avoid confusion.]

Gustavo



On Fri, Dec 2, 2016 at 5:37 AM,  wrote:

> Daniel Feltey  [16-12-02 09:28]:
> > I think something like this works:
> >
> > ;; shuffle/seed : list? integer -> list?
> > (define (shuffle/seed lst seed)
> >   (random-seed seed)
> >   (shuffle lst))
> >
> > > (define a-list (list 1 2 3 4 5 6 7 8 9 10))
> > > (shuffle/seed a-list 0)
> > '(3 4 9 8 5 1 10 7 6 2)
> > > (shuffle/seed a-list 0)
> > '(3 4 9 8 5 1 10 7 6 2)
> > > (shuffle/seed a-list 1)
> > '(3 2 1 8 5 10 4 7 6 9)
> > > (shuffle/seed a-list 1)
> > '(3 2 1 8 5 10 4 7 6 9)
> >
> >
> >
> > On Fri, Dec 2, 2016 at 2:05 AM,  wrote:
> >
> > > Hi,
> > >
> > > is there a racket function, which shuffles a list of items
> > > based on a seed value...that is: Same seed value results in
> > > same shuffle results?
> > >
> > > Cheers
> > > Meino
> > >
> > > --
> > > 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.
>
> HI Daniel,
>
> thanks a lot...exactly for what I have searched for!
>
> Cheers
> Meino
>
>
> --
> 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] a litle help

2016-11-16 Thread Gustavo Massaccesi
The program has a few errors.

For example,

* (define O ( X0 Y0 ))

should be something like

(define O (make-point X0 Y0))
(define O (point X0 Y0))
(define O (vector X0 Y0))

I'm not sure because the first two don't exist and I guess the last one is
not what you want, but you must change that line to

(define O (something X0 Y0))

* (* cos dT 30)

I guess it should be (* (cos 30) dT)

but you have to transform the 30 degrees to radians.

--

My suggestion is to try first with an easier exercise. Try to draw a
balloon that doesn't move. It's boring but the program is easier. Once you
understand all the details about the framework to draw the non moving
balloon, you can add the movement.

Gustavo


On Wed, Nov 16, 2016 at 6:54 AM, Masto Fine 
wrote:

>  (define (ballon-tourne)
> (local [(define LARG 110 )
> (define HAUT 110 )
> (define SCENE (carre 100 100 'outline "black"))
> (define BALLON ( circle 5 'solid "red"))
> (define X0 (/ LARG 2))
> (define Y0 (/ HAUT 2 ))
> (define O ( X0 Y0 ))
> (define M ( XM YM ))
> (define P ((+ X0 30) Y0))
> (define t (angle OP OM ))
> (define INIT 0)
> (define dT 5)
> (define (suivant t)
>   ((+ X0 (* cos dT 30)( - Y0 (* sin dT )
> (define (dessiner t)
>   (place-image BALLON ( (+ X0 ( * cos t 30))(- Y0 (*sin t)
> (define (final? t)
>(= t 700))]
>   (big-bang INIT
> (on-tick suivant)
> (on-draw dessiner)
> (stop-when final?can you correct 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.
>

-- 
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] Creating a list of random things

2016-10-26 Thread Gustavo Massaccesi
An additional example, I hope it's useful.

I think it's easy to explain if we replace (random) with a new
function (get-counter!) that instead of generating a random number, it
provides an increasing sequence.

#lang racket
(define secret-counter 0)
(define (get-counter!)
  (displayln "secret-counter increased")
  (set! secret-counter (add1 secret-counter))
  secret-counter)

(make-list 5 (get-counter!))  ;==> '(1 1 1 1 1)
(build-list 5 (lambda (ignored) (get-counter!)))  ;==> '(2 3 4 5 6)
(make-list 5 (get-counter!))  ;==> '(7 7 7 7 7)

In the first example, make-list is a function, so all the arguments
are evaluated before running the function. The result of
(get-counter!) is 1 so
   (make-list 5 (get-counter!))
is equivalent to
   (make-list 5 1)
so you get
   '(1 1 1 1 1)

In the second example, build-list is also a function, but the second
argument is an anonymous function instead of a simple value. So
build-list calls the anonymous function 5 time (each time with a
different argument that is ignored in this example).

In the third example, we use make-list again so (get-counter!) is
called only once again, but this time the value is 7 so the result is
the result of (make-list 5 7)

Gustavo



On Tue, Oct 25, 2016 at 11:47 PM, Ben Greenman
 wrote:
> Or:
>
> (build-list n (lambda (dont-care) (make-random-string)))
>
> On Tue, Oct 25, 2016 at 10:42 PM, Robby Findler
>  wrote:
>>
>> I would probably write that function like this:
>>
>> #lang racket
>>
>> (provide
>>  (contract-out
>>   [make-a-string (-> non-empty-string? string?)]))
>>
>> (define (make-a-string candidates)
>>   (apply
>>string
>>(for/list ([i (in-range (random 100))])
>>  (string-ref candidates (random (string-length candidates))
>>
>> (module+ test
>>   (require rackunit)
>>   (check-true (string? (make-a-string
>> "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
>>
>>
>> hth,
>> Robby
>>
>>
>> On Tue, Oct 25, 2016 at 9:39 PM,   wrote:
>> > Hi,
>> >
>> > I want to create a list of random strings.
>> > For that I have created a function, which returns a string
>> > of random length and random contents.
>> >
>> > Then I used
>> > make-list n (make-random-string)
>> >
>> > to create that listand get back a list filled with n
>> > identical strings.
>> >
>> > h...
>> >
>> > make-list calls make-random-string ones and the rest
>> > is repetition.
>> >
>> > If I think to have understood correctly for-loops and such are
>> > somehow of "imperative, non-functional old-school programming style"
>> > and map/apply and friends are the tools of the real racket programmer
>> > ;) this lead to a more general "problem" ("problem" only for a newbie
>> > like me may be)...:
>> >
>> > Since make-list calls its list-argument only once, the above does not
>> > work in the sense it is wanted, so make-list creates only lists of
>> > the same thing.
>> >
>> > Therefore to prevent "for" and friends, I have to call make-list
>> > with the empty list as list-argument and then map the
>> > make-random-string to each of them, which ensures that
>> > make-random-string is not called once.
>> > That feels ugly.
>> >
>> > What is a good "racket-ish" of "racket-y" way (nothing negative
>> > meant...just a play with words by someone, who is no native
>> > speaker...;) to do something n times without old-school
>> > for-and-friends-loops.
>> >
>> > Here is the code:
>> >
>> > #lang racket
>> > (require racket/random)
>> > (require racket/string)
>> >
>> > (define charseq "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" )
>> > (define minchars  7)
>> > (define maxchars 15)
>> > (define numlists 6)
>> >
>> > (define (make-random-string seq min max)
>> >   ( let ((lenstr (random min max)))
>> > ( apply string (random-sample seq lenstr
>> >
>> > (define (make-list-of-random-strings cnt seq min max )
>> >   (make-list cnt (make-random-string seq min max )))
>> >
>> > (define (make-list-of-lists numsublists)
>> >   ( make-list numsublists (make-list-of-random-strings numlists charseq
>> > minchars maxchars)))
>> >
>> > ( define (main)
>> >  (make-list-of-lists 20))
>> >
>> > (main)
>> >
>> > Any improvement is welcome!
>> >
>> > Cheers,
>> > Meino
>> >
>> >
>> >
>> > --
>> > 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.
>
>
> --
> You 

Re: [racket-users] Trouble with recursive lambda macros, using Y combinator

2016-09-11 Thread Gustavo Massaccesi
Just a comment about how to compare identifiers. In some cases, using
equal? and syntax-e gives the wrong result. It's better to use
free-identifier=? . For example, in this program we can use three
methods to compare identifiers (there are more!).

The program has two macros:

clasify-id: shows the result of three methods to compare identifiers.

show: it creates an unuseful temporal variable, and shows the value of
the "argument" and the value of the unuseful variable.

The problem is that that temporal variable is called temp, so it can
confuse the comparison methods because it has the same name that one
of the module level variables. But if free-identifier=? does a more
thoughtful comparison.

;---
#lang racket

(define-syntax (clasify-id stx)
  (syntax-case stx ()
[(_ x y)
 (begin
   (displayln
(list (equal? #'x #'y)
  (equal? (syntax-e #'x) (syntax-e #'y))
  (free-identifier=? #'x #'y)))
   #'(void))]))

(define-syntax (showln stx)
  (syntax-case stx ()
[(_ var)
 #'(let ([temp (random)])
 (displayln (list temp var))
 (clasify-id temp var))]))

(define x 5)
(define temp 5)

(clasify-id x temp)  ;==> (#f #f #f)
(clasify-id x x) ;==> (#F #t #t) <-- the first is wrong
(showln x)   ;==> (#f #f #f)
(showln temp);==> (#f #T #f) <-- the seccond is wrong
;---

Gustavo


On Sun, Sep 11, 2016 at 12:26 PM, Vasily Rybakov  wrote:
> Hi, gustavo!
>
> Thanks for your answer, it was very helpful.
>
> So i rewrote my (substitute-term) macro like this:
>
> (define-syntax (substitute-term stx)
>   (syntax-case stx ()
> [(_ term-from term-to (body0 body ...))
>  #`#,(append (if (equal? (syntax-e #'body0) (syntax-e #'term-from))
>  (list #'term-to)
>  (list #'body0))
>  #'((substitute-term term-from term-to body) ...))]
> [(_ term-from term-to body)
>  (if (equal? (syntax-e #'body)
>  (syntax-e #'term-from))
>  #'term-to
>  #'body)]))
>
> The (syntax-e) parts is kept because (equal? #'body #'term-from) won't yield 
> #t.
>
> Now it works:
>>(substitute-term and or (and #t #f))
> #t
>
> After a little bit tinkering I returned to (case) form, so it can substitute 
> not only single terms, but whole expressions:
>
> (define-syntax (substitute-syntax stx)
>   (syntax-case stx ()
> [(_ term-from term-to body)
>  (cond
>[(equal? (syntax->datum #'body) (syntax->datum #'term-from)) #'term-to]
>[(list? (syntax->datum #'body)) #`#,(append (if (equal? (syntax->datum 
> (car (syntax-e #'body)))
>(syntax->datum 
> #'term-from))
>(list #'term-to)
>(list #`#,(car 
> (syntax-e #'body
>(map (lambda (x)
>   (append (syntax-e 
> #'(substitute-syntax term-from term-to))
>   (list x)))
> (cdr (syntax-e 
> #'body]
>  [else #'body])]))
>
>>(substitute-syntax (and #t #f) or ((and #t #f) #f #t))
> Expands into (or #t #f)
> #t
>
> And my final version of recursion looks like this:
> (define-syntax recursion
>   (syntax-rules ()
> [(_ (args ...) body ...)
>  ((lambda (x) (x x))
>   (lambda (generated-label)
> (lambda (args ...)
>   (substitute-syntax recursion (generated-label generated-label) 
> body) ...)))]
> [(_ label (args ...) body ...)
>  ((lambda (x) (x x))
>   (lambda (label)
> (lambda (args ...)
>   (substitute-syntax label (label label) body) ...)))]))
>
> So it can be used without label, if there are no nested recursions:
>>((recursion (n)
> (if (zero? n)
> 1
> (* n (recursion (sub1 n) 5)
> 5
>
> Now it works, as intended.
>
> --
> 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] Trouble with recursive lambda macros, using Y combinator

2016-09-11 Thread Gustavo Massaccesi
In the first method, the problem is #%app
https://docs.racket-lang.org/reference/application.html?q=%23%25app
It's hidden by the default configuration of the macro stepper. Try
changing the configuration to show it.

The problem is that the expansion is:

(substitute-term and or (and #t #f))

---> first item is a macro, so apply it

((substitute-term and or and) (substitute-term and or #t)
(substitute-term and or #f))

--> first item is not a macro (it's only something that calls a
macro), so add #%app

(#%app (substitute-term and or and) (substitute-term and or #t)
(substitute-term and or #f))

--> first item is a especial form, so analyze the subexpressions

(#%app *(substitute-term and or and)* (substitute-term and or #t)
(substitute-term and or #f))

--> first item in the second subexpression is a macro, so apply it

(#%app or (substitute-term and or #t) (substitute-term and or #f))

--> no surprises in the other subexpressiosn, I'll skip the repetitive steps

(#%app or #t #f)

--> now everything is expanded, so #%app want's to call the function
that is the first argument, but it's a macro instead of a function.
--> error



To fix it, I think it's necessary that substitute-term does more work,
and tries to replace the first expression directly instead of using
recursion.

(substitute-term and or (and #t #f))

---> first item is a macro, so apply it

(and (substitute-term and or #t) (substitute-term and or #f))

where in the first position, the or->and is replaced directly. I also
think this will be easier if you use syntax-case instead of case and
syntax-e.


 

 The problem with the second method is in the line

 (datum->syntax stx (for-substitute-term (syntax->datum #'term-from)
(syntax->datum #'term-to) (syntax->datum #'body)))

This is unhygienic because in the substitution all the
marks/scopes/whatever are lost.

In this case, when #'body is n, the n is not a plain n, is an n that
has a scope that says that it's the argument of the function. When the
macro applies (syntax->datum #'body) then the result is the symbol 'n
without additional information, it's almost a like string of text.
Later when the macro calls (datum->syntax stx (...)) then the symbol
'n get the scopes from the syntax, that are probably the wrong scopes,
so the result is not the n that is the argument of the function but
another n, perhaps the toplevel n that should be defined in the
module.

This explanation is very very very confusing. I'm confused. I'm not
even sure it's 100% accurate, but the general idea is right. Anyway,
the takeaway is "Don't do it". Or to be more precise, only
try this after studding carefully about the hygiene system.

Gustavo





On Sun, Sep 11, 2016 at 12:54 AM, Vasily Rybakov  wrote:
> Hi!
>
> I'm learning Racket and I stumpbled into a couple of problems with macros.
>
> I tried to make macros that implements recursive lambda, but not the classic 
> one (that uses letre), but the one that uses Y combinator.
>
> So it should work like this:
>
> (recursion fact (n)
> (if (zero? n)
> 1
> (* n (fact (sub1 n)
>
> transforms into
>
> ((lambda (x) (x x))
> (lambda (fact)
>   (lambda (n)
>  (if (zero? n) 1 (* n ((fact fact) (sub1 n)))
>
> which produces recursive anonymous function to compute factorial.
>
> So I wrote this macros:
>
> (define-syntax recursion
>   (syntax-rules ()
> [(_ label (args ...) body ...)
>  ((lambda (x) (x x))
>   (lambda (label)
> (lambda (args ...)
>   (substitute-term label (label label) body) ...)))]))
>
> (substitute-term) macros is helper macros to substitute one piece of code 
> with another, here its fist version:
>
> (define-syntax (substitute-term stx)
>   (syntax-case stx ()
> [(_ term-from term-to body)
>(cond
>  [(null? (syntax-e #'body)) #'(void)]
>  [(list? (syntax-e #'body)) #`#,(map (lambda (x) (append (syntax-e 
> #'(substitute-term term-from term-to)) (if (list? x) x (list x (syntax-e 
> #'body))]
>  [else (if (equal? (syntax-e #'body) (syntax-e #'term-from)) 
> #'term-to #'body)])]))
>
>>(substitute-term - + (- 1 2))
> 3
>
> This works. But
>
>>(substitute-term and or (and #t #f))
> or: bad syntax in: or
>
> Macro stepper shows that it expands into
>
> (or (substitute-term and or #t) (substitute-term and or #f))
>
> And after this step is "bad syntax" error. I couldn't figure why is this and 
> how to fix it. It raises "bad syntax" errors with all special forms for some 
> reason. Can somebody explain to me -- why? And how to fix it?
>
> Then I tried rewrite (substitute-term) macro:
>
> (define-syntax (substitute-term-2 stx)
>   (syntax-case stx ()
> [(substitute-term term-from term-to body)
>  (datum->syntax stx (for-substitute-term (syntax->datum #'term-from) 
> (syntax->datum #'term-to) (syntax->datum #'body)))]))
>
> It uses helper function (define-for-syntax) 

Re: [racket-users] Re: lambda and the equivalent define / "defun"

2016-09-04 Thread Gustavo Massaccesi
I hope these examples are enough to help with your problem:

;--
#lang racket
(define (negative . s)
  (map - s))
(negative 1 2 3 -4) ; ==> '(-1 -2 -3 4)

(define (multiply-by n . s)
  (map (lambda (x) (* n x)) s))
(multiply-by 5 1 2 3) ; ==> '(5 10 15)

(define (count . s)
  (length s))
(count 1 2 3 1 2 3) ; ==> 6
;--

Gustavo


On Sun, Sep 4, 2016 at 2:36 PM, Sanjeev Sharma  wrote:
> two "x" 's also work
>
> (define list (lambda x x))
>
> --
> 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] Do I need a critical section here ... and if so, how to?

2016-09-01 Thread Gustavo Massaccesi
What about box-cas! ?
https://docs.racket-lang.org/reference/boxes.html#%28def._%28%28quote._~23~25kernel%29._box-cas%21%29%29

Something like:
;---

#lang racket
(define handle-counter (box 1))
(define (new-handle)
  (define old (unbox handle-counter))
  (define new (add1 old))
  (unless (box-cas! handle-counter old new)
(new-handle))
  old); or new ?
;---

Gustavo



On Thu, Sep 1, 2016 at 6:44 AM, Erich Rast  wrote:
> This question is also about style. Take an admittedly ugly
> counter like this
>
> ;; increasing counter for handles
> (define handle-counter 1)
>
> (define (new-handle)
>   (begin0
> handle-counter
> (set! handle-counter (add1 handle-counter
>
> Various threads may call (new-handle) concurrently, so I need to
> ensure that every thread gets a unique handle. However, the handles need
> not reflect the temporal order of the calling sequence in any way. It's
> hard to debug but I believe I've seen a case in which the above code
> has assigned the same handle to concurrent threads, as one would expect.
>
> So basically new-handle needs to be in a critical section, right? I feel
> stupid that I don't know the answer, but how do I do this?
>
> In the docs I've found ffi/unsafe/atomic, but this seems like overkill
> and is unsafe and only intended for the FFI.
>
> Second question: Should I use a parameter or something else for this
> construct, and if so, what are the benefits of doing so? What would be
> the 'right' way of providing unique numbers in a synchronized way?
>
> Best,
>
> Erich
>
> --
> 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] Help needed in file processing idioms

2016-08-19 Thread Gustavo Massaccesi
Minor fix: In the first function "read-on-row" you must replace
for/first with for/last.

Gustavo

PS for Pekka: In this case it's better to use for/last and for/or, but
in more complicated cases you can try with for/fold.


On Fri, Aug 19, 2016 at 10:34 AM, WarGrey Gyoudmon Ju
 wrote:
> (define (read-on-row *params*)
>   ;; Returns the last line in "myfile" which contains
>   ;; substring "ON", otherwise #f
>   (call-with-input-file (hash-ref *params* "myfile")
> (lambda (inp)
>   (for/first ([row (in-lines inp 'return-linefeed)]
>   #:when (string-contains? row "ON"))
>  row
>
> (define (on-row-exists *params*)
>   ;; Returns #t if there is line in "myfile" which contains
>   ;; substring "ON", otherwise #f
>   (call-with-input-file (hash-ref *params* "myfile")
> (lambda (inp)
>   (for/or ([row (in-lines inp 'return-linefeed)])
>   (string-contains? row "ON")
>
>
> On Fri, Aug 19, 2016 at 9:18 PM, Pekka Niiranen 
> wrote:
>>
>> Hello users,
>>
>> I would like to read lines from a file, process each line
>> and return either the success of the operation or the processed line to
>> another function located in another module.
>>
>> Below are two functions that work OK, but are in my opinion "ugly" because
>> they use "set!".
>>
>> It there a way to make both functions work without "set!"?
>>
>>
>> ;;
>> (define (read-on-row *params*)
>> ;; Returns the last line in "myfile" which contains
>> ;; substring "ON", otherwise #f
>>
>>   (define pdata #f) ;; I do not like this extra variable!
>>
>>   (call-with-input-file (hash-ref *params* "myfile")
>> (lambda (inp)
>>   (for/last ([row (in-lines inp 'return-linefeed)]
>>  #:when (string-contains? "ON" row))
>> (set! pdata row
>>
>>   pdata)
>>
>> ;;
>>
>> (define (on-row-exists *params*)
>> ;; Returns #t if there is line in "myfile" which contains
>> ;; substring "ON", otherwise #f
>>
>>   (define found-on #f) ;; I do not like this extra variable!
>>
>>   (call-with-input-file (hash-ref *params* "myfile")
>> (lambda (inp)
>>   (for/last ([row (in-lines inp 'return-linefeed)]
>>  #:when (string-contains? "ON" row))
>> (set! found-on #t
>>
>>   found-on)
>>
>> -pekka-
>>
>>
>> --
>> 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.

-- 
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: Time of hash-ref when the key is (not) found

2016-08-12 Thread Gustavo Massaccesi
Ok. To reproduce the results I have to use:
  (define char (integer->char 37932))

Thank to both.

Gustavo


On Fri, Aug 12, 2016 at 7:08 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:
> That still seems consistent with Alex's explanation. To test Alex's
> explanation, I think you need a hash table with a key whose hash code
> matches the one for the value you check, but where the key is not equal
> that value.
>
> Here's a variant of your code with a `bignum` and `char` that have the
> same hash code, and `other` with a different hash code. The fastest
> case is the last one, where there's no match on hash code. The slowest
> case in the second one, where there's a match on the hash code but the
> values are not `equal?`. The matching case is in between.
>
>
> #lang racket/base
>
> ;; These two have the same `equal?` hash code internally:
> (define bignum (expt 2 64))
> (define char (integer->char 4164))
>
> ;; Has a different hash code:
> (define other 0)
>
> (define hash-with-bignum (hash bignum #t))
> (define hash-with-char (hash char #t))
> (define hash-with-other (hash other #t))
>
> (for ([rep (in-range 5)])
>   (display "found: ")
>   (time
>(for ([i (in-range 1000)])
>  (hash-ref hash-with-bignum bignum #f))
>(void))
>
>   (display "not found, but hash code found: ")
>   (time
>(for ([i (in-range 1000)])
>  (hash-ref hash-with-char bignum #f))
>(void))
>
>   (display "hash code not found: ")
>   (time
>(for ([i (in-range 1000)])
>  (hash-ref hash-with-other bignum #f))
>(void))
>   )
>
> At Fri, 12 Aug 2016 17:27:29 -0300, Gustavo Massaccesi wrote:
>> I think it's something more subtle. With this definitions:
>>
>>  (define long-assoc (for/list ([i (in-range 64 (+ 64 1024))])
>>   (cons i #t)))
>>  (define hash0 (make-immutable-hash (cons '(0 . #t) long-assoc)))
>>  (define hash1 (make-immutable-hash (cons '(1 . #t) long-assoc)))
>>
>> With 5 repetitions I get:
>>
>> h0: average 3872 +- 30
>> h1: average 2511 +- 22
>>
>> I get similar results replacing 1024 with other numbers. For example
>> with 1048576 both times increase, but the difference is still there.
>>
>> Gustavo
>>
>>
>> On Fri, Aug 12, 2016 at 12:17 AM, Alex Harsanyi <alexharsa...@gmail.com> 
>> wrote:
>> > On Friday, August 12, 2016 at 10:09:21 AM UTC+8, gustavo wrote:
>> >> 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
>> >
>> > The "found case" probably has the following 3 steps:
>> >
>> > 1. compute hash value of the lookup key (0 in your case)
>> > 2. locate the bucket for that hash value
>> > 3. compare the value 

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

2016-08-12 Thread Gustavo Massaccesi
I think it's something more subtle. With this definitions:

 (define long-assoc (for/list ([i (in-range 64 (+ 64 1024))])
  (cons i #t)))
 (define hash0 (make-immutable-hash (cons '(0 . #t) long-assoc)))
 (define hash1 (make-immutable-hash (cons '(1 . #t) long-assoc)))

With 5 repetitions I get:

h0: average 3872 +- 30
h1: average 2511 +- 22

I get similar results replacing 1024 with other numbers. For example
with 1048576 both times increase, but the difference is still there.

Gustavo


On Fri, Aug 12, 2016 at 12:17 AM, Alex Harsanyi  wrote:
> On Friday, August 12, 2016 at 10:09:21 AM UTC+8, gustavo wrote:
>> 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
>
> The "found case" probably has the following 3 steps:
>
> 1. compute hash value of the lookup key (0 in your case)
> 2. locate the bucket for that hash value
> 3. compare the value 0 against the first value in the bucket => *found*
>
> Well, the "not found" case probably has the following 2 steps:
>
> 1. compute hash value of the lookup key (0 in your case)
> 2. locate the bucket for that hash value => *not found*
>
> So there is less work to do in the "not found" case.
>
> I suspect if you looked up a value that hashes to the same bucket as the 
> value 0, you would get the same time for the "not found" case.
>
> A better test is to use a hash with lots of keys, and I'm not sure what lots 
> mean here.
>
> Best Regards,
> Alex.
>
> --
> 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] 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] Case vs. Match

2016-06-04 Thread Gustavo Massaccesi
Oh! More fancy that what I expected (link
https://github.com/racket/racket/blob/master/racket/collects/racket/private/case.rkt
 )

It separates the items by type, and to trigger most of the special
cases it requires at lest 10/12 of each.

Another example, with many special cases:
#lang racket
 (syntax->datum
  (expand
   #'(case x
   [(11 12 13 14 1000 a b c d "a" "b" "c" "d") 100]
   [(15 16 17 18 2000 e f g h "e" "f" "g" "h") 200]
   [(19 20 21 22 3000 i j k l "i" "j" "k" "l") 300])))

Gustavo




On Fri, Jun 3, 2016 at 8:38 PM, Robby Findler
<ro...@eecs.northwestern.edu> wrote:
> Really this is not the best example either. I guess best to look at
> the source, which is in racket/private/case and, according to a
> comment in the top of the file, is based on  Clinger's paper, "Rapid
> Case Dispatch in Scheme".
>
> Robby
>
> On Fri, Jun 3, 2016 at 6:35 PM, Robby Findler
> <ro...@eecs.northwestern.edu> wrote:
>> I think they need to be bigger, but case does have some smarts. Try
>> this one (add a `pretty-write` if you're running in cmd-line racket).
>>
>> #lang racket
>> (syntax->datum
>>  (expand
>>   #'(case x
>>   [(1 2 3 4 5 6 7 8 9 10) 1]
>>   [(a b c d e f g h i j k l m n o p q r s t) 2])))
>>
>>
>> On Fri, Jun 3, 2016 at 6:23 PM, Gustavo Massaccesi <gust...@oma.org.ar> 
>> wrote:
>>>  > [...] I saw in the docs that case specifically mentions it can
>>> distribute in log(n) time [...]
>>>
>>> I think it's strange. I found the reference in
>>> https://docs.racket-lang.org/reference/case.html but it's very
>>> strange. Is it true???
>>>
>>> For example, I tried with
>>>
>>> ;---
>>> #lang racket
>>> (lambda (x)
>>>   (case x
>>> [(1 "1" #"1" |1|) 1]
>>> [(2 "2" #"2" |2|) 2]))
>>> (lambda (x)
>>>   (case x
>>> [(1 3 5 7) 1]
>>> [(2 4 6 8) 2]))
>>> ;---
>>>
>>> but both expand to a bunch of nested if, nothing fancy that may run in
>>> O(log(N)).
>>> (I don't expect that it has a smarter implementation for bigger N.)
>>>
>>> Gustavo
>>>
>>>
>>> On Fri, Jun 3, 2016 at 11:40 AM, Gerald Pipes
>>> <gerald_pi...@student.uml.edu> wrote:
>>>> On Friday, June 3, 2016 at 10:30:35 AM UTC-4, Jon Zeppieri wrote:
>>>>> There's rarely a good reason. If you were dispatching over a very large 
>>>>> set of constants -- fixnums or characters, in particular -- I'd expect 
>>>>> better performance from case. That's about it.
>>>>>
>>>>> > On Jun 3, 2016, at 10:10 AM, Gerald Pipes 
>>>>> > <gerald_pi...@student.uml.edu> wrote:
>>>>> >
>>>>> > I have been recently using match a lot and I was wondering what was the 
>>>>> > main benefit of using case instead of match?  It seems as though match 
>>>>> > has the distribution on a single val-exp except match allows for the 
>>>>> > pattern matching and case just uses equal?.
>>>>> >
>>>>> > --
>>>>> > 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.
>>>>
>>>> Yes, I saw in the docs that case specifically mentions it can distribute 
>>>> in log(n) time but for match there is no time mentioned. I assumed case's 
>>>> performance was better because of the performance omission of match. Does 
>>>> anyone know the actual performance of match?
>>>>
>>>> --
>>>> 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.

-- 
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] Case vs. Match

2016-06-03 Thread Gustavo Massaccesi
 > [...] I saw in the docs that case specifically mentions it can
distribute in log(n) time [...]

I think it's strange. I found the reference in
https://docs.racket-lang.org/reference/case.html but it's very
strange. Is it true???

For example, I tried with

;---
#lang racket
(lambda (x)
  (case x
[(1 "1" #"1" |1|) 1]
[(2 "2" #"2" |2|) 2]))
(lambda (x)
  (case x
[(1 3 5 7) 1]
[(2 4 6 8) 2]))
;---

but both expand to a bunch of nested if, nothing fancy that may run in
O(log(N)).
(I don't expect that it has a smarter implementation for bigger N.)

Gustavo


On Fri, Jun 3, 2016 at 11:40 AM, Gerald Pipes
 wrote:
> On Friday, June 3, 2016 at 10:30:35 AM UTC-4, Jon Zeppieri wrote:
>> There's rarely a good reason. If you were dispatching over a very large set 
>> of constants -- fixnums or characters, in particular -- I'd expect better 
>> performance from case. That's about it.
>>
>> > On Jun 3, 2016, at 10:10 AM, Gerald Pipes  
>> > wrote:
>> >
>> > I have been recently using match a lot and I was wondering what was the 
>> > main benefit of using case instead of match?  It seems as though match has 
>> > the distribution on a single val-exp except match allows for the pattern 
>> > matching and case just uses equal?.
>> >
>> > --
>> > 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.
>
> Yes, I saw in the docs that case specifically mentions it can distribute in 
> log(n) time but for match there is no time mentioned. I assumed case's 
> performance was better because of the performance omission of match. Does 
> anyone know the actual performance of match?
>
> --
> 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] Compiler question

2016-04-30 Thread Gustavo Massaccesi
> I tend to favor ((if x y z) foo) over (if x (y foo) (z foo)) because it avoids
> redundancy and localizes the choice. Apparently, that's a pessimising
> choice and I now don't feel like I have much intuition at all about how
> things will perform.


My recommendation is to write nice code, unless you are writing a hot
spot that is critical for the application. 99% of the time the program
is just waiting for user input or read data from the disk or
something, so write nice and idiomatic code that is easy to maintain.



*IF* you really need speed, try to avoid "((whatever) ...)". In many
situations, the optimizer can rewrite it under the hood. For example
((let (...) ... z) ...) is rewritten to (let (...) ... (z ...)), so
they are equivalent after optimizations. The second expression has
many advantages:

- If z is a Racket primitive, then the function z can use the JIT
implementation, that is faster that the C implementation. Also, some
of the primitives can be reduced at compile time, for example (list?
x) can be reduced to #t or #f if the optimizer can figure out the type
of x.

- If z is defined in Racket with a lambda, then the optimizer may
inline it. So it will avoid the function call, and the constants can
be propagated and many internal expressions can be reduced. If it's a
recursive functions, it may be inlined a few times, that has a similar
effect of a loop unrolling. (I think this is what is happening in your
example.)


The problem with ((if X Y Z) a b c) is that it's more complicated.
It's not possible to reduce it automatically to (if X (Y a b c) (Z a b
c)) because a, b or c may be big expressions and this will duplicate a
lot of code, or produce wrong results if one of them is something like
'(1 2 3).

An alternative os to reduce it to
  (let ([X_ X] [a_ a] [b_ b] [c_ c])
(if X_ (Y a_ b_ c_) (Z a_ b_ c_))
but this only is correct if Y and Z are simple expressions, for
example Y may be a mutable variable that is changed in c, or Y may be
an expression that changes the value of c, or ...

But I think that there are a few easy usual cases of ((if ...) ...)
that can be reduced. I have to think about them to try to get most of
them and don't forget any of the corner cases that are incorrect.


For now, *IF* you need speed, then check the details by hand and use
(if X (Y a b c) (Z a b c)), but perhaps in a future version of Racket
this optimization can be automatic.

Gustavo

PS: Another general recommendation: Try to avoid set!, because most of
the optimizations are disabled for mutable variables.

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


Re: [racket-users] Re: (eqv? Racket-land Wonderland) -> #t

2016-02-15 Thread Gustavo Massaccesi
On Mon, Feb 15, 2016 at 6:26 AM, Saša Janiška  wrote:
> "Jos Koot"  writes:
>
> Hello Jos,
>
>> I am a Racket-using hobbyist. It surprises me that, according to the
>> observation, not many hobbyists are using Racket.
>
> Seeing so much proliferation of JS crap it looks like people are really
> going insane. :-)
>

One advantage of JS is tht you can run it in every browser in every
computer in the word.

But it has a few disadvantages, so someone adds a thin wrapper to
improve some details and fix incompatibilities between browsers. Then
the wrapper gets more features, until it's contains an ad hoc,
informally-specified, bug-ridden, slow implementation of half of
Common Lisp^H^H^H^H^H^H^H^H Racket.

Part of the solution may be to get a Racket to JavaScript compiler. I
think there are two or three projects, with different advance level.

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] DrRacket Coverage

2016-02-14 Thread Gustavo Massaccesi
I guess painting everything black is more confusing, because black is
used to mark the uncovered parts. The students will think that
everything is wrong.

I think that a better possibility is to add a backcolor (and
forecolor) to the code covered by the test. I vote for very light
green,  #C0FFC0, because green usually means ok. So each time they add
more test, they will get more green background until everything is
green.

Gustavo

On Sun, Feb 14, 2016 at 7:25 PM, Robby Findler
 wrote:
> Since in that context test coverage is an opt-in kind of a thing,
> maybe it makes sense to just make the whole thing turn black? Do you
> think that would also solve the problem?
>
> Robby
>
>
> On Sun, Feb 14, 2016 at 4:10 PM, Eli Barzilay  wrote:
>> On Sun, Feb 14, 2016 at 5:06 PM, Robby Findler
>>  wrote:
>>> Can you explain the use case a little bit more, please? This is the
>>> *SL languages?
>>
>> No, a plain #lang with the syntactic code coverage enabled.
>>
>>
>>> They run their program, they see black/orange, they add tests, they no
>>> longer see black/orange, and they are confused?
>>
>> Yes exactly -- and that's after I mention it in class and describe it in
>> the course pages.
>>
>>
>>> Did they not understand what black/orange means or were they expecting
>>> entirely black?
>>
>> I think that by the time they work hard to cover everything and the
>> coverage colors disappear they quickly jump to a conclusion that
>> something is wrong.  -- I even have the server report to them about
>> uncovered code, but even that doesn't help.
>>
>> In case it wasn't clear -- this is not too important, just something
>> that strikes me as weird every time another student gets confused.
>>
>> --
>> ((x=>x(x))(x=>x(x)))   Eli Barzilay:
>> http://barzilay.org/   Maze is Life!
>
> --
> 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] Chaperone of immutable hash

2016-02-14 Thread Gustavo Massaccesi
Thanks to both. I searched by mistake "make-chaperone-hash" instead of
"chaperone-hash", so I didn't find it.

Gustavo

On Sat, Feb 13, 2016 at 7:11 PM, Stephen Chang <stch...@ccs.neu.edu> wrote:
> I added similar basic tests here.
>
> https://github.com/racket/racket/blob/master/pkgs/racket-test-core/tests/racket/hash.rktl
>
> On Feb 13, 2016 4:12 PM, "Robby Findler" <ro...@eecs.northwestern.edu>
> wrote:
>>
>> I think this is what you want?
>>
>> (chaperone-hash
>>  (hash)
>>  (λ (h key) (values key (λ (h key val) val)))
>>  (λ (h key val) (values key val))
>>  (λ (h key) key)
>>  (λ (h key) key)
>>  (λ (hash) 'okay)
>>  (λ (hash key) key))
>>
>>
>>
>>
>> On Sat, Feb 13, 2016 at 3:02 PM, Gustavo Massaccesi <gust...@oma.org.ar>
>> wrote:
>> > I want to make a test with a chaperone of an immutable hash, but the
>> > signature of make-chaperone-hash has too many parts.
>> >
>> > Do anyone have an example of use of make-chaperone-hash. If possible,
>> > the chaperone that does nothing, only forward the values.
>> >
>> > 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.
>>
>> --
>> 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] building openwrt .ipk for racket

2016-02-13 Thread Gustavo Massaccesi
The scripts are slightly different. Is it necessary or it' enough to
change the version and md5?

Gustavo


On Fri, Feb 12, 2016 at 11:36 PM, Neil Van Dyke  wrote:
> I dumped onto the Web the files I used to build OpenWrt packages for Racket:
> http://www.neilvandyke.org/racket-openwrt/
>
> Neil V.
>
> --
> 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] Chaperone of immutable hash

2016-02-13 Thread Gustavo Massaccesi
I want to make a test with a chaperone of an immutable hash, but the
signature of make-chaperone-hash has too many parts.

Do anyone have an example of use of make-chaperone-hash. If possible,
the chaperone that does nothing, only forward the values.

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] macro stepper

2016-02-11 Thread Gustavo Massaccesi
I've seen similar errors many times too (perhaps it's more common in
my machine that is slow and has windows ...)

Once I tracked it, but I never got enough details to fix it. It was a
few months ago, ... Perhaps it was another error,  In case this is
useful ...

IIRC the problem is that two threads try to unlock-modify-lock the
editor. There is some wrapper that saves and restore the lock state.
The idea is that this work:

unlock1-modify1-unlock2-modify2-lock2-modify1-lock1

As unlock2 sees that the editor is already unlocked, lock2 does not
lock the editor and modify1 is ok

For some reason, sometimes this is executed as

unlock1-modify1-unlock2-modify1-lock1-modify2-lock2

As unlock1 sees that the editor is locked, lock1 locks the editor and
modify2 generates an error.

Gustavo


On Thu, Feb 11, 2016 at 1:37 PM, Scott Moore  wrote:
> Yes, around 80% of the time if I disable macro hiding, and sometimes even
> with macro hiding if I’m moving back and forth through a long sequence of
> steps.
>
> I had been meaning to file a report...
>
> On February 11, 2016 at 11:27:21 AM, Matthias Felleisen
> (matth...@ccs.neu.edu) wrote:
>
>
> ... has anyone seen this error message from stepping thru macros:
>
> [:~/svn/2HtDP] matthias% sequence-contract-violation: negative: method
> set-max-width cannot be called, except in states (unlocked write-lock), args
> 834
> context...:
> /Users/matthias/plt/racket/collects/racket/private/more-scheme.rkt:148:2:
> call-with-break-parameterization
> /Users/matthias/plt/racket/share/pkgs/gui-lib/mred/private/lock.rkt:43:38
> /Users/matthias/plt/racket/collects/racket/private/more-scheme.rkt:265:2:
> call-with-exception-handler
> /Users/matthias/plt/racket/share/pkgs/gui-lib/mred/private/wxme/text.rkt:766:2:
> end-edit-sequence method in text%
> /Users/matthias/plt/racket/share/pkgs/macro-debugger/macro-debugger/view/stepper.rkt:438:4:
> update* method in macro-stepper-widget%
> /Users/matthias/plt/racket/share/pkgs/macro-debugger/macro-debugger/view/stepper.rkt:400:31
> .../more-scheme.rkt:261:28
> /Users/matthias/plt/racket/share/pkgs/macro-debugger/macro-debugger/view/stepper.rkt:369:24
>
> --
> 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.

-- 
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] Try-Raket is not working

2016-01-29 Thread Gustavo Massaccesi
From: http://try-racket.org/

> Exception
> The application raised an exception with the message:
> resolver: undefined;
>  cannot reference an identifier before its definition
>   in module: "/usr/share/racket/collects/planet/private/resolver.rkt"


I don't know the email of the owner, but I guess s/he is in the list.

Gustavo

PS: Is it possible to add a link to http://try-racket.org/ and
http://pasterack.org/ in the webpage of Racket?

-- 
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] Places performance & channel capacity

2016-01-22 Thread Gustavo Massaccesi
>In hindsight, I guess that's not too surprising since the majority of work
is copying byte from >one place to another anyway (soundex isn't that
slow), so if the parallel version has to copy
>the line twice when the work is ~ copying the line once, it's going to be
expensive getting
>the data into and out of places.

I didn't read the implementation of places, so some details here may be
wrong ...

Sending some bytes from one place to another probably involves some kind of
lock or semaphore to avoid race conditions. Also, the data has to be copied
from a core of the micro to another core (and perhaps to actual memory).
This is very cache unfriendly, so this destroy the automatic speedup off
using all the internal caches of the micro. So I expect a lot of overhead
for each call.

Gustavo




On Thursday, January 21, 2016, Brian Adkins  wrote:

> On Thursday, January 21, 2016 at 2:53:48 PM UTC-5, Brian Adkins wrote:
> >
> > Ok, so the huge place channel for each worker isn't the main issue. I
> changed the code so the output process sends a message to the main process
> every N messages, and the main process waits on a message from the output
> process every N messages. This has the effect of setting a limit on the
> place channels.
> >
> > Through some trial and error, I discovered that waiting every 8,000
> messages provides the best performance. So, the size of the place channels
> for each worker is < 8000 / num-workers (currently 4 workers), and the size
> of the place channel for the output process is < 8,000 messages.
> >
> > I don't know the exact count since I don't know the ratio of consumer to
> producer.
> >
> > My input lines are all exactly 300 bytes, so the output channel has <
> 2.3 MB and each worker has < 600 KB
> >
> > Current elapsed time for sequential is 2.467s and places is 3.732 s  >
> 50% slower.
> >
> > Limiting the place channel size reduced GC time also:
> >
> > cpu time: 13249 real time: 3012 gc time: 280
> >
> > Ratio of CPU time to real time is 4.4 which is good, but minimizing the
> elapsed time is the goal.
> >
> > So, in summary, copy byte strings to other places is too expensive in my
> scenario.
>
> I did some more experimenting by adding a sleep to the processing function
> to see how expensive the processing function had to be for the sequential
> and places versions to be equal.
>
> Adding a 2.1 microsecond sleep gives the following:
>
> Sequential:
> cpu time: 3574 real time: 3887 gc time: 77 (operating system elapsed =
> 4.321s)
>
> Places:
> cpu time: 13791 real time: 2958 gc time: 231 (operating system elapsed =
> 3.659s)
>
> less sleep, e.g. 2.0 microseconds, puts the sequential version ahead.
>
> I then increased the sleep as follows:
>
> 17.5 microseconds => places ~ 1/2 as long as sequential
> 32.0 microseconds => places ~ 1/3 as long as sequential
> 50.0 microseconds => places ~ 1/4 as long as sequential
> 100 microseconds => places ~ 1/3.8 as long as sequential (only 4 workers)
>
> The work itself is ~ 10 microseconds, so it would appear that a (32+10)=42
> microsecond unit of work is required to get a 3x speed up on 4 cores when
> needing to copy ~ 300 bytes twice into place channels.
>
> In hindsight, I guess that's not too surprising since the majority of work
> is copying bytes from one place to another anyway (soundex isn't that
> slow), so if the parallel version has to copy the line twice when the work
> is ~ copying the line once, it's going to be expensive getting the data
> into and out of places.
>
> If the work was parsing HTML or JSON, then the places version would
> probably be worth it on a 4 core machine.
>
> Brian
>
> --
> 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] backwards-incompatible change to in-vector

2016-01-19 Thread Gustavo Massaccesi
I couldn't write an example that is not obvious, but this programs
looks ok to me:

;---
#lang racket
(define (display-vector v)
  (for ([x (in-vector v 0 (vector-length v))])
(display x)))

(display-vector (vector 1 2 3))
(newline)
(display-vector (vector))
(newline)
;---

And I also like (in-vector (vector) 1 1), but it's more difficult to
defend this case.

Gustavo


On Tue, Jan 19, 2016 at 5:55 PM, Robby Findler
 wrote:
>
>
> On Tuesday, January 19, 2016, Stephen Chang  wrote:
>>
>> > I think you should not change this backwards compatibility unless you
>> > really know it isn't used (and even then it is hard to know such
>> > things).
>>
>> Well I still think these programs would be relying on a bug, since
>> they are referencing a non-existent vector element.
>
>
> Just to be clear, you cannot know that. And even if you did, you would be
> dictating how the programmers that maintain that code spend their time. If
> they have something more important to do you are not giving them the option
> to do their more important thing first but instead to do what you want. And
> many programmers, when faced with this choice choose not to upgrade which is
> a very bad outcome for us.
>
> You could help those programmers by finding them and pointing out the fix to
> them instead?
>
> Robby
>
>
>>
>>
>> But since there's no agreement, I'll leave it for now.
>>
>> I'll just add a special case for empty vectors and 0,0.
>>
>> It's probably not worth it to add yet-another new special case, as in
>> Matthew's email, right?
>>
>>
>>
>>
>> >
>> > Robby
>> >
>> > On Tue, Jan 19, 2016 at 1:16 PM, Stephen Chang 
>> > wrote:
>> >> Yes, or course it's possible, at the expense of more unreadable code.
>> >>
>> >> But the zero special case doesnt make sense. And is inconsistent with
>> >> other out-of-range cases, eg (in-vector (vector) 1 1) errors
>> >>
>> >> To be clear, empty traversals with valid indices would still be legal,
>> >> eg (in-vector (vector 1 2) 1 1)
>> >>
>> >> On Tue, Jan 19, 2016 at 2:06 PM, Vincent St-Amour
>> >>  wrote:
>> >>> Would it be possible to special-case `(in-vector (vector) 0 0)`
>> >>> directly, and fix the bug while keeping backwards compatibility?
>> >>>
>> >>> Vincent
>> >>>
>> >>>
>> >>> On Tue, 19 Jan 2016 12:19:12 -0600,
>> >>> Stephen Chang wrote:
>> 
>>  I'm fixing pr 15227 but I would like to do so in a
>>  backwards-incompatible way.
>> 
>>  Right now an out-of-range index is sometimes allowed as an argument
>>  to
>>  in-vector, leading to the bug:
>> 
>>  $ racket
>>  Welcome to Racket v6.4.0.4.
>>  -> (for/sum ([x (in-vector (vector 10 20) 2 -1 -1)]) x)
>>  SIGSEGV MAPERR si_code 1 fault on addr 0x180
>>  Aborted
>> 
>>  From what I can tell, the out-of-range index is allowed to enable
>>  this program:
>> 
>>  (in-vector (vector) 0 0)
>> 
>>  I want to change in-vector so that the starting index is always a
>>  valid vector-ref. The above program would become illegal.
>> 
>>  From what I gather, the above program is allowed so that in-vector
>>  mimics in-range but I don't think this makes sense either if it means
>>  allowing out-of-range indices for the former.
>> 
>>  Any objections?
>> 
>>  --
>>  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.
>> >>
>> >> --
>> >> 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.
>
> --
> 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 

Re: [racket-users] Racket performance tips

2016-01-18 Thread Gustavo Massaccesi
I have a few minor stile comments:

*** I'd replace
   (define backslash 92)
with
   (define backslash (char->integer #\\))
to improve legibility.
And do the same replacement for other magic numbers. After
optimization, both versions are identical.

[The only site where this would cause a difference is in code like
(for ([i (in-range 92)]) ...)
but you are not using something like this.]


*** In  few spots, you use `null` as "do nothing in this case", for
example in line 38. I think it's more idiomatic to use `(void)`.

*** In line 328, I it possible to do this? Replace

  ;;[[[
  ;; 5. Remove all occurrences of AEIOU, except first letter
  (define len2 (bytes-length str4))
  (define str5(bytes-append
   (subbytes str4 0 1)
   (bytes-delete-pred
(if (> len2 1) (subbytes str4 1 len2) #"")
 (λ (b) ...
  ;; 6. If first symbol is a digit replace it with letter saved on step 1.
  (when (byte-numeric? (bytes-ref str5 0))
(bytes-set! str5 0 first_letter))
  ;;;]]]

with this

  ;;[[[
  ;; 5. Remove all occurrences of AEIOU, except first letter
  (define len2 (bytes-length str4))
  (define str5(bytes-append
   #"?"
   (bytes-delete-pred
(if (> len2 1) (subbytes str4 1 len2) #"")
 (λ (b) ...
  ;; 6. Replace firt symbol with letter saved on step 1.
  (bytes-set! str5 0 first_letter)
  ;;;]]]

or this:

  ;;[[[
  ;; 5. Remove all occurrences
  (define len2 (bytes-length str4))
  (when (>= len2 1)
(bytes-set! str4 0 (char->integer #\?))
  (define str5
   (bytes-delete-pred
 str4
 (λ (b) ...
  ;; 6. Replace firt symbol with letter saved on step 1.
 (when (>= len2 1)
   (bytes-set! str5 0 first_letter))
  ;;;]]]

I hope I'm not missing a corner case. I estimate that with the 200K
fields this will reduce the time from 2.5s to 2.4s.


*** I tried a few more changes that avoid allocating intermediate
bytes, but they are more complex and with 200K rows I estimate that
the difference in run time would be only 0.02s. If I find something
bigger, I'll write again.

Gustavo

PS: How many "JOHN"s do you have? Have you considered caching the
soundex of the names. But I'm not sure if this would be faster.

On Sun, Jan 17, 2016 at 10:13 PM, Brian Adkins  wrote:
> On Sunday, January 17, 2016 at 2:54:39 PM UTC-5, Brian Adkins wrote:
>> On Sunday, January 17, 2016 at 2:50:19 PM UTC-5, Brian Adkins wrote:
>> >
>> > With built-in string-trim, the lowest of three runs was 10293. Using your 
>> > string-trim the lowest of three runs was 7618, so it reduced the runtime 
>> > by 26%.
>>
>> Although, I probably should've mentioned that I'm not particularly 
>> interested in unsafe optimizations. I already have a very fast C program if 
>> I'm willing to risk unsafe behavior, so for Racket, I'd like to retain 
>> safety.
>>
>> Having said that, I'm pretty sure a combination of using Byte Strings and 
>> manually optimizing string-trim & string-replace (or skipping them in some 
>> cases) will get under the Ruby time.
>
> Yay - success!  :)
>
> I changed all strings to byte strings while leaving the style of the code 
> very similar. It made a significant difference. Of course, I also gained the 
> benefit if handwritten bytes-split, bytes-replace, bytes-delete, bytes-trim, 
> etc. which were narrowly defined just for this app.
>
> Timings on a 200K line file are now:
>
> Ruby = 7.53s
> Racket = 2.52s  (was 10.3s)
>
> The string version of the Racket program was over 4x slower. I'm quite 
> satisfied with being 3x faster than Ruby with a similar coding style given 
> this is really in Ruby's sweet spot i.e. text munging.
>
> New code is here:
>
> https://gist.github.com/lojic/892049e617637903f982
>
> I think my next step will be to create a version that uses places. 
> make-shared-bytes may be useful for that.  I'll report back with timings. I 
> have a 4 core macbook pro w/ 8 hyperthreads - no idea whether the 
> hyperthreads are actually useful, but if I can get a 3x speedup with 4 cores, 
> I'd be pretty pleased.
>
> I suppose the following is a reasonable architecture:
>
> 1 place for reading the input file and placing a record in a input queue
> N places (one per core) to read from the input queue, process and place in an 
> output queue
> 1 place for reading the output queue and writing to either of two output files
>
> --
> 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.

Re: [racket-users] [racket] suggestions on scribble/example

2016-01-09 Thread Gustavo Massaccesi
In TravisCI, building with the "main-distribution" packge, the
versions in linux that don't have "--disable-jit" finish corretly just
a minutes after an hour. (I think the official max time is 1 hour, but
apparently there are some bonus minutes.)

The versions with "--disable-jit" take longer and are broken automatically.

See https://travis-ci.org/gus-massa/racket/builds/100167233 (The error
was caused by an unrelated problem.)

Gustavo

On Sat, Jan 9, 2016 at 2:38 PM, Sam Tobin-Hochstadt
 wrote:
> We do run the core racket tests without exflonums on Travis; you can
> see an example here:
> https://travis-ci.org/racket/racket/jobs/101270780
>
> Unfortunately, building all of Racket + everything else takes more
> time that various hosted CI systems allow. If there was a build of
> Racket without extflonums, then the Typed Racket CI could test that,
> but there are a lot of different configurations to test, and that
> requires individual per-package effort.
>
> Sam
>
> On Sat, Jan 9, 2016 at 11:13 AM, Robby Findler
>  wrote:
>> Could this problem be helped if we run something like drdr, but in
>> more configurations? (That doesn't seem particularly simple, tho.)
>>
>> Robby
>>
>>
>> On Sat, Jan 9, 2016 at 10:07 AM, Matthew Flatt  wrote:
>>> At Sat, 9 Jan 2016 08:34:45 -0700, Matthew Flatt wrote:
 At Sat, 9 Jan 2016 22:58:00 +0800, WarGrey Gyoudmon Ju wrote:
 > 1. Could you please treat the exn:fail:unsupported like a normal case as 
 > if
 > it is wrapped by (eval:error)?
 >
 >
 http://docs.racket-lang.org/ts-reference/type-ref.html#%28form._%28%28lib._type
 > d-racket%2Fbase-env%2Fbase-types..rkt%29._.Ext.Fl.Vector%29%29
 >
 > this example is about ExtFlVector which is not supported in my 
 > openindiana
 > box.

 Treating an `exn:fail:unsupported` error as if wrapped by `eval:error`
 sounds reasonable to me.
>>>
>>> On further reflection, that seems like a bad idea  --- repeating the
>>> mistakes of `scribble/eval`.
>>>
>>> I think it's better in this case to adjust the documentation. I don't
>>> have a good idea on how to prevent this kind of problem in the future,
>>> though.
>>>
>>> --
>>> 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.
>
> --
> 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] Re: Typed Racket: Is (- 1 1) equivalent to (- 2 2)?

2015-12-10 Thread Gustavo Massaccesi
IIRC, the only numeric type that are singletons are Zero and One, so
this also typechecks:

(+ 1 (if (= 0 (- 0 0)) 1 "x"))

On a related note, the (untyped)Racket optimizer has constant folding,
so in (untyped)Racket all these expressions are compiled to 2. I don't
know if it's possible to add constant folding to Typed Racket.

Anyway, other obvious expressions like
(lambda (x) (+ 1 (if (eq? x x) 1 "x")))
are not reduced (currently).

Gustavo


On Thu, Dec 10, 2015 at 3:12 PM, Vincent St-Amour
 wrote:
> Right.
>
> The key distinction here is that TR is not so much reasoning about
> constants, but about a singleton type. So TR is still working in terms
> of types, not in terms of concrete values.
>
> Vincent
>
>
>
> On Thu, 10 Dec 2015 11:55:24 -0600,
> 'John Clements' via Racket Users wrote:
>>
>>
>> > On Dec 10, 2015, at 9:50 AM, George Neuner  wrote:
>> >
>> > On Thu, 10 Dec 2015 12:35:34 -0500, Alex Knauth
>> >  wrote:
>> >
>> >> In typed racket (- 1 1) and (- 2 2) are equal at runtime, but the type
>> >> checker doesn't necessarily know that at compile time. It knows that
>> >> (- 1 1) is zero because that's a special case in the type system. But it
>> >> doesn't have a special case for (- 2 2), so it only knows that that's a
>> >> Fixnum.
>> >
>> > But in this case the type checker isn't dealing with variables.  Which
>> > begs the question why is (- 1 1) special cased?  Shouldn't there be a
>> > general rule: (- C C) where C is a numeric constant?
>> > [Ok, I know equality is a problem with floating point ... but, still,
>> > the principle remains.]
>>
>> Check out the numeric tower in TR: there’s a type that includes just the 
>> number 1. The natural extension to all numbers (each number has its own 
>> type) leads (IIUC) to a totally intractable type system.
>>
>> John
>>
>> >
>> > George
>> >
>> > --
>> > 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.
>
> --
> 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] Rust vs. C as a complement to Racket?

2015-11-19 Thread Gustavo Massaccesi
> I did *some* hand optimizing. Here's the code for the soundex and some string 
> helper functions I created:
>
> https://gist.github.com/lojic/1deba97f2e2eb2fe3fc0
>

I'm optimistic and I think that there is still some room for
micro-optimizations (for example, replace the set!'s, but I didn't try
yet).

But more important is:Do you want to preserve the general structure of the code?

It has many small functions that are nice to write and debug, but each
one creates an intermediate string. In this algorithm, most of the
processing is character-by-character. So I think that most of the
calculations can be merged in a megafunction that avoids most of the
allocations.

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] Defining a symbol breaks symbols?

2015-10-18 Thread Gustavo Massaccesi
This "breaks" my old example:

#lang hygienic-quote racket
(define-syntax-rule (quasiquote x) (reverse 'x))
`(1 2 3 4)

Nice idea!


I found a strange side effect of the use of the marks. This compiles
without error:

#lang hygienic-quote racket

(define 'x 5)
(define 'x 5)
'3

But I think it's not a problem for real word use, and it's better than
the standard behavior.

Gustavo




On Fri, Oct 16, 2015 at 12:32 AM, Alex Knauth  wrote:
> Sorry it took so long, but I just finished making a meta-language that adds
> quote, quasiquote, etc. as hygienic reader extensions.
>
> https://github.com/AlexKnauth/hygienic-quote-lang
>
> So now, you can write
>
> #lang hygienic-quote racket
>
> To make sure that the ' character will always be bound to the quote from
> racket/base, not some weird thing that you accidentally defined. It also
> does this for quasiquote, unquote, unquote-splicing, syntax, quasisyntax,
> unsyntax, and unsyntax-splicing.
>
> It only works with the the new scope-set expander right now, although I
> could probably tweak it so that it works for both.
>
>
> On Oct 8, 2015, at 11:31 AM, Alex Knauth  wrote:
>
>
> On Oct 8, 2015, at 9:00 AM, Lyle Kopnicky  wrote:
>
> Yes, sorry, I've been traveling and didn't have time to respond. I was
> originally tempted to say "statically typed" and then realized that wasn't
> exactly right, because it was not static types that would forbid such a
> construction, so I said "static languages" suggesting languages where things
> cannot be so easily changed.
>
>
> Ok I think I see what you're saying. Unhygienic macros capture bindings from
> the use site, which breaks lexical scope and brings it closer to looking
> like dynamic scope, and unhygienic reader extensions do the same thing. But
> that's why we have hygienic macros and hygienic reader extensions; to
> restore lexical scope, which is static.
>
> I'm not so familiar with reader macros. The documentation looks pretty
> extensive so I don't have to time to absorb it right now.
>
>
> Reader extensions are not my favorite part of racket. Whenever I make them,
> they feel like a bit of a mess.
>
> I would imagine that macros are not closures, therefore they shouldn't have
> any free variables.
>
>
> Half the point of hygienic macros is that they can "close over" variables
> that would otherwise appear to be free variables, but are actually bound to
> some variable in the context of the macro definition instead of the context
> of the macro use site. So they can act like closures. And it's in that
> analogy of hygienic macros as closures that unhygienic macros look like
> dynamic scope. But hygienic macros can "close over" these things to restore
> lexical scope.
>
> Hygienic reader extensions can do the same thing, although there can be some
> complications with an identifier being bound to an identifier that is not
> available anywhere that the use site module knows about. So for instance the
> afl meta-language expands to lambda from racket/base, but it only works when
> the base language depends in some way on racket/base. That base language
> doesn't need to provide the lambda from racket/base, but a dependency has to
> be there somewhere. That isn't a lot to ask, but it does means that for
> instance #lang afl racket/kernel won't work.
>
> Matthew Flatt explained to me that for normal macros, this is handled
> automatically, but not for reader extensions.
>
> Matthew Flatt gave a nice demonstration of a clean way to do that (using
> multiple scopes with colors). I'm not sure how things might be different for
> reader macros, though. It seems to me that while the input of a reader macro
> is different (plain text instead of sexprs), the output is still sexprs, so
> the same sort of scoping rules should apply.
>
>
> For hygienic macros to avoid this capturing behavior, there has to be a
> color at the use site of the macro that is not in the context of the
> definition of the macro. This is handled automatically by default.
>
> For hygienic reader extensions, the same principle applies, but you have to
> do that yourself because it's not handled automatically. Also, there has to
> be a dependency somewhere on the module that provides the identifier, which
> is another thing macros handle automatically and reader extensions don't.
>
>
> --
> 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] racket users fight for their right to colon keywords

2015-10-16 Thread Gustavo Massaccesi
I agree. I think that :xyz doesn't look special enough, and with #:xyz
is clear that the reader is doing something special.

Gustavo

On Thu, Oct 15, 2015 at 1:00 PM, Laurent  wrote:
> On Thu, Oct 15, 2015 at 3:25 PM, Deren Dohoda 
> wrote:
>>
>> I don't have a very strong opinion, it seems like convenient syntax, but
>> half of what draws me to stick with lisps is the low amount of syntax.
>> Pound-colon has a strong line noise quality to it which colons lack,  I
>> admit. But they also have an explicit feel which colons lack.
>
> In particular, they have a "reader syntax" feeling, as most things that
> start with a pound in Racket. I initially didn't like them for keywords, but
> now I'm feeling somewhat ok with them. Having two characters to prefix a
> keyword argument is a lot though, especially when one uses them so much.
>
> Laurent
>
> --
> 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] help on coding finite state automata

2015-10-13 Thread Gustavo Massaccesi
:( . I tried few modifications, but I didn't get any improvement. I
think that the recalculation of the population is used very seldom, so
any change there will not affect the speed too much.

Most of the time is used in the matches, but I don't have any
suggestion for it (that doesn't include uglifying the code, and
perhaps are also not useful).

Gustavo

On Mon, Oct 12, 2015 at 7:14 PM, Matthias Felleisen
<matth...@ccs.neu.edu> wrote:
>
>
> So I couldn't resist and wrote the vector-based, allocation-minimizing
> version of the program. I didn't get that much of a performance gain.
>
> I might still change the fitness representation (into a vector) or
> integrate it into 'population' (where it belongs from an SE perspective).
> I doubt this will do much better in terms of speed. A speed-up of 6x
> will have to do for now.
>
> Code at the same old link:
>
>>https://github.com/mfelleisen/sample-fsm
>
>
>
>
>
>
>
> On Oct 12, 2015, at 11:46 AM, Matthias Felleisen <matth...@ccs.neu.edu> wrote:
>
>>
>> for/last: good point.
>>
>> Based on my previous experience with replacing imperative automata with 
>> functional ones,
>> I don't think replacing the list-based population container with a vector 
>> per se will
>> speed up things much. But the pairing up of neighbors might be a tad faster. 
>> Then again
>> I would have to rewrite shuffle for imperative vectors.
>>
>> I have pulled out the population for now so that you can play with this:
>>
>> https://github.com/mfelleisen/sample-fsm
>>
>> It's easy to run now from the command line.
>>
>>
>>
>> On Oct 12, 2015, at 11:17 AM, Gustavo Massaccesi <gust...@oma.org.ar> wrote:
>>
>>> Sorry for not testing before posting, but in this code:
>>>
>>> (define (randomise-over-fitness accumulated-payoff-percentage population 
>>> speed)
>>> (for/list ([n (in-range speed)])
>>>   [define r (random)]
>>>   (for/and ([p (in-list population)]
>>> [a (in-list accumulated-payoff-percentage)]
>>> #:break (< r a))
>>> p)))
>>>
>>> It looks like the population is stored in a list, and the changes in
>>> the populations create more lists. I think that changing the
>>> implementation to use vectors instead of list would make the code
>>> faster. (But I haven't tested it.)
>>>
>>> Also, I think that for/and can be changed to for/last. I guess it will
>>> almost no no change the speed, but it would make the intention
>>> clearer.
>

-- 
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] help on coding finite state automata

2015-10-12 Thread Gustavo Massaccesi
Sorry for not testing before posting, but in this code:

 (define (randomise-over-fitness accumulated-payoff-percentage population speed)
  (for/list ([n (in-range speed)])
[define r (random)]
(for/and ([p (in-list population)]
  [a (in-list accumulated-payoff-percentage)]
  #:break (< r a))
  p)))

It looks like the population is stored in a list, and the changes in
the populations create more lists. I think that changing the
implementation to use vectors instead of list would make the code
faster. (But I haven't tested it.)

Also, I think that for/and can be changed to for/last. I guess it will
almost no no change the speed, but it would make the intention
clearer.

Gustavo



On Mon, Oct 12, 2015 at 5:31 AM, Linh Chi Nguyen
 wrote:
> I dont know how the email group work. If someone keeps receiving emails out 
> of interest, please notice me.
>
> Thanks Bryan for the suggestion, it's nice to know, however Im not able to 
> afford upgrading now.
>
> And Matthias, for your notice of the spawning process
> ```
> (define (randomise-over-fitness accumulated-payoff-percentage population 
> speed)
>   (for/list ([n (in-range speed)])
> [define r (random)] ;; SHOULDN"T THIS LINE BE OUTSIDE OF THE for/list 
> COMPREHENSION?
> (for/and ([p (in-list population)][a (in-list 
> accumulated-payoff-percentage)]
>   #:break (< r a))
>   p)))
> ```
>
> The randomly generated r has to be inside the for/list loop. Because if it's 
> outside, then there is only one random number generated at the beginning, and 
> the newly spawn automata will keep being the same one repeatedly.
>
> For example, when the learning speed is s = 10, it means that, 10 old 
> automata should be replaced with 10 new ones. And the replacement should be 
> done in 10 different places in the population.
>
> This procedure is called an independent bernoulli draw. We independently draw 
> a random number (associated with an automaton) for 10 times. How likely an 
> automaton is chosen depends on its own fitness (its interval in the unit 
> scale of the accumulated percentages.)
>
> On Monday, 12 October 2015 03:46:05 UTC+2, Matthias Felleisen  wrote:
>> I have pushed some more cleanups, more speed.
>> I added another question to the “spawning” procedure.
>>
>>
>>
>>
>
> --
> 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] Separate compilation vs macros in signatures and compiler stacktraces (crashes?)

2015-10-08 Thread Gustavo Massaccesi
(Old thread ...)

I only want to add an example of identifier capture. Here the
identifier _it_ is not bound at the macro compiling time, but is bound
at the final code. Note: Capture is discouraged in Racket.

I think that 99% of the times, the unbound identifiers are just typos,
like displyaln. So if this becomes illegal some day in the future I'll
be 99% happier.

#lang racket

(define-syntax (show-it ignored-stx)
  (with-syntax ([it (syntax-local-introduce #'it)])
#'(displayln it)))

(let ()
  (define it 7)
  (show-it))

Gustavo

On Tue, Oct 6, 2015 at 8:54 PM, Sam Tobin-Hochstadt
 wrote:
> On Tue, Oct 6, 2015 at 7:50 PM, Paolo Giarrusso  wrote:
>> Thanks for the prompt answer and the clarifications! But there's a
>> third issue, which unfortunately I've hid when I combined the modules
>> in one file (sorry), and which is more important. Sorry I made this
>> unclear.
>>
>> In the split version
>> (https://github.com/Blaisorblade/racket-playground/tree/master/bug-with-signatures-and-macros,
>> client.rkt and its 2 dependencies), for a bug in the first module I
>> get the error only in the third module (as detailed in the first
>> email). That's why I talked about separate compilation: maybe I'm
>> still confused, but I'd expect the error to be on the first module. If
>> this weren't separate compilation, I believe I'd still argue it's an
>> important guarantee.
>
> This is a general issue with macros. Racket can't tell that `thunk`
> will be unbound once its expanded the macro until it actually happens.
> So no error can be reported until then. You can see the same issue
> with these two modules:
>
> (module m1 racket
>   (provide m)
>   (define-syntax-rule (m) (add1 unbound-id)))
>
>
> (module m2 racket
>   (require 'm1)
>   (m))
>
> The error only happens when expanding m2.
>
>>
>> In addition, I get an error it without any line number — which is
>> maybe a more subtle matter. Also DrRacket shows no line number.
>>
>> $ raco make client.rkt
>> thunk: unbound identifier in module
>>   in: thunk
>>   compilation context...:
>>
>> /Users/pgiarrusso/AeroFS/Repos/racket-playground-bluevelvet/bug-with-signatures-and-macros/client.rkt
>>   context...:
>> [ the same ]
>
> That sounds like somewhere the source location is getting lost in the
> unit macro, which is probably a bug.
>
> Sam
>
>> Cheers,
>> Paolo
>>
>> On 7 October 2015 at 01:28, Sam Tobin-Hochstadt  wrote:
>>> I think there are two issues here:
>>>
>>> 1. The stack trace in your email is just a result of `raco make`
>>> printing its current context when there's a syntax error. If you
>>> replace the whole body of the module with just `(lambda)`, you'll see
>>> the same stack trace. Probably `raco make` should be changed not to
>>> print that part of the stack.
>>
>> I'm in favor. (Also because I'm used to the Scala compiler, where
>> stacktraces are bugs and bugs are plentiful).
>>
>>> 2. `(require (for-syntax racket/function))` would be needed if you
>>> used `thunk` to compute the new syntax that your macro expanded into
>>> -- in other words, if `thunk` gets executed during expansion. However,
>>> your macro expands into a use of `thunk`, just like it expands into a
>>> use of `reify-thunk`.
>>
>> Sorry, on this point I was plainly confused.
>>
>>> If we rewrite your macro not using
>>> `syntax-rules, the distinction is perhaps clearer:
>>>
>>> (define-syntax reify (lambda (stx) (syntax-case stx () [(_ e)
>>> (syntax (reify-thunk (thunk e)))])))
>>>
>>> The things used in the computation of the new syntax are, here,
>>> `lambda`, `syntax-case`, and `syntax`. `reify-thunk` and `thunk`
>>> appear inside `syntax` -- they are part of the program that we expand
>>> into, and thus need to be available at phase 0.
>>>
>>> Hopefully that helps explain what's going on here.
>>>
>>> Sam
>>>
>>>
>>>
>>> On Tue, Oct 6, 2015 at 7:18 PM, Paolo Giarrusso  
>>> wrote:
 I feel I've found (and minimized) a perfectly repeatable bug in separate 
 compilation in Racket 6.2.1, or at least a situation which is a pain to 
 debug for related reasons. The example code is available at 
 http://pasterack.org/pastes/25050 (or at the end of this email) with all 
 modules in one file, but I've first obtained it with modules in separate 
 files.

 In module base-sig, I can use an identifier (here `thunk`) which is *not* 
 in scope in a "macro" (?) inside define-signature. In module base (which 
 requires module base-sig) I provide a unit implementing the signature. 
 Then, if in module client I require module base, load the unit *and use 
 the macro*, I get a compiler stacktrace mentioning `thunk`, even though 
 `thunk` isn't mentioned (except after macro expansion). No error before.
 To fix this, I must trace this to module 1 by trial and error — requires 
 elsewhere won't help (because lexical scope is still 

Re: [racket-users] Failure when building a distributable application

2015-10-01 Thread Gustavo Massaccesi
I think that I will not be to able to fix this, but anyway I think
that there is very little information here.

Windows, OSX, Linux, or other? Version?

Which DrRacket version are you using?

Gustavo



On Wed, Sep 30, 2015 at 5:54 AM, Byron Davies  wrote:
> How can one debug a failure to build a distributable application (from the 
> Racket menu)? I can build the lesser levels (source launcher and compiled 
> launder), but building a distributable application just bombs out, with no 
> trace of information.  DrRacket itself is still alive, but the process doing 
> the build just went poof.
>
> --
> 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] memq vs member [was: typed/racket + rackunit = trouble]

2015-09-20 Thread Gustavo Massaccesi
I've done a few experiments with a easy version of , that
never has a third argument. (It's wrong, but it's useful to estimate
how much better the final version could be.)

https://github.com/gus-massa/racket/commit/cd35e0dc3db474f8dc31fea170d1bc2900f2e338

I simplified the use of the macros, but I'm not sure that it's
necessary. The main improvement comes from using
begin-encourage-inline, so  can be inlined and then the
optimizer can see the (equal? x 'symbol) and transform it to (eq? x
'symbol).

A typical run of:

#lang racket
(require racket/private/member2)
(define l (make-list 5000 'x))
; normal version
(time (for ((i 1)) (memq 'y l)))
(time (for ((i 1)) (member 'y l)))
; inlinable version
(time (for ((i 1)) (memq2 'y l)))
(time (for ((i 1)) (member2 'y l)))

;=>

cpu time: 764 real time: 873 gc time: 0
cpu time: 5148 real time: 5368 gc time: 0
cpu time: 905 real time: 1041 gc time: 0
cpu time: 2293 real time: 2689 gc time: 0


Analyzing the decompiled version, the for loop is partially "unrolled"
and one half of the times the  function is inlined and the
other half of the times it is not inlined. (The pattern is
YYNNYYNNYYNN...) So half of them are fast and half of them are slow,
and the time is close to the average.

This is caused because the internal inlining fuel is not enough to
inline all the instances of member. The same fuel is used for
something similar to loop unrolling, so the pattern is strange. (I
think that more fuel would change the pattern to YNNYNN...)

One possible solution is to inline  before unrolling the loop.
I think that there are some tricks in the current Racket version that
try to do this when the loop is big, but this is a small loop. But I'm
not sure how this change would affect other code and how difficult
this is.

(Loops are difficult to optimize. Somewhat related: "loop
optimizations in guile"
http://wingolog.org/archives/2015/07/28/loop-optimizations-in-guile )

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] Re: typed/racket + rackunit = trouble

2015-09-19 Thread Gustavo Massaccesi
Probably the difference is caused by the diference of the Racket
version in your machine and in PasteRack. In my machine:

*** Using Racket 6.2
cpu time: 687 real time: 702 gc time: 0
cpu time: 14352 real time: 14838 gc time: 0
cpu time: 3619 real time: 3674 gc time: 0
cpu time: 5429 real time: 5430 gc time: 0
cpu time: 3245 real time: 3252 gc time: 0
cpu time: 3213 real time: 3242 gc time: 0

*** Using Racket almost the current HEAD (~one week old)
cpu time: 717 real time: 742 gc time: 0
cpu time: 4368 real time: 4465 gc time: 0
cpu time: 3526 real time: 3550 gc time: 0
cpu time: 5616 real time: 5809 gc time: 0
cpu time: 3057 real time: 3056 gc time: 0
cpu time: 2996 real time: 2996 gc time: 0

Gustavo


On Sat, Sep 19, 2015 at 9:22 PM, Sam Tobin-Hochstadt
<sa...@cs.indiana.edu> wrote:
> When I run my original program on my own machine (instead of
> Pasterack), the difference is more like 2-3x. So my original email
> overstated the speed difference a bunch. I don't know what's going on
> that makes it so different on pasterack.
>
> An interesting side note -- we tried this program in Pycket, and two
> interesting things happened:
>  - it turned out to be another test case for a problem we are working
> on right now -- memq was too slow because it was used previously with
> different types
>  - when that's fixed, memq and member are the same speed, because
> Pycket's version of `eq?` is slower than it would be otherwise,
> precisely because it has to maintain the semantics that Robby doesn't
> like :)
>
> Sam
>
> On Sat, Sep 19, 2015 at 5:38 PM, Gustavo Massaccesi <gust...@oma.org.ar> 
> wrote:
>> There is something very strange with memq vs member:
>> http://pasterack.org/pastes/80845  (note: I added one 0 to the loop
>> constants)
>>
>> I used two mutable variables eq?? and equal?? to avoid (most of) the
>> optimizations and I get that the time with equal? is 2x than the time
>> with eq?. This is closer to the range I expected.
>>
>> Using directly eq? and equal? is slightly faster, and the time is the
>> same because under the hood the optimizer transforms equal? to eq?
>> when one of the arguments is an explicit symbol.
>>
>> The implementation of member and memq is very short but very
>> entangled. I think that with some tweaks is possible to reduce the
>> time difference to x2, and with some luck to make it more optimizer
>> friendly and gain some additional speed.
>>
>> Gustavo
>>
>>
>>
>> On Thu, Sep 17, 2015 at 11:01 PM, Sam Tobin-Hochstadt
>> <sa...@cs.indiana.edu> wrote:
>>> Unfortunately, that's only true when eq? produces #t, which probably isn't
>>> an issue when using eq? directly, but can be when using memq or similar.
>>> This benchmark suggests about a 10x speed difference when the symbols are
>>> different: http://pasterack.org/pastes/94877
>>>
>>> Sam
>>>
>>>
>>> On Thu, Sep 17, 2015, 9:52 PM Robby Findler <ro...@eecs.northwestern.edu>
>>> wrote:
>>>>
>>>> FWIW, if you use equal? in those cases, you'll get the same
>>>> performance behavior and you will have fewer eq?s to audit when things
>>>> go wonky.
>>>>
>>>> ;)
>>>>
>>>> Robby
>>>>
>>>> On Thu, Sep 17, 2015 at 8:36 PM, Neil Van Dyke <n...@neilvandyke.org>
>>>> wrote:
>>>> > Whew. :)  I only rarely have a non-symbol use for `eq?`, but I use `eq?`
>>>> > heavily for symbols in everyday application code.
>>>> >
>>>> > Robby Findler wrote on 09/17/2015 09:27 PM:
>>>> >>
>>>> >> eq? on symbols is a special part of the specification and that seems
>>>> >> benign to me, all things considered. The "giant hash in the sky" that
>>>> >> makes sure that works isn't exactly trouble free, but we seem to have
>>>> >> it under control.
>>>> >
>>>> >
>>>> > --
>>>> > 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.
>>>
>>> --
>>> 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] Re: typed/racket + rackunit = trouble

2015-09-19 Thread Gustavo Massaccesi
There is something very strange with memq vs member:
http://pasterack.org/pastes/80845  (note: I added one 0 to the loop
constants)

I used two mutable variables eq?? and equal?? to avoid (most of) the
optimizations and I get that the time with equal? is 2x than the time
with eq?. This is closer to the range I expected.

Using directly eq? and equal? is slightly faster, and the time is the
same because under the hood the optimizer transforms equal? to eq?
when one of the arguments is an explicit symbol.

The implementation of member and memq is very short but very
entangled. I think that with some tweaks is possible to reduce the
time difference to x2, and with some luck to make it more optimizer
friendly and gain some additional speed.

Gustavo



On Thu, Sep 17, 2015 at 11:01 PM, Sam Tobin-Hochstadt
 wrote:
> Unfortunately, that's only true when eq? produces #t, which probably isn't
> an issue when using eq? directly, but can be when using memq or similar.
> This benchmark suggests about a 10x speed difference when the symbols are
> different: http://pasterack.org/pastes/94877
>
> Sam
>
>
> On Thu, Sep 17, 2015, 9:52 PM Robby Findler 
> wrote:
>>
>> FWIW, if you use equal? in those cases, you'll get the same
>> performance behavior and you will have fewer eq?s to audit when things
>> go wonky.
>>
>> ;)
>>
>> Robby
>>
>> On Thu, Sep 17, 2015 at 8:36 PM, Neil Van Dyke 
>> wrote:
>> > Whew. :)  I only rarely have a non-symbol use for `eq?`, but I use `eq?`
>> > heavily for symbols in everyday application code.
>> >
>> > Robby Findler wrote on 09/17/2015 09:27 PM:
>> >>
>> >> eq? on symbols is a special part of the specification and that seems
>> >> benign to me, all things considered. The "giant hash in the sky" that
>> >> makes sure that works isn't exactly trouble free, but we seem to have
>> >> it under control.
>> >
>> >
>> > --
>> > 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.
>
> --
> 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: Make, in place build, was Re: [racket-users] Racket v6.2

2015-09-11 Thread Gustavo Massaccesi
I'm using:

make in-place PKGS="racket-test-core"

This install only a small set of packages, so the build time is short.
Also, the time of "raco setup" is smaller.

I usually add a few additional packages when I need them, for example
"compiler-lib".

Gustavo



On Fri, Sep 11, 2015 at 12:06 AM, Anthony Carrico  wrote:
> On 09/10/2015 08:40 PM, Anthony Carrico wrote:
>> I'll forward you a transcript of a failed build.
>
> FYI: Off list Matthew suggested that it ran out of memory, and indeed
> the build succeeds with more free memory.
>
> --
> Anthony Carrico
>
>
> --
> 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] 6.2 regression in running tests?

2015-07-20 Thread Gustavo Massaccesi
Sorry for the delay. It has been a very interesting week in the low
level implementation of Racket. A few days ago, Matthew fixed the bug
and enabled the new expander, and then he fixed most of the problems
that appear with the changes. So now looks like a good time to retry
all the tests and see if the test are working with the snapshot
version of Racket.

Following this idea, I remembered that the rackjure project (
https://github.com/greghendershott/rackjure ) has a .travis.yml file,
to get continuous integration tests in Travis. It uses a trick to run
the project with the latest 10 versions of Racket. You can configure
it to run less versions, for example only 6.0.1, 6.1.1 and HEAD (but
allow errors in HEAD). You should look at the file in the repository
because it's very clear, and if you have a problem you may ask the
author because he usually reads the list.

This will give you a report of the errors that the next version of
Racket would create, and you can send an early warning to the list.
This will be helpfull to fix the errors before shipping.

Gustavo


On Wed, Jul 15, 2015 at 4:14 AM, Ryan Davis zenspi...@gmail.com wrote:

 On Jul 14, 2015, at 20:19, Gustavo Massaccesi gust...@oma.org.ar wrote:

 Replacing the line 1758 of optimize.c

 -  if ((info-inline_fuel  0)  info-has_nonleaf  !noapp)
 +  if ((info-inline_fuel = 0)  info-has_nonleaf  !noapp)

 make the problem disappear, but I still don't understand why (dup
 rep) is the only combination that creates a problem.

 I also want to think about the (info-inline_fuel = 0) in line 1872
 and how that interacts with the if (noapp) in line 1876 ...

 Thanks! I can test against my whole suite in tomorrow's daily if you'd like.


-- 
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] 6.2 regression in running tests?

2015-07-15 Thread Gustavo Massaccesi
Update: No so good news, my idea of yesterday was slightly wrong. I
think it causes no errors, but it makes the compiler pessimistic and
it avoid some optimizations. I found another fix, but I want to test
it more before submitting the patch.

More details:

In some cases, the optimizer reoptimize an expression with fuel=0, to
get the correct values of some internal flags. So some code in
optimize_for_inline must run even when fuel=0.

The idea is that when fuel=0 there should be no inlining, but the
compiler tries to inline the functions that are used only once even
when there is not enough fuel, so the original copy disappear and only
the inlined code survives. (When the function is used more than one
time this may increase the size of the bytecode. But this is a good
idea for single used functions.)

So this modified version hangs:
#lang racket
(define dup (lambda (f) (f f)))
(lambda ()
  (let ([rep (lambda (f) (f f))])
(list
 (dup rep)
 dup))) ; -- look here

But this modified version is ok
#lang racket
(define dup (lambda (f) (f f)))
(lambda ()
  (let ([rep (lambda (f) (f f))])
(list
 (dup rep)
 rep))) ; -- look here

This also explains why only '(dup rep)' caused problems.

Todays fix is in line 1900 of optimize.c
-  if ((sz = 0)  (single_use || (sz = threshold))) {
+  if ((sz = 0)  (single_use || (sz = threshold)) 
(info-inline_fuel  0)) {

But perhaps the problem is in the code that tracks the single_use
value. After 'dup' is applied, 'rep' is not long a singled used
function.  ... I must test this a little more ...

Gustavo



On Wed, Jul 15, 2015 at 4:14 AM, Ryan Davis zenspi...@gmail.com wrote:

 On Jul 14, 2015, at 20:19, Gustavo Massaccesi gust...@oma.org.ar wrote:

 Replacing the line 1758 of optimize.c

 -  if ((info-inline_fuel  0)  info-has_nonleaf  !noapp)
 +  if ((info-inline_fuel = 0)  info-has_nonleaf  !noapp)

 make the problem disappear, but I still don't understand why (dup
 rep) is the only combination that creates a problem.

 I also want to think about the (info-inline_fuel = 0) in line 1872
 and how that interacts with the if (noapp) in line 1876 ...

 Thanks! I can test against my whole suite in tomorrow's daily if you'd like.


-- 
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] 6.2 regression in running tests?

2015-07-14 Thread Gustavo Massaccesi
I reduced it a little, it's a variation of the old
  ((lambda (x) (x x)) (lambda (x) (x x)))
but there must be a problem in the inlining fuel.

In my example, the ´dup´ definition is not necessary, but it makes it
more clear. It can be copied by hand to the application point.

I wrapped the example in a 'lambda', to be sure that it should not be
executed even once. This lambda is not necessary and can be removed.

#lang racket
(define dup (lambda (f) (f f)))
(lambda ()
  (let ([rep (lambda (f) (f f))])
(dup rep)))

It's strange that only (dup rep) causes a problem, (dup dup), (rep
rep) and (rep dup) are ok.

Gustavo


On Tue, Jul 14, 2015 at 6:23 PM, Sam Tobin-Hochstadt
sa...@cs.indiana.edu wrote:
 This appears to be a bug in the inliner, which appears in HEAD as well.

 This program is sufficient to reproduce:

 #lang racket

 (define (Y3 outer)
   (define ((call f) x)
 ((f f) x))
   ((lambda (f) (f f)) call))

 I wasn't able to make this any smaller -- in particular, the `outer`
 parameter is needed. If you try to compile this with `raco make`, it will
 hang, but `raco make --disable-inline` will succeed.

 That's also why `--timeout` didn't help, because it seems to wait for
 compilation to have any effect.

 Sam

 On Tue, Jul 14, 2015 at 6:31 AM Ryan Davis zenspi...@gmail.com wrote:

 I'm tired and not thinking straight, but we just finished running the
 schemer gauntlet and I decided to dip my toes into the 6.2 release. I can't
 get it to run my tests and I need external validation that it's not me doing
 something stupid.

   git clone https://github.com/searbsg/little-schemer
   cd little-schemer/zenspider
   raco test --direct ch*.rkt

 For me, it hangs hard on ch09.rkt, ch10.rkt, and some combo of ch11.rkt
 and beyond. I can run all of ch2*.rkt just fine.

 Additionally, it appears that `raco test --timeout` wasn't fixed after I
 reported it last time. I thought commits went it to address it. --heartbeat
 also appears to do nothing when run against these tests.

 Under the previous racket release:

 10028 % rake test
 time raco test --direct ch*.rkt
 raco test: ch00.rkt
 raco test: (submod ch01.rkt test)
 raco test: (submod ch02.rkt test)
 raco test: (submod ch03.rkt test)
 raco test: (submod ch04.rkt test)
 raco test: (submod ch05.rkt test)
 raco test: (submod ch06.rkt test)
 raco test: (submod ch07.rkt test)
 raco test: (submod ch08.rkt test)
 raco test: (submod ch09.rkt test)
 raco test: (submod ch10.rkt test)
 raco test: (submod ch11.rkt test)
 raco test: (submod ch12.rkt test)
 raco test: (submod ch13.rkt test)
 raco test: (submod ch14.rkt test)
 raco test: (submod ch15.rkt test)
 raco test: (submod ch16.rkt test)
 raco test: (submod ch17.rkt test)
 raco test: (submod ch18.rkt test)
 raco test: (submod ch19.rkt test)
 raco test: (submod ch20.rkt test)
 raco test: (submod ch21.rkt test)
 raco test: (submod ch22.rkt test)
 raco test: (submod ch23.rkt test)
 raco test: (submod ch24.rkt test)
 raco test: (submod ch25.rkt test)
 raco test: (submod ch26.rkt test)
 raco test: (submod ch27.rkt test)
 raco test: (submod ch29.rkt test)
 raco test: (submod ch30.rkt test)
 'done
 909 tests passed

 real0m3.482s
 user0m3.091s
 sys 0m0.354s

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

-- 
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] 6.2 regression in running tests?

2015-07-14 Thread Gustavo Massaccesi
Replacing the line 1758 of optimize.c

-  if ((info-inline_fuel  0)  info-has_nonleaf  !noapp)
+  if ((info-inline_fuel = 0)  info-has_nonleaf  !noapp)

make the problem disappear, but I still don't understand why (dup
rep) is the only combination that creates a problem.

I also want to think about the (info-inline_fuel = 0) in line 1872
and how that interacts with the if (noapp) in line 1876 ...

Gustavo

On Tue, Jul 14, 2015 at 8:38 PM, Gustavo Massaccesi gust...@oma.org.ar wrote:
 I reduced it a little, it's a variation of the old
   ((lambda (x) (x x)) (lambda (x) (x x)))
 but there must be a problem in the inlining fuel.

 In my example, the ´dup´ definition is not necessary, but it makes it
 more clear. It can be copied by hand to the application point.

 I wrapped the example in a 'lambda', to be sure that it should not be
 executed even once. This lambda is not necessary and can be removed.

 #lang racket
 (define dup (lambda (f) (f f)))
 (lambda ()
   (let ([rep (lambda (f) (f f))])
 (dup rep)))

 It's strange that only (dup rep) causes a problem, (dup dup), (rep
 rep) and (rep dup) are ok.

 Gustavo


 On Tue, Jul 14, 2015 at 6:23 PM, Sam Tobin-Hochstadt
 sa...@cs.indiana.edu wrote:
 This appears to be a bug in the inliner, which appears in HEAD as well.

 This program is sufficient to reproduce:

 #lang racket

 (define (Y3 outer)
   (define ((call f) x)
 ((f f) x))
   ((lambda (f) (f f)) call))

 I wasn't able to make this any smaller -- in particular, the `outer`
 parameter is needed. If you try to compile this with `raco make`, it will
 hang, but `raco make --disable-inline` will succeed.

 That's also why `--timeout` didn't help, because it seems to wait for
 compilation to have any effect.

 Sam

 On Tue, Jul 14, 2015 at 6:31 AM Ryan Davis zenspi...@gmail.com wrote:

 I'm tired and not thinking straight, but we just finished running the
 schemer gauntlet and I decided to dip my toes into the 6.2 release. I can't
 get it to run my tests and I need external validation that it's not me doing
 something stupid.

   git clone https://github.com/searbsg/little-schemer
   cd little-schemer/zenspider
   raco test --direct ch*.rkt

 For me, it hangs hard on ch09.rkt, ch10.rkt, and some combo of ch11.rkt
 and beyond. I can run all of ch2*.rkt just fine.

 Additionally, it appears that `raco test --timeout` wasn't fixed after I
 reported it last time. I thought commits went it to address it. --heartbeat
 also appears to do nothing when run against these tests.

 Under the previous racket release:

 10028 % rake test
 time raco test --direct ch*.rkt
 raco test: ch00.rkt
 raco test: (submod ch01.rkt test)
 raco test: (submod ch02.rkt test)
 raco test: (submod ch03.rkt test)
 raco test: (submod ch04.rkt test)
 raco test: (submod ch05.rkt test)
 raco test: (submod ch06.rkt test)
 raco test: (submod ch07.rkt test)
 raco test: (submod ch08.rkt test)
 raco test: (submod ch09.rkt test)
 raco test: (submod ch10.rkt test)
 raco test: (submod ch11.rkt test)
 raco test: (submod ch12.rkt test)
 raco test: (submod ch13.rkt test)
 raco test: (submod ch14.rkt test)
 raco test: (submod ch15.rkt test)
 raco test: (submod ch16.rkt test)
 raco test: (submod ch17.rkt test)
 raco test: (submod ch18.rkt test)
 raco test: (submod ch19.rkt test)
 raco test: (submod ch20.rkt test)
 raco test: (submod ch21.rkt test)
 raco test: (submod ch22.rkt test)
 raco test: (submod ch23.rkt test)
 raco test: (submod ch24.rkt test)
 raco test: (submod ch25.rkt test)
 raco test: (submod ch26.rkt test)
 raco test: (submod ch27.rkt test)
 raco test: (submod ch29.rkt test)
 raco test: (submod ch30.rkt test)
 'done
 909 tests passed

 real0m3.482s
 user0m3.091s
 sys 0m0.354s

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

-- 
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] Rebuild html documentation

2015-07-08 Thread Gustavo Massaccesi
Thanks. I think that the problem was a weird configuration of the
package system. I'm not sure about the steps to reproduce it, but I
reinstalled everything and it's *apparently* fixed.

The problem was that I was editing a .scrbl file of the racket-doc package.

Idea of the main steps, (I'm no sure of the details). In the git
folder (don't try this at home):
* Remove all the packages with raco pkg remove xyz
* And raco pkg remove --auto
* Just in case run git clean -fx (or -fX?)
* Now run nmake win32-as-is
* Install scribble with raco pkg scribble
The problem is that this installs racket-doc from github, because it
is not registered as a package in a folder. So in spite I modify the
local racket-doc copy, raco setup uses the github copy.

I just removed all the packages (again) and ...
* Now run nmake win32-in-places instead of win32-as-is

This register the local racket-doc folder, and that *apparently*
solves the problem.

Gustavo


On Wed, Jul 8, 2015 at 2:39 AM, Matthew Flatt mfl...@cs.utah.edu wrote:
 Running `raco setup` should have worked. Can you describe the steps
 that you tried in more detail (i.e., enough for me to try the same
 thing and see the result)?

 At Tue, 7 Jul 2015 20:31:16 -0300, Gustavo Massaccesi wrote:
 I'm trying a few changes in a .scrbl file of one package and I want to
 rebuild the .html files to be sure that the problem is fixed. I tried:

 raco setup

 and

 raco setup --doc-index

 but the documentation don't change.

 What command should I run?

 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.


[racket-users] Rebuild html documentation

2015-07-07 Thread Gustavo Massaccesi
I'm trying a few changes in a .scrbl file of one package and I want to
rebuild the .html files to be sure that the problem is fixed. I tried:

raco setup

and

raco setup --doc-index

but the documentation don't change.

What command should I run?

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] DrRacket stubbornly indents code as if it were Racket

2015-06-16 Thread Gustavo Massaccesi
You can select the text mode in the menu

  EditModes(near the bottom)Text mode

It disables indentation, but it may disable too many features.

For example it disables also parens matching :( .

And it also disables background syntax expansion, but you can still
use the check syntax button manually.

(Perhaps you can create a no-indent mode, I didn't look at the code.)

Gustavo

On Tue, Jun 16, 2015 at 1:20 AM, Yuhao Dong yd2d...@uwaterloo.ca wrote:
 Greetings Racketeers,

 I'm trying to make my own #lang that has a non-sexp syntax, like Scribble.
 However, the problem is the DrRacket always tries to indent my code as if it
 were Racket, which is extremely unusable and annoying.

 Since changing DrRacket's indenting behaviors seems undocumented, I looked
 at how Scribble did it, and then I put what I thought must be correct code
 here:

 https://github.com/quantum1423/mir/blob/master/lang/reader.rkt

 However, DrRacket still indents my code as if it were Racket, although it
 does turn off syntax highlighting correctly. I added the with-output-to-file
 line to see if the drracket:indentation branch is ever executed, but
 apparently it isn't.

 How does Scribble manage to get DrRacket to indent it in a non-sexp way?

 Thanks!
 Yuhao Dong

 --
 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] disappeeraing binding arrows

2015-05-22 Thread Gustavo Massaccesi
This is a minimized example (after expansions and simplifications):

 #lang racket
(letrec-syntaxes+values ([(c) {lambda (stx)
(let ([x #'0]) x)}])
()
  (c))

This prints correctly 0, but no identifier inside the curly {lambda
...} get any arrow. I guess it's a problem with
letrec-syntaxes+values.

Another similar problem:

#lang racket
(letrec-syntaxes+values ([(c) {lambda (stx) (displayln 5) #'0}])
()
  (c))

This prints correctly 5 and 0, but no identifier inside the curly
{lambda ...} get any arrow. Moreover, when you press the syntax
check button, you get the cryptic error 5.


Gustavo


On Fri, May 22, 2015 at 4:52 PM, Jos Koot jos.k...@gmail.com wrote:
 Hi Alexander
 Thanks for taking notice of my post.
 Yes, it is within the *definition* that the arrows don't show up.
 I apologize if my post wasn't clear.
 Jos


 
 From: Alexander D. Knauth [mailto:alexan...@knauth.org]
 Sent: viernes, 22 de mayo de 2015 21:42
 To: Jos Koot
 Cc: Racket-Users List
 Subject: Re: [racket-users] disappeeraing binding arrows

 Oh, I thought you were talking about the arrows within the *use* of
 stx-case.
 I just realized they don’t work within the *definition* of the second
 version of stx-case.
 That is weird.

 On May 22, 2015, at 3:37 PM, Alexander D. Knauth alexan...@knauth.org
 wrote:

 For me the arrows seem to work fine for both versions.
 I tried it with racket version 6.1.1 and a racket snapshot build version
 6.2.0.3--2015-05-17.
 Which arrows aren’t working for you?

 On May 22, 2015, at 1:40 PM, Jos Koot jos.k...@gmail.com wrote:

 Below two versions of a very stripped version of a macro I have made.
 In version 1 background expansion and check-syntax show binding arrows
 within macro stx-case.
 However, in version 2 the arrows are not shown.
 How come?
 Thanks, Jos

 #lang racket

 (require (for-syntax racket))

 ;;; version 1

 (begin-for-syntax
  (define-syntax (stx-case stx) ; Here background expansion and macro stepper
   (syntax-case stx ()  ; do show binding arrows in stx-case.
((_ stx-expr clause ...)
 (with-syntax
  ((+ (datum-syntax stx '+))
   (- (datum-syntax stx '-))
   (* (datum-syntax stx '*))
   (/ (datum-syntax stx '/)))
#'(syntax-case stx-expr (+ - * /) clause ...))

 (define-syntax (a stx)
  (stx-case stx
   ((_ +) #''plus)
   ((_ -) #''minus)
   ((_ *) #''mult)
   ((_ /) #''div)
   ((_ x) #''x)))

 ;;; version 2

 (define-syntax (b stx)
  (define-syntax (stx-case stx) ; Here background expansion and macro stepper
   (syntax-case stx ()  ; do NOT show binding arrows in stx-case.
((_ stx-expr clause ...)
 (with-syntax
  ((+ (datum-syntax stx '+))
   (- (datum-syntax stx '-))
   (* (datum-syntax stx '*))
   (/ (datum-syntax stx '/)))
#'(syntax-case stx-expr (+ - * /) clause ...)
  (stx-case stx
   ((_ +) #''plus)
   ((_ -) #''minus)
   ((_ *) #''mult)
   ((_ /) #''div)
   ((_ x) #''x)))

 ; Both a and b work correctly:

 (a +)
 (a else)
 (b -)
 (b else)

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


 --
 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] Regular expressions and Unicode categories

2015-05-06 Thread Gustavo Massaccesi
Thanks, I was looking in the reference instead of the guide, and
it has more information but less easy examples.

[Just for reference: (regexp-match #px\\.(?:\\p{N}|\\p{L})+$ zz.1ñ3é) ]

Gustavo


On Wed, May 6, 2015 at 12:08 AM, Evgeny Odegov evgeny-ode...@mail.ru wrote:
 05.05.2015 20:41, Gustavo Massaccesi пишет:

 I was tiring to solve the extended version of a Rosetta code task, but
 I can't find the correct regexp to match accented letters and numbers:

 #lang racket

 (regexp-match #px\\.\\p{L}+$ zz.aBc) ;== '(.aBc)
 (regexp-match #px\\.\\p{L}+$ zz.ñéü) ;== '(.ñéü)
 (regexp-match #px\\.\\p{N}+$ zz.123) ;== '(.123)

 (regexp-match #px\\.(\\p{N}|\\p{L})+$ zz.1ñ3é) ;== '(.1ñ2é é)
 [but I want only '(.1ñ2é)]

 Gustavo


 Look at
 http://docs.racket-lang.org/guide/regexp-clusters.html#%28part._.Non-capturing_.Clusters%29

-- 
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] Regular expressions and Unicode categories

2015-05-05 Thread Gustavo Massaccesi
I was tiring to solve the extended version of a Rosetta code task, but
I can't find the correct regexp to match accented letters and numbers:

#lang racket

(regexp-match #px\\.\\p{L}+$ zz.aBc) ;== '(.aBc)
(regexp-match #px\\.\\p{L}+$ zz.ñéü) ;== '(.ñéü)
(regexp-match #px\\.\\p{N}+$ zz.123) ;== '(.123)

(regexp-match #px\\.(\\p{N}|\\p{L})+$ zz.1ñ3é) ;== '(.1ñ2é é)
[but I want only '(.1ñ2é)]

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] Rosetta Code: Level 1st (that's FIRST) with TCL

2015-05-04 Thread Gustavo Massaccesi
Too early. Tcl is (apparently) first again :(
(I'm not sure how is the correct method to count them.)

http://timb.net/popular-languages.html
# Count Name
1 855 Tcl
2 852 Racket
3 842 Python
4 776 J

In the Rosetta webpage
# Count Name
1 851 Tcl
2 850 Racket
3 826 Python (???)
4 773 J

Gustavo

On Wed, Apr 29, 2015 at 3:57 AM, Jens Axel Søgaard
jensa...@soegaard.net wrote:
 Great news!

 Worth a blog post to follow up on:

 http://blog.racket-lang.org/2013/03/200_25.html
 http://blog.racket-lang.org/2014/11/800.html

 /Jens Axel



 2015-04-29 1:38 GMT+02:00 Tim Brown t...@cityc.co.uk:

 Folks,

 I've just done a quick burst of cherry picking tasks on Rosetta
 Code (www.rosettacode.org). I took a quick look at:
 * http://rosettacode.org/wiki/Category:Tcl
 and
 *  http://rosettacode.org/wiki/Category:Racket

 And they both have the line:
 The following 845 pages are in this category, out of 845 total. 

 I *think* that means that both Tcl and Racket have 845 tasks impemented,
 but short of walking down a printout with a pen (and it's far to late to
 be doing that) -- I do believe that Tcl and Racket are now jointly the
 most popular programming languages on Rosetta Code.

 WELL DONE AND THANKS TO EVERYONE WHO HAS CONTRIBUTED (especially Racket)
 CODE ONTO ROSETTA CODE!

 And many, many thanks to the Racket team for producing a language which
 is now demonstrably as competent as any. (Although we all knew that before
 anyway, didn't we?)

 Tim

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




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

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