Re: [racket-users] html-parsing package 5.0 changes

2018-05-22 Thread Neil Van Dyke
FYI, I made another potentially breaking change to `html-parsing`, and 
so have incremented the major version number, to 6.0.


Sorawee Porncharoenwase found a case in which the parser was doing the 
wrong thing for a real-world example of contemporary HTML.  It turned 
out to be in some 17 year-old "structure recovery" constraints that 
thought HTML `p` elements couldn't be children of `blockquote` 
elements.  I decided to change that in `html-parsing` version 6.0, which 
could easily break some Web scraper code that was based on the previous 
parse involving `blockquote` and `p`.


More generally, with the `html-parsing` package, I'm trying to minimize 
the changes (and effort spent) on that package, while still making an 
effort to respond to problems that people encounter with real-world HTML.


I hope there won't be any further breaking changes.  But, having good 
unit tests for your Web scraper (or other code) will hopefully identify 
any problems without much pain.  Please let me know of any such pains.


http://www.neilvandyke.org/racket/html-parsing/
https://pkgs.racket-lang.org/package/html-parsing


--
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 build unix paths on windows with build-path/convention-type

2018-05-22 Thread Alex Harsanyi
Hi Matthew,

Thanks for clarifying this.

It seems to me that `build-path/convention-type` is very difficult to use 
correctly:  it is very easy for someone working on a Linux machine to just 
use this function with a 'unix convention and plain strings, under the 
assumption that it will work correctly on a Windows machine.   The 
documentation for the function seem imply that it is this easy, but it is 
not.  Even the return value for the function seems to be a "unix-path" if I 
run it with a 'unix convention, but a "path" if I run it with a 'windows 
convention, so `path->string` will not always work on the return type.

