[racket-users] racket-money email list - discussing commercial use of Racket

2018-03-16 Thread Neil Van Dyke
To encourage discussion among people who are using Racket commercially 
(or interested in that topic), who might speak more candidly in a forum 
that's less-public than "racket-users"...


Some of us are trying out an unofficial "racket-money" email list that 
is not archived on the Web.  The idea is that, to see a post, you have 
to be subscribed at the time that the post is sent.  An expectation is 
that people will respect that discussion on the list is not to be 
quoted/posted/mirrored/etc. elsewhere.  We'll see.


If you want to subscribe, one way is to send a blank email to: 
racket-money+subscr...@googlegroups.com


A human moderator will approve all subscribe requests that don't look 
like bots.  Posts to the list are NOT moderated, and we know that 
everyone will conduct ourselves in a constructive and inclusive manner 
(inclusive, except for bots -- down with bots!).


After you're subscribed, please feel encouraged to post to the list, 
introducing yourself.



(If you see I messed up anything in the error-prone Google Groups setup, 
or if you'd like to volunteer to be one of the moderators who approves 
subscription requests in a timely manner, please email me.)


(Small Print: Our stable of lawyers advise us that we can't guarantee 
that the list will be as private as we intend.  That said, our lawyers 
are an imposing bunch, as they sharpen their legal pads, in a manner 
just short of the legal threshold for menacingly, and I'm sure there 
won't be any need for unpleasantness.)


--
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] Storing JSON into PostgreSQL 10

2018-03-16 Thread Ryan Culpepper

On 03/16/2018 11:28 PM, David Storrs wrote:
I'm noticing that when I store jsexpr?s into PostgreSQL 10 I end up with 
them as strings, not as actual JSONB data.  I've read the docs and tried 
every combination of typecasting / methods of writing that I can think 
of but nothing ends up working.  Can anyone point me to the right way?


Here's an example:

  (require db)
  (define c (dsn-connect 'pg))
  (query c "create temporary table foo (i integer, j jsonb)")
  (query-exec c "insert into foo (i,j) values ($1,$2)"
  1 "hello")
  (query-exec c "insert into foo (i,j) values ($1,$2)"
  2 (hash 'a 1 'b 2))
  (query-rows c "select * from foo")
  ;; => '(#(1 "hello") #(2 #hasheq((a . 1) (b . 2
  (query-rows c "select i, j->'b' from foo")
  ;; => '(#(1 #) #(2 2))

It's a little trickier if you have json that's already in string form 
and want it to be parsed on the PostgreSQL side:


  (query-value c "select cast($1 as jsonb)" "{\"a\":1}") ;; WRONG
  ;; => "{\"a\":1}"
  (query-value c "select cast($1::text as jsonb)" "{\"a\":1}") ;; RIGHT
  ;; => '#hasheq((a . 1))
  (query-value c "select $1::text::json" "{\"a\":1}") ;; RIGHT
  ;; => '#hasheq((a . 1))

The inner "cast" (::) actually gets interpreted as a type ascription for 
the parameter.


Finally, PostgreSQL treats (some?) type names as conversion functions, 
so you can also do this:


  (query-value c "select json($1::text)" "{\"a\":1}") ;; RIGHT
  ;; => '#hasheq((a . 1))

I hope that helps. Let me know if you have an example that isn't working 
as you expect.


Ryan

--
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] Storing JSON into PostgreSQL 10

2018-03-16 Thread Philip McGrath
I suspect this may be an issue with your PostgreSQL schema. Racket uses the
`jsexpr?` type for both the types "JSON" and "JSONB" at the PostgreSQL
level.[1] Can you confirm that your column is defined with the "JSONB" type?

[1]
http://docs.racket-lang.org/db/sql-types.html#%28part._postgresql-types%29

-Philip

On Fri, Mar 16, 2018 at 5:28 PM, David Storrs 
wrote:

> I'm noticing that when I store jsexpr?s into PostgreSQL 10 I end up with
> them as strings, not as actual JSONB data.  I've read the docs and tried
> every combination of typecasting / methods of writing that I can think of
> but nothing ends up working.  Can anyone point me to the right way?
>
> --
> 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] Storing JSON into PostgreSQL 10

2018-03-16 Thread David Storrs
I'm noticing that when I store jsexpr?s into PostgreSQL 10 I end up with
them as strings, not as actual JSONB data.  I've read the docs and tried
every combination of typecasting / methods of writing that I can think of
but nothing ends up working.  Can anyone point me to the right way?

-- 
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] struct-copy question

2018-03-16 Thread Kevin Forchione


