Re: [racket-users] Racket performance tips

2016-01-17 Thread Brian Adkins
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 runtim

Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Alexis King
Perfect, that works great, thank you! It looks like the precedence works out such that I could do $1::text::inet and have it work properly, which is clean enough for my needs. > On Jan 17, 2016, at 16:39, Marc Burns wrote: > > You can cast first to a supported type: > > (query-exec conn "INSERT

Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Jon Zeppieri
Ah, that is a better idea. > On Jan 17, 2016, at 7:39 PM, Marc Burns wrote: > > You can cast first to a supported type: > > (query-exec conn "INSERT INTO some_table (ip) VALUES (inet ($1 ::text))" > client-ip) > >> On 2016-01-17 7:35 PM, Alexis King wrote: >> I would like to avoid interpolat

Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Jon Zeppieri
I sympathize, but using a prepared statement parameter requires support for the type of the parameter. If the library doesn't support it, you'll need to use strings (and escape them appropriately, though it looks like the library doesn't provide a string-escaping function), or else patch the lib

Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Marc Burns
You can cast first to a supported type: (query-exec conn "INSERT INTO some_table (ip) VALUES (inet ($1 ::text))" client-ip) On 2016-01-17 7:35 PM, Alexis King wrote: I would like to avoid interpolating into a query if at all possible, given that this string is not something I control. I could

Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Alexis King
I would like to avoid interpolating into a query if at all possible, given that this string is not something I control. I could be very careful about validating or sanitizing it, but this is a pretty textbook use case for parameterized queries. > On Jan 17, 2016, at 16:19, Jon Zeppieri wrote: >

Re: [racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Jon Zeppieri
How about: (query-exec conn (format "INSERT INTO some_table (ip) VALUES (inet '~a')" client-ip)) On Sun, Jan 17, 2016 at 6:35 PM, Alexis King wrote: > The DB docs for SQL type conversions[1] note that not all Postgres types > are supported by Racket, and it recommends using a cast to work around

[racket-users] Store value with unsupported type in Postgres?

2016-01-17 Thread Alexis King
The DB docs for SQL type conversions[1] note that not all Postgres types are supported by Racket, and it recommends using a cast to work around this. It even uses the inet type as an example right at the start of the page. However, I want to store an inet value in my database, not query an inet val

Re: [racket-users] Racket performance tips

2016-01-17 Thread Jon Zeppieri
However, I don't think string representation is the issue, so long as we're talking about the performance of string-trim. Racket's string-trim is written for flexibility. It allows you to trim the left side, the right side, or both sides of the string, and it allows you to trim characters matching

Re: [racket-users] Racket performance tips

2016-01-17 Thread Jon Zeppieri
MRI (the main ruby interpreter) has an odd string representation that's optimized for shorter strings. There's some info here: [ http://patshaughnessy.net/2012/1/4/never-create-ruby-strings-longer-than-23-characters]. The type is defined here: [ https://github.com/ruby/ruby/blob/af18eafc44bb3bb6aff

Re: [racket-users] Racket performance tips

2016-01-17 Thread Robby Findler
Do we know if ruby represents strings the same way Racket does? The representation in C clearly admits more efficient implementations of relevant operations here, and Ruby's might too. Robby On Sun, Jan 17, 2016 at 2:00 PM, Jon Zeppieri wrote: > My string-trim uses unsafe ops, but I'm pretty su

Re: [racket-users] Racket performance tips

2016-01-17 Thread Jon Zeppieri
My string-trim uses unsafe ops, but I'm pretty sure it's safe. The (safe) string-length at the start ensures we're using a string. The rest are indexing and fixnum arithmetic on integers that are guaranteed to be valid indices of the string. Still, if you don't like this, replace the unsafe ops

Re: [racket-users] Racket performance tips

2016-01-17 Thread Brian Adkins
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 particula

Re: [racket-users] Racket performance tips

2016-01-17 Thread Alex Knauth
> On Jan 17, 2016, at 2:50 PM, 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%. Would converting this into a `bytes-trim` function that only works with byte-s

Re: [racket-users] Racket performance tips

2016-01-17 Thread Brian Adkins
On Sunday, January 17, 2016 at 10:09:36 AM UTC-5, Jon Zeppieri wrote: > Oops: that final else was wrong. If all we encounter in the string is > whitespace, the result is the empty string, not the input string, so: > > > ;; === > > (require racket/unsafe/ops) > > > (define (string-trim s) >  

Re: [racket-users] How can I build up the #:usage-help string dynamically in racket lang's (command-line …) function?

2016-01-17 Thread Jon Zeppieri
I think you'll need to use parse-command-line, instead of command-line. -J On Sun, Jan 17, 2016 at 7:51 AM, Pieter Breed wrote: > Hi All, > > (I'm cross-posting this from StackOverflow) > http://stackoverflow.com/q/34837318/24172 > > I have this code: > > (define s1 "aoeu") > > (define command

Re: [racket-users] Racket performance tips

2016-01-17 Thread Jon Zeppieri
Oops: that final else was wrong. If all we encounter in the string is whitespace, the result is the empty string, not the input string, so: ;; === (require racket/unsafe/ops) (define (string-trim s) (define len (string-length s)) (let loop ([i 0]) (cond [(unsafe-fx< i len) (co

[racket-users] How can I build up the #:usage-help string dynamically in racket lang's (command-line …) function?

2016-01-17 Thread Pieter Breed
Hi All, (I'm cross-posting this from StackOverflow) http://stackoverflow.com/q/34837318/24172 I have this code: (define s1 "aoeu") (define command (command-line #:usage-help s1 #:args (op) op)) It fails with "command-line: #:usage-help clause contains non-string." If I replace the re