Even when it fails, the error message is confusing, as "foo" is in fact a 
valid "path element" :

 > (build-path/convention-type 'unix "foo" "bar")
build-path/convention-type: specified convention incompatible with 
string path element
  path element: "foo"
  convention: 'unix

I would suggest that the documentation for this function is updated to at 
least mention this caveat.   I'm not sure how the error message could be 
improved, but it is confusing as it is.  For me, the following wrapper 
function seems to work OK:

(define (build-path/ct type base . sub)
  (define b-base (string->bytes/utf-8 base))
  (define b-sub (map string->bytes/utf-8 sub))
  (define result (apply build-path/convention-type
type
(bytes->path b-base type)
(map (lambda (b) (bytes->path b type)) b-sub)))
  (bytes->string/utf-8 (path->bytes result)))

BTW, I found this problem, when working on the "frog" blog generator:  its 
unit tests fail on windows because it generates windows style paths and 
compares them to unix style path strings and it also generates the internal 
links for the HTML  pages using the Windows convention.

Best regards,
Alex,

On Tuesday, May 22, 2018 at 7:56:21 PM UTC+8, Matthew Flatt wrote:
>
> To build paths for a convention other than the current machine's 
> convention, you have to work in bytes instead of strings. 
>
>   (define (bs->p bs) (bytes->path bs 'unix)) 
>   (build-path/convention-type 'unix (bs->p #"/") (bs->p #"foo") (bs->p 
> #"bar")) 
>
> Roughly, strings don't work, because they have to be converted to bytes 
> using the locale's default encoding. Although strings are allowed for 
> the current platform's convention on the assumption that the current 
> locale's encoding is the right one, we've avoided building in any 
> assumption about the encoding for the other convention. 
>
> At Tue, 22 May 2018 03:51:03 -0700 (PDT), Alex Harsanyi wrote: 
> > I am trying to create a path named "/foo/bar" in Racket on a windows 
> > machine.  build-path produces "/foo\\bar" and build-path/convention-type 
> > does not seem to work: 
> > 
> >  > (path->string (build-path "/" "foo" "bar")) 
> > "/foo\\bar" ; I am running on a Windows machine, so this is expected 
> > > (path->string (build-path/convention-type 'windows "/" "foo" 
> "bar")) 
> > "/foo\\bar" 
> > > (path->string (build-path/convention-type 'unix "/" "foo" "bar")) 
> > ; build-path/convention-type: specified convention incompatible with 
> > string path element 
> > ;   path element: "/" 
> > ;   convention: 'unix 
> > > (path->string (build-path/convention-type 'unix "/foo" "bar")) 
> > ; build-path/convention-type: specified convention incompatible with 
> > string path element 
> > ;   path element: "/foo" 
> > ;   convention: 'unix 
> > 
> > It seems that I cannot specify the root path, "/", when the convention 
> type 
> > is set to 'unix.  Technically, the error is correct, as "/" is not a 
> valid 
> > directory name, but I am not sure what to replace it with. The empty 
> string 
> > does not work either.   The unix convention type seems to be more strict 
> > than the windows one: 
> > 
> > > (path->string (build-path/convention-type 'windows "./foo/" 
> "bar")) 
> > "./foo/bar" 
> > > (path->string (build-path/convention-type 'unix "./foo/" "bar")) 
> > ; build-path/convention-type: specified convention incompatible with 
> > string path element 
> > ;   path element: "./foo/" 
> > ;   convention: 'unix 
> > 
> > Is this a bug, or I am missing something? 
> > 
> > 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...@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] Announcing Event-lang

2018-05-22 Thread Matthew Butterick
I'm sure I'm not the only one who would like to see these (and other examples 
you have handy) added to your `event-lang` docs.


> On May 22, 2018, at 7:29 AM, Eric Griffis  wrote:
> 
> Here's a variety of small examples.

-- 
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] Announcing Event-lang

2018-05-22 Thread Eric Griffis
On Mon, May 21, 2018 at 11:21 AM Jay McCarthy 
wrote:

> This is very cute! Can you point to a fun example? I looked through
> the repo and it wasn't obvious where some tests and examples were.
>
> Jay
>

Here's a variety of small examples.

Sometimes, I just want to wait until a bunch of stuff is done:

  > (sync
 (async-void*
  (append
   (for/list ([i 10])
 (thread (λ () (channel-put ch i
   (for/list ([_ 10])
 (thread (λ () (write (channel-get ch
  1594302867

Sometimes, I want to do something more than once:

  > (define (channel-dup-evt cs v)
  (async-void* (map (curryr channel-put-evt v) cs)))

With some background getters,

  > (define cs (build-list 5 (λ _ (make-channel
  > (for ([c cs] [i 5])
  (thread (λ () (writeln (cons i (channel-get c))

it's ready for synchronization.

  > (sync (channel-dup-evt cs 'X))
  (1 . X)
  (3 . X)
  (0 . X)
  (2 . X)
  (4 . X)

The natural numbers:

  > (define nats
  (let ([n 0]) (pure (begin0 n (set! n (add1 n))

This event acts like a generator.

  > (sync nats)
  0
  > (sync nats)
  1
  > (sync nats)
  2

nats is handy for generating indices and unique keys in bulk through
repetition.

  > (sync (event-list* (make-list 4 nats)))
  '(3 4 5 6)

It's always fun to implement the fibonacci sequence:

  > (define (naive-fib n)
  (case n
[(0) (pure 0)]
[(1) (pure 1)]
[else (fmap + (naive-fib (- n 1)) (naive-fib (- n 2)))]))

Of course, the naive implementation is very slow.

  > (time (sync (naive-fib 29)))
  cpu time: 5826 real time: 5831 gc time: 1004
  514229

This one:

  > (define fib
  (let ([a 1] [b 0])
(pure (begin0 b (set!-values (a b) (values (+ a b) a))

is much faster.

  > (time (last (sync (event-list* (make-list 30 fib)
  cpu time: 1 real time: 1 gc time: 0
  514229

nats and fib can be combined to build an index:

  > (define fibs (make-hash))
  > (sync
 (async-void*
  (make-list 30 (fmap (curry hash-set! fibs) nats fib
  > (hash-ref fibs 29)
  514229
  > (hash-ref fibs 15)
  610

Promises are pretty easy, too:

  > (define (promise thunk)
  (define result #f)
  (bind (thread (λ ()
  (define vs (call-with-values thunk list))
  (set! result (pure (apply values vs)
(λ _ result)))

The results are memoized so multiple syncs don't replay side effects.

  > (define p (promise (λ () (writeln 123) 4)))
  123
  > (sync p)
  4
  > (sync p)
  4

My personal favorite is more practical than fun:

  > (define (dispatch m ms [default void-mediator])
  (define (dispatch-put m0)
(bind-put
 (make-mediator)
 (λ _ (λ (k . vs) (say* (hash-ref ms k default) vs m0)
  (event-let ([m0 (accept m)]) (offer m0 (dispatch-put m0

Without getting into what mediators are, this one forwards a message from m
 to
an element of hash ms. If the message is a list and the first element is a
key
of ms, the rest of the message is delivered to the keyed element. The
dispatch
event may finish before the message is delivered, but the sender and
receiver
are guaranteed to synchronize on each other. Getting this right was hard.

Most of my work with event-lang is in solving hairy synchronization problems
like this, so I felt I should sneak one in.

Eric

-- 
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] Using Racket's raco on on Guix(SD)

2018-05-22 Thread Christopher Lemmer Webber
Hello all!  Sorry for the cross-post, but I've been doing more
development in Racket lately from GuixSD... and who wouldn't want a
scheme-based distribution and a scheme language's tooling to get along
better?

Unfortunately when I try to install packages with "raco pkg install"
I get errors like the following:

open-output-file: cannot open output file
  path: 
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/racket/compiled/tmp15189875891518987589961
  system error: Read-only file system; errno=30
  compilation context...:
   /home/cwebber/.racket/6.11/pkgs/br-parser-tools-lib/br-parser-tools/lex.rkt
   /home/cwebber/sandbox/beautiful-racket/bf/parser.rkt
  context...:
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/racket/private/more-scheme.rkt:261:28
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/racket/file.rkt:199:0:
 call-with-atomic-output-file20
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:363:0:
 compile-zo*
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:572:26
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:564:42
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:635:0:
 compile-root
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:688:15
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:723:0:
 ormap-strict
   [repeats 6 more times]
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:635:0:
 compile-root
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:688:15
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:635:0:
 compile-root
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:782:4:
 compilation-manager-load-handler
   standard-module-name-resolver
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/syntax/modcode.rkt:225:0:
 get-module-code82
   
/gnu/store/wnqdzv3f0i86nk3nq15aavpb7kg7fbwx-racket-6.11/share/racket/collects/compiler/cm.rkt:363:0:
 compile-zo*
   ...

I seem to remember a couple of packages failing altogether, though in
the present moment I think the result is bad performance due to not
being properly compiled, but I'm not really sure.

My reading of this is that for whatever reason, Racket is trying to
compile the files in Racket's installed directory, but that's read-only
because it's installed as part of the system (in an immutable package
collection, at that).

My guess is that the Guix package has something misconfigured so that
this compilation directory is set to the wrong place, but what?

Thanks!

-- 
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 build unix paths on windows with build-path/convention-type

2018-05-22 Thread Matthew Flatt
To build paths for a convention other than the current machine's
convention, you have to work in bytes instead of strings.

  (define (bs->p bs) (bytes->path bs 'unix))
  (build-path/convention-type 'unix (bs->p #"/") (bs->p #"foo") (bs->p #"bar"))

Roughly, strings don't work, because they have to be converted to bytes
using the locale's default encoding. Although strings are allowed for
the current platform's convention on the assumption that the current
locale's encoding is the right one, we've avoided building in any
assumption about the encoding for the other convention.

At Tue, 22 May 2018 03:51:03 -0700 (PDT), Alex Harsanyi wrote:
> I am trying to create a path named "/foo/bar" in Racket on a windows 
> machine.  build-path produces "/foo\\bar" and build-path/convention-type 
> does not seem to work:
> 
>  > (path->string (build-path "/" "foo" "bar")) 
> "/foo\\bar" ; I am running on a Windows machine, so this is expected
> > (path->string (build-path/convention-type 'windows "/" "foo" "bar"))
> "/foo\\bar"
> > (path->string (build-path/convention-type 'unix "/" "foo" "bar"))
> ; build-path/convention-type: specified convention incompatible with 
> string path element
> ;   path element: "/"
> ;   convention: 'unix
> > (path->string (build-path/convention-type 'unix "/foo" "bar"))
> ; build-path/convention-type: specified convention incompatible with 
> string path element
> ;   path element: "/foo"
> ;   convention: 'unix
> 
> It seems that I cannot specify the root path, "/", when the convention type 
> is set to 'unix.  Technically, the error is correct, as "/" is not a valid 
> directory name, but I am not sure what to replace it with. The empty string 
> does not work either.   The unix convention type seems to be more strict 
> than the windows one:
> 
> > (path->string (build-path/convention-type 'windows "./foo/" "bar"))
> "./foo/bar"
> > (path->string (build-path/convention-type 'unix "./foo/" "bar"))
> ; build-path/convention-type: specified convention incompatible with 
> string path element
> ;   path element: "./foo/"
> ;   convention: 'unix
> 
> Is this a bug, or I am missing something?
> 
> 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] Racket 7 multi core support

2018-05-22 Thread Sam Tobin-Hochstadt
Just like with current Racket, both futures and places run in a single
process.

Sam

On Tue, May 22, 2018, 2:39 AM Piyush Katariya 
wrote:

> Thanks Sam.
>
> When you say Racket 7's "cs" variant can use Future and Places to leverage
> multiple CPU cores, is it one OS process or multiple ?
>
> --
> 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] How to build unix paths on windows with build-path/convention-type

2018-05-22 Thread Alex Harsanyi
I am trying to create a path named "/foo/bar" in Racket on a windows 
machine.  build-path produces "/foo\\bar" and build-path/convention-type 
does not seem to work:

 > (path->string (build-path "/" "foo" "bar")) 
"/foo\\bar" ; I am running on a Windows machine, so this is expected
> (path->string (build-path/convention-type 'windows "/" "foo" "bar"))
"/foo\\bar"
> (path->string (build-path/convention-type 'unix "/" "foo" "bar"))
; build-path/convention-type: specified convention incompatible with 
string path element
;   path element: "/"
;   convention: 'unix
> (path->string (build-path/convention-type 'unix "/foo" "bar"))
; build-path/convention-type: specified convention incompatible with 
string path element
;   path element: "/foo"
;   convention: 'unix

It seems that I cannot specify the root path, "/", when the convention type 
is set to 'unix.  Technically, the error is correct, as "/" is not a valid 
directory name, but I am not sure what to replace it with. The empty string 
does not work either.   The unix convention type seems to be more strict 
than the windows one:

> (path->string (build-path/convention-type 'windows "./foo/" "bar"))
"./foo/bar"
> (path->string (build-path/convention-type 'unix "./foo/" "bar"))
; build-path/convention-type: specified convention incompatible with 
string path element
;   path element: "./foo/"
;   convention: 'unix

Is this a bug, or I am missing something?

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.


Re: [racket-users] Racket 7 multi core support

2018-05-22 Thread Piyush Katariya
Thanks Sam.

When you say Racket 7's "cs" variant can use Future and Places to leverage 
multiple CPU cores, is it one OS process or multiple ? 

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