> On Mar 16, 2018, at 2:38 PM, Kevin Forchione  wrote:
> 
> Hi guys, 
> I’ve noticed that struct-copy doesn’t appear to work when fields are defined 
> with #:auto. So this leads to my question, which may not be answerable since 
> it would presumably be used to fix struct-copy, but is there a way to 
> retrieve a list of struct fields for a struct? I have a feeling there is some 
> macro work going on and that the struct isn’t really “aware” of its field 
> names. If that’s the case, wouldn’t it be interesting if the macro included 
> building a function that would return these names as a symbols list? :) 

Actually, what wold be interesting would be a list of lists, containing the 
getters and setters for the struct. :) 

Kevin

-- 
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] struct-copy question

2018-03-16 Thread Kevin Forchione
Hi guys, 
I’ve noticed that struct-copy doesn’t appear to work when fields are defined 
with #:auto. So this leads to my question, which may not be answerable since it 
would presumably be used to fix struct-copy, but is there a way to retrieve a 
list of struct fields for a struct? I have a feeling there is some macro work 
going on and that the struct isn’t really “aware” of its field names. If that’s 
the case, wouldn’t it be interesting if the macro included building a function 
that would return these names as a symbols list? :) 

Thanks, 
Kevin

-- 
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] Parameterized Redex models

2018-03-16 Thread 'Leandro Facchinetti' via Racket Users
As far as I understand, your ‘length-ok’ is implementing in Redex the ‘(<= 
(length ___) ___)’ I had in my ‘side-condition’. But I can’t see how it 
addresses two important features from my original code: (1) ‘k’ is 
parameterizable, and its value influences whether a list is valid or not; 
and (2) the non-terminal ‘t’ could appear in patterns, for example, in a 
metafunction contract. This last one is essential, because using ‘t’ in a 
contract enforces a data structure invariant—‘t’ can’t be longer than 
‘k’—and I can’t trust all callers of my metafunctions to check ‘length-ok’ 
themselves. In some cases, they wouldn’t even be able to do it; for 
example, suppose ‘t’ is part of the ‘domain’ of a ‘reduction-relation’ and 
I use it with ‘apply-reduction-relation*’, then there’s no way to access 
intermediary states and check if they preserve the invariant.

-- 
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 opens too many files

2018-03-16 Thread 'Paulo Matos' via Racket Users


On 16/03/18 13:52, Matthew Flatt wrote:
>> But even more surprised that given I only open one
>> open (the null) port for stdout and stderr I still get the system error.
> 
> There's no avoiding an OS-level file descriptor for each of stdin,
> stdout, and stderr. Even if you supply an existing file-stream port, it
> will be `dup`ed internally, and `open-output-nowhere` is not close
> enough to the core for there to be a special case.
> 

Understood.
At the moment this certainly does feel like it's not a problem but as
number of cores per machine increase, it's certainly possible that one
might want to have a larger number of places running simultaneously.

At least it seems I can catch the exception and present the error nicely
to the user.

Thanks,

-- 
Paulo Matos

-- 
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] Parameterized Redex models

2018-03-16 Thread Robby Findler
If you want to stay inside redex-land, you have to do something like the
code below, where you use typesetting to turn uses of length-ok (in other
relations) into something like "#(l) = k".

hth,
Robby

#lang racket
(require redex)

(define-term k 3)

(define-language L)

(define-judgment-form L
  #:mode (length-ok I I)
  #:contract (length-ok (any ...) natural)

  [
   (length-ok () 0)]

  [(length-ok (any_2 ...) ,(- (term natural_k) 1))
   ---
   (length-ok (any_1 any_2 ...) natural_k)])


(test-judgment-holds (length-ok (1 2 3) k))
(test-results)




On Fri, Mar 16, 2018 at 7:44 AM, 'Leandro Facchinetti' via Racket Users <
racket-users@googlegroups.com> wrote:

>
> But I clearly don’t get what you really want so I will abandon this one.
>>
>> Good luck — Matthias
>>
>
> Thanks for trying, talking to you is always instructive 😀
>
> For people that hasn’t abandoned this one: I decided to bite the bullet
> and thread the ‘metaparameter’ in my definitions. This will allow me to
> re-enable the cache, and I’m interested in measuring how this impacts
> performance. (I’m not benchmarking these models, I know that isn’t Redex
> purpose, but there are some small programs that are beyond the reach of my
> models because they take too long to complete.) In the process I found a
> case that I can’t express: in my language definition I have a production
> that means “a list of maximum size ‘k’”, which I express with a
> side-condition. There is no way to *thread parameters* into ‘redex-match?’
> and pattern matching in general, so I have to turn off this verification.
>
> The problem below is a minimal working example to illustrate my use case.
> Either I have to remove the ‘side-condition’ for ‘t’ or turn off the cache:
>
> #lang racket
> (require redex)
>
> (define k (make-parameter 0))
>
> (define-language L
>   [t ::= (side-condition (name t [_ ...]) (<= (length (term t)) (k)))])
>
> (caching-enabled? #f)
>
> (displayln (redex-match? L t (term []))) ;; => #t
> (displayln (redex-match? L t (term [a]))) ;; => #f
> (displayln (redex-match? L t (term [a b]))) ;; => #f
>
> (parameterize ([k 1])
>   (displayln (redex-match? L t (term []))) ;; => #t
>   (displayln (redex-match? L t (term [a]))) ;; => #t
>   (displayln (redex-match? L t (term [a b]))) ;; => #f
>   )
>
> --
> 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] places opens too many files

2018-03-16 Thread Matthew Flatt
At Fri, 16 Mar 2018 13:30:07 +0100, "'Paulo Matos' via Racket Users" wrote:
> I was playing around with places and decided to try to spawn 200 places.
> [...]
> Is there anything I can do to avoid this? Which files are actually being
> created? And 200 is not a very large number...

This is a limitation of places. They're heavyweight enough that 200
ends up counting as a very large number of them.

> To my surprise this happened:
> dynamic-place: stderr pipe failed
>   system error: Too many open files; errno=24
> 
> I am actually surprised that I get an error based on dynamic-place
> instead of place*.

Yes, that's not great. But in contrast to argument errors,
resource-exhaustion errors are often difficult to tie to a suitable
source. It's a little lucky that the messages says "place" at all,
since he "too many open files" error could just as easily happen when
trying to load the place's initial code or trying to search the
filesystem for a module.

> But even more surprised that given I only open one
> open (the null) port for stdout and stderr I still get the system error.

There's no avoiding an OS-level file descriptor for each of stdin,
stdout, and stderr. Even if you supply an existing file-stream port, it
will be `dup`ed internally, and `open-output-nowhere` is not close
enough to the core for there to be a special case.

-- 
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] Parameterized Redex models

2018-03-16 Thread 'Leandro Facchinetti' via Racket Users


> But I clearly don’t get what you really want so I will abandon this one. 
>
> Good luck — Matthias 
>

Thanks for trying, talking to you is always instructive 😀

For people that hasn’t abandoned this one: I decided to bite the bullet and 
thread the ‘metaparameter’ in my definitions. This will allow me to 
re-enable the cache, and I’m interested in measuring how this impacts 
performance. (I’m not benchmarking these models, I know that isn’t Redex 
purpose, but there are some small programs that are beyond the reach of my 
models because they take too long to complete.) In the process I found a 
case that I can’t express: in my language definition I have a production 
that means “a list of maximum size ‘k’”, which I express with a 
side-condition. There is no way to *thread parameters* into ‘redex-match?’ 
and pattern matching in general, so I have to turn off this verification.

The problem below is a minimal working example to illustrate my use case. 
Either I have to remove the ‘side-condition’ for ‘t’ or turn off the cache:

#lang racket
(require redex)

(define k (make-parameter 0))

(define-language L
  [t ::= (side-condition (name t [_ ...]) (<= (length (term t)) (k)))])

(caching-enabled? #f)

(displayln (redex-match? L t (term []))) ;; => #t
(displayln (redex-match? L t (term [a]))) ;; => #f
(displayln (redex-match? L t (term [a b]))) ;; => #f

(parameterize ([k 1])
  (displayln (redex-match? L t (term []))) ;; => #t
  (displayln (redex-match? L t (term [a]))) ;; => #t
  (displayln (redex-match? L t (term [a b]))) ;; => #f
  )

-- 
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] places opens too many files

2018-03-16 Thread 'Paulo Matos' via Racket Users
Hi,

I was playing around with places and decided to try to spawn 200 places.

#lang racket


(define (kaboom)

  (define null-port (open-output-nowhere))

  (define ps
(for/list ([i (in-range 200)])
  (define-values (p _1 _2 _3)
(place* #:in #f
#:out null-port
#:err null-port
pch

(sleep 10)))
  p))

  (for ([p ps])
(place-wait p)))



To my surprise this happened:
dynamic-place: stderr pipe failed
  system error: Too many open files; errno=24


I am actually surprised that I get an error based on dynamic-place
instead of place*. But even more surprised that given I only open one
open (the null) port for stdout and stderr I still get the system error.

Is there anything I can do to avoid this? Which files are actually being
created? And 200 is not a very large number...

-- 
Paulo Matos

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