Re: [racket-users] Re: appending files
On Fri, Jan 29, 2016 at 7:04 PM, Scotty Cwrote: > > > question for you all. right now i use modulo on my bignums. i know i > > > can't do that to a byte string. i'll figure something out. if any of > > > you know how to do this, can you post a method? > > > > > > > I'm not sure what your asking exactly. > > i'm talking about getting the hash index of a key. see my key is a bignum > and i get the hash index with (modulo key 611). so i either need to > turn the key (which will be a byte string) into a number. stuff that right > in where i have key. or i replace modulo. Sorry -- I haven't been following this thread closely, so I apologize if this question was already answered: Did you implement your own hash tables, or are you using Racket's built-in hashes? Because if you're using the built-in ones, there's no reason to do this. You just use your object (a bignum, a byte string, or anything else) as the key. (The hash code is generated by `equal-hash-code`, but you don't have to call it yourself. The hash implementation does that.) However, if you have implemented your own, you can still call `equal-hash-code` on your byte string. That will give you an exact integer, and you can then call modulo (or remainder) on that. -Jon -- 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: appending files
On Fri, Jan 29, 2016 at 7:45 PM, Scotty Cwrote: > > my plan right now is to rework my current hash so that it runs byte > strings instead of bignums. > > i have a new issue. i wrote my data as char and end records with 'return. > i use (read-line x 'return) and the first record is 15 char. when i use > (read-line-bytes x 'return) i get 23 byte. i have to assume that my old > assumption that an 8 bit char would write to disk as 8 bits is incorrect? > > from documentation on read-char > Reads a single character from in—which may involve reading several bytes > to UTF-8-decode them into a character > > i get the feeling that i will need to read the entire file as i used to > read it taking each record and doing the following: > convert the string record to a bignum record > convert the bignum record into a byte string > write the byte string to a new data file > > does that seem right? I don't know for sure, because I don't know what your file format is like (apologies again, if I missed it; I *did* realize after I sent my last message that you are using a custom hash table). But, if you're just taking the first N bytes of a record and using that as your key, then there's no reason to go through a bignum. You can read bytes (as opposed to characters) from an input port. Just use `read-bytes` or one of its variants. -Jon -- 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 performance tips
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 with the corresponding safe ones. It will still be much faster than the built-in version. > On Jan 17, 2016, at 2:54 PM, Brian Adkinswrote: > >> 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. > > -- > 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 performance tips
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 an arbitrary regexp. Ruby's String#strip, on the other hand, trims whitespace characters from both sides of the string. If you want to trim only the left side, you use String#lstrip. The right side? String#rstrip. (And then there are in-place and non-mutating versions of each.) If you want to trim something other than whitespace you use something else. My string-trim is much faster than Racket's built-in one, because it's completely inflexible, like Ruby's String#strip. Also, because it doesn't use regexps, it doesn't have another layer of interpretation -- and the whole thing is visible to the JIT (though I don't know how much difference that makes in this case). -Jon On Sun, Jan 17, 2016 at 3:08 PM, Robby Findler <ro...@eecs.northwestern.edu> wrote: > 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 <zeppi...@gmail.com> wrote: > > 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 with the > corresponding safe ones. It will still be much faster than the built-in > version. > > > >> On Jan 17, 2016, at 2:54 PM, Brian Adkins <lojicdot...@gmail.com> > 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. > >> > >> -- > >> 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 performance tips
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/af18eafc44bb3bb6aff78f244a67b807500e3e9f/include/ruby/ruby.h#L979 ]. -J On Sun, Jan 17, 2016 at 3:08 PM, Robby Findler <ro...@eecs.northwestern.edu> wrote: > 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 <zeppi...@gmail.com> wrote: > > 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 with the > corresponding safe ones. It will still be much faster than the built-in > version. > > > >> On Jan 17, 2016, at 2:54 PM, Brian Adkins <lojicdot...@gmail.com> > 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. > >> > >> -- > >> 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] Store value with unsupported type in Postgres?
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 Kingwrote: > 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 value out, and I can’t figure out what set of casts I need for > the right coercion to take place. > > My query looks like this: > > (query-exec conn "INSERT INTO some_table (ip) VALUES ($1)" client-ip) > > Attempting to execute that query gives me the following error: > > query-exec: unsupported type > type: inet > typeid: 869 > > Is there any way to annotate this so that I can insert into that table? > > [1]: http://docs.racket-lang.org/db/sql-types.html > > -- > 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] Store value with unsupported type in Postgres?
Ah, that is a better idea. > On Jan 17, 2016, at 7:39 PM, Marc Burns <m4bu...@uwaterloo.ca> 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 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 <zeppi...@gmail.com> wrote: >>> >>> How about: (query-exec conn (format "INSERT INTO some_table (ip) VALUES >>> (inet '~a')" client-ip)) > > -- > 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] Store value with unsupported type in Postgres?
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 library to provide support. > On Jan 17, 2016, at 7:35 PM, Alexis King <lexi.lam...@gmail.com> 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 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 <zeppi...@gmail.com> wrote: >> >> How about: (query-exec conn (format "INSERT INTO some_table (ip) VALUES >> (inet '~a')" client-ip)) > -- 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 can I build up the #:usage-help string dynamically in racket lang's (command-line …) function?
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 Breedwrote: > 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 reference to s1 with an actual string (eg "aoeu") then it > works just fine. I would like to build up that string (s1 in this example) > dynamically, but I can't figure out how to do that. > > P > > -- > 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 performance tips
On Sat, Jan 16, 2016 at 11:29 PM, Brian Adkinswrote: > > I'm happy to run experiments and report timings though. > > Since the profile suggests that string-trim is the biggest culprit (followed by fprintf), try using this specialized version of string-trim locally: ;; === (require racket/unsafe/ops) (define (string-trim s) (define len (string-length s)) (let loop ([i 0]) (cond [(unsafe-fx< i len) (cond [(char-whitespace? (unsafe-string-ref s i)) (loop (unsafe-fx+ i 1))] [else (let inner ([j (unsafe-fx- len 1)]) (cond [(char-whitespace? (unsafe-string-ref s j)) (inner (unsafe-fx- j 1))] [else (substring s i (unsafe-fx+ j 1))]))])] [else s]))) ;; === Instead of fprintf-ing the tabbed values, you might try (displayln (string-join fields "\t")). Of course, that requires building a list of strings, which has its own cost. -- 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] Calling a procedure without allowing it to permanently alter parameters.
I don't think there is a better way than what you have. I looked into the undocumented `reparameterize` procedure, from '#%paramz: [ https://github.com/racket/racket/blob/a6eb00a41cc29859424335f40ef9ae68c471c57a/racket/src/racket/src/thread.c#L7680], but it only copies built-in parameters, so it fails your test case. It would be easy enough to implement a version that copied the whole parameterization, but it would have to be implemented in C. On Tue, Jan 12, 2016 at 9:38 AM, Jos Kootwrote: > #| > Hi, > Consider a procedure, say protected-caller, > that accepts a thunk and calls it, > but does not want any parameter or handler to be altered by the thunk. > Of course the called thunk can alter parameters and handlers for its own > use, > but I want all parameters and handlers reset after return from the thunk. > First I tried to accomplish this with > current-parameterization and call-with-parameterization, > but did not find a way out. > Now I use call-in-nested-thread to fullfil my wish, > which works well, I think. I did this as shown below. > Is this the correct way to do what I want? > May be it is expensive with respect to cpu time, > but in my case this is not an important issue. > > Don't bother about the continuation-barrier. > It is there because I don't allow the called thunk > to escape from the dynamic range of procedure protected-caller. > > The code shown below is a simplification of my original code. > |# > > #lang racket > > (define (protected-caller thunk) > #;"some things to do not shown here." > (call-with-continuation-barrier > (λ () (call-in-nested-thread thunk))) > #;"more things to do not shown here.") > > (define p (make-parameter 1)) > > (protected-caller (λ () (p 2) (p))) ; -> 2 ; as I wish. > > (p) ; -> 1 ; as I wish. > > ; 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. > 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] Is there a way to return no value?
On Fri, Dec 11, 2015 at 5:27 PM, David Storrswrote: > > > On Fri, Dec 11, 2015 at 1:53 PM, Matthew Butterick > wrote: >> >> PS. I'm assuming that you're using `eq?` here in deliberate preference to >> `equal?`. Because `eq?` is not reliable for string comparisons. > > > Ah. No, I did not realize that. I thought that Racket worked on a > flyweight pattern where all strings of the same characters were eq? -- > isn't that what interned symbols are about? Yes, but strings aren't interned symbols (or symbols, at all, in fact). Many (most?) uses of strings don't benefit from interning. -Jon -- 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] Contract error when installing Gregor
Ok, I just pushed an update to the tzinfo package. It make take a little while for the package catalog to notice the change. -Jon On Tue, Nov 3, 2015 at 6:59 PM, Jon Zeppieri <zeppi...@gmail.com> wrote: > On Tue, Nov 3, 2015 at 6:44 PM, William J. Bowman > <w...@williamjbowman.com> wrote: >> On Tue, Nov 03, 2015 at 06:37:59PM -0500, Jon Zeppieri wrote: >>> Okay, that is odd. I'll try reinstalling from scratch on my own machine to >>> make sure I didn't introduce a bug at some point. That's also where my >>> zoneinfo DB is too, so I'd expect it to behave the same way. I am running >>> macos, but I don't see why that should make any difference. >> It's possible that I have something misconfigured, but my locale and >> time seem to work properly everywhere else. > > I think it's far more likely to be a bug in my detection code. > > So, your /etc/localtime should be a symlink. What path does it point > to? And, in particular, is the path that it points to absolute or > relative? > On my system, I have: >/etc/localtime -> /usr/share/zoneinfo/America/New_York > > Since it looked from your stack trace like gregor was trying to find > ../usr/share/zoneinfo/America/New_York, that makes me think that the > trouble may start with this symlink. Those two paths would point to > the same file, of course, since we're starting in /etc. So I probably > need to canonicalize the linked path. > > -Jon -- 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] Contract error when installing Gregor
On Tue, Nov 3, 2015 at 6:44 PM, William J. Bowman <w...@williamjbowman.com> wrote: > On Tue, Nov 03, 2015 at 06:37:59PM -0500, Jon Zeppieri wrote: >> Okay, that is odd. I'll try reinstalling from scratch on my own machine to >> make sure I didn't introduce a bug at some point. That's also where my >> zoneinfo DB is too, so I'd expect it to behave the same way. I am running >> macos, but I don't see why that should make any difference. > It's possible that I have something misconfigured, but my locale and > time seem to work properly everywhere else. I think it's far more likely to be a bug in my detection code. So, your /etc/localtime should be a symlink. What path does it point to? And, in particular, is the path that it points to absolute or relative? On my system, I have: /etc/localtime -> /usr/share/zoneinfo/America/New_York Since it looked from your stack trace like gregor was trying to find ../usr/share/zoneinfo/America/New_York, that makes me think that the trouble may start with this symlink. Those two paths would point to the same file, of course, since we're starting in /etc. So I probably need to canonicalize the linked path. -Jon -- 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] Contract error when installing Gregor
On Tue, Nov 3, 2015 at 8:07 PM, Jon Zeppieri <zeppi...@gmail.com> wrote: > Ok, I just pushed an update to the tzinfo package. It make take a > little while for the package catalog to notice the change. > Actually, the package catalog already noticed it, so you should be able to update that package now. Thanks for the bug report. -Jon -- 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] Contract error when installing Gregor
What OS are you using, and to you happen to know if/where the zoneinfo database is on your system? If the problem is that your database is in a location that Gregor doesn't expect, I'll be happy to fix that. If you don't have the database, at all (which would be odd for a modern UNIX), you can install the tzinfo-data package. Installing that package should also be a work-around for the problem, too. > On Nov 3, 2015, at 5:50 PM, 'William J. Bowman' via Racket Users >wrote: > > I get the following contract error when installed Gregor (the excellent > date and time library) on my machine. > > Any one know if this is a problem with my setup and if so how to > resolve? > > ; find-relative-path: contract violation > ; expected: (and/c path-for-some-system? simple-form?) > ; given: # > ; context...: > ;/racket/racket/collects/racket/path.rkt:114:0: do-explode-path > ;/racket/racket/collects/racket/path.rkt:124:0: find-relative-path5 > ;/racket/racket/share/pkgs/tzinfo/tzinfo/private/os/unix.rkt:11:0: > detect-tzid/unix > ;/racket/racket/share/pkgs/tzinfo/tzinfo/private/zoneinfo.rkt:54:3: > detect-system-tzid > ;/racket/racket/share/pkgs/tzinfo/tzinfo/main.rkt:70:0: system-tzid > ; > /racket/racket/collects/racket/contract/private/arrow-val-first.rkt:302:18 > ;/racket/racket/share/pkgs/gregor-lib/gregor/private/moment.rkt: > [running body] > ;/racket/racket/share/pkgs/gregor-lib/gregor/private/generics.rkt: > [traversing imports] > > -- > William J. Bowman > > -- > 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] Contract error when installing Gregor
Though, looking at the stack trace, it seems like something in my path manipulation code is probably at fault. For some reason, it appears to be using a path that's prefixed with ../ when it shouldn't, but I'll need to know where your zoneinfo is to be sure. It's *probably* in /usr/share/zoneinfo. > On Nov 3, 2015, at 6:20 PM, Jon Zeppieri <zeppi...@gmail.com> wrote: > > > What OS are you using, and to you happen to know if/where the zoneinfo > database is on your system? If the problem is that your database is in a > location that Gregor doesn't expect, I'll be happy to fix that. If you don't > have the database, at all (which would be odd for a modern UNIX), you can > install the tzinfo-data package. Installing that package should also be a > work-around for the problem, too. > > >> On Nov 3, 2015, at 5:50 PM, 'William J. Bowman' via Racket Users >> <racket-users@googlegroups.com> wrote: >> >> I get the following contract error when installed Gregor (the excellent >> date and time library) on my machine. >> >> Any one know if this is a problem with my setup and if so how to >> resolve? >> >> ; find-relative-path: contract violation >> ; expected: (and/c path-for-some-system? simple-form?) >> ; given: # >> ; context...: >> ;/racket/racket/collects/racket/path.rkt:114:0: do-explode-path >> ;/racket/racket/collects/racket/path.rkt:124:0: find-relative-path5 >> ;/racket/racket/share/pkgs/tzinfo/tzinfo/private/os/unix.rkt:11:0: >> detect-tzid/unix >> ;/racket/racket/share/pkgs/tzinfo/tzinfo/private/zoneinfo.rkt:54:3: >> detect-system-tzid >> ;/racket/racket/share/pkgs/tzinfo/tzinfo/main.rkt:70:0: system-tzid >> ; >> /racket/racket/collects/racket/contract/private/arrow-val-first.rkt:302:18 >> ;/racket/racket/share/pkgs/gregor-lib/gregor/private/moment.rkt: >> [running body] >> ;/racket/racket/share/pkgs/gregor-lib/gregor/private/generics.rkt: >> [traversing imports] >> >> -- >> William J. Bowman >> >> -- >> 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] Contract error when installing Gregor
Okay, that is odd. I'll try reinstalling from scratch on my own machine to make sure I didn't introduce a bug at some point. That's also where my zoneinfo DB is too, so I'd expect it to behave the same way. I am running macos, but I don't see why that should make any difference. By the way, do you actually get this error when installing the package? Or just when trying to use it? The TZ detection code shouldn't run on install, I don't think-- hmm, unless it breaks when building documentation? Since that actually does use the package... > On Nov 3, 2015, at 6:33 PM, William J. Bowman <w...@williamjbowman.com> wrote: > > I'm running Arch Linux, and the zoneinfo database is in /usr/share/zoneinfo. > > -- > William J. Bowman > >> On Tue, Nov 03, 2015 at 06:20:54PM -0500, Jon Zeppieri wrote: >> >> What OS are you using, and to you happen to know if/where the zoneinfo >> database is on your system? If the problem is that your database is in a >> location that Gregor doesn't expect, I'll be happy to fix that. If you don't >> have the database, at all (which would be odd for a modern UNIX), you can >> install the tzinfo-data package. Installing that package should also be a >> work-around for the problem, too. >> >> >>> On Nov 3, 2015, at 5:50 PM, 'William J. Bowman' via Racket Users >>> <racket-users@googlegroups.com> wrote: >>> >>> I get the following contract error when installed Gregor (the excellent >>> date and time library) on my machine. >>> >>> Any one know if this is a problem with my setup and if so how to >>> resolve? >>> >>> ; find-relative-path: contract violation >>> ; expected: (and/c path-for-some-system? simple-form?) >>> ; given: # >>> ; context...: >>> ;/racket/racket/collects/racket/path.rkt:114:0: do-explode-path >>> ;/racket/racket/collects/racket/path.rkt:124:0: find-relative-path5 >>> ;/racket/racket/share/pkgs/tzinfo/tzinfo/private/os/unix.rkt:11:0: >>> detect-tzid/unix >>> ;/racket/racket/share/pkgs/tzinfo/tzinfo/private/zoneinfo.rkt:54:3: >>> detect-system-tzid >>> ;/racket/racket/share/pkgs/tzinfo/tzinfo/main.rkt:70:0: system-tzid >>> ; >>> /racket/racket/collects/racket/contract/private/arrow-val-first.rkt:302:18 >>> ;/racket/racket/share/pkgs/gregor-lib/gregor/private/moment.rkt: >>> [running body] >>> ;/racket/racket/share/pkgs/gregor-lib/gregor/private/generics.rkt: >>> [traversing imports] >>> >>> -- >>> William J. Bowman >>> >>> -- >>> 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] DrRacket indentation adds spaces to empty non-top-level lines?
DrWhitespace will certainly remove spaces from empty non-top-level lines. (And from other places, as well.) -J On Wed, Oct 21, 2015 at 4:23 PM, Alexis Kingwrote: > This might be a relevant thread: > https://groups.google.com/d/msg/racket-users/5pxs1pM-8lE/uh0yn9D0QHYJ > > (It also might not be. I’m not really sure if it addresses your issue or not.) > >> On Oct 21, 2015, at 12:47 PM, Paolo Giarrusso wrote: >> >> Hi all! >> >> Every time I reindent a file with DrRacket in a Git repository, DrRacket and >> Git fight over whitespace. Git assumes that spaces at the end of lines are >> whitespace errors, while DrRacket indentation will add spaces to empty lines >> (including existing ones), if they are inside parens (that is, not at the >> outermost level). >> >> What's more, the official coding style says "Don’t pollute your code with >> spaces at the end of lines", suggesting DrRacket is not behaving well even >> according to Racket guidelines: >> http://docs.racket-lang.org/style/Textual_Matters.html#%28part._.Spaces%29 >> >>> Don’t pollute your code with spaces at the end of lines. >> >> I suspect most people don't have these issue because their empty lines are >> at the outermost level, so they don't need to be indented anyway. But I'm >> writing module statements, namely (module checker handin-server/checker >> ...), and switching to `#lang handin-server/checker` fails for me, >> apparently because that language is defined in a package and not a >> collection, so I'm stuck. >> >> == >> >> What's more, the style guide continues confusingly: >> >>> If you find yourself breaking long blocks of code with blank lines to aid >>> readability, consider refactoring your program to introduce auxiliary >>> functions so that you can shorten these long blocks of code. If nothing >>> else helps, consider using (potentially) empty comment lines. >> >> But I find the discussion confusing: are empty lines at the outermost level >> fine (as I'd guess), or does the text discourage empty lines everywhere (as >> the actual text suggests)? >> And what are "(potentially) empty comment lines"? Do you actually mean >> >> ; >> >> ? Why's that better? >> >> Finally, does DrRacket not indent empty lines well because they're >> discouraged? >> >> -- >> 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] Re: [ann] gregor (date + time library) updates
[I'm unaccountably happy about the fact that the gregor docs on pkg-build.racket-lang.org reveal that they were scribbled on a machine in the America/Denver time zone. -J] On Mon, Aug 31, 2015 at 9:33 AM, Jon Zeppieri <zeppi...@gmail.com> wrote: > I've added a couple of features to gregor: > > - Calendar query functions: > [http://pkg-build.racket-lang.org/doc/gregor/query.html] > These are functions that were already used internally by the library > but should be public (and now are). > - leap-year? > - days-in-year > - days-in-month > - iso-weeks-in-year > > - Periods: [http://pkg-build.racket-lang.org/doc/gregor/period.html] > A period represents some period of time. To allow arithmetic on > periods, arithmetic has been moved into its own set of generics. > So, for example, `+years` is no longer part of the `date-provider` > interface; it's now part of `date-arithmetic-provider`, and values > that satisfy `date-period?` also satisfy `date-arithmetic-provider?`. > So you can, for example, write: > ``` > (+months (years 2) 6) > ``` > ... which results in a period of 2 years, 6 months. > In addition, the following new arithmetic functions were added: > - [+/-]date-period (on date-arithmetic-provider) > - [+/-]time-period (on time-arithmetic-provider) > - [+/-]period (on datetime-arithmetic-provider) > > And `duration-between` was removed in favor of > date-period-between, time-period-between, and > period-between. > > > Documentation: http://pkg-build.racket-lang.org/doc/gregor/index.html > Source: https://github.com/97jaz/gregor > > -Jon -- 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] [ann] gregor (date + time library) updates
I've added a couple of features to gregor: - Calendar query functions: [http://pkg-build.racket-lang.org/doc/gregor/query.html] These are functions that were already used internally by the library but should be public (and now are). - leap-year? - days-in-year - days-in-month - iso-weeks-in-year - Periods: [http://pkg-build.racket-lang.org/doc/gregor/period.html] A period represents some period of time. To allow arithmetic on periods, arithmetic has been moved into its own set of generics. So, for example, `+years` is no longer part of the `date-provider` interface; it's now part of `date-arithmetic-provider`, and values that satisfy `date-period?` also satisfy `date-arithmetic-provider?`. So you can, for example, write: ``` (+months (years 2) 6) ``` ... which results in a period of 2 years, 6 months. In addition, the following new arithmetic functions were added: - [+/-]date-period (on date-arithmetic-provider) - [+/-]time-period (on time-arithmetic-provider) - [+/-]period (on datetime-arithmetic-provider) And `duration-between` was removed in favor of date-period-between, time-period-between, and period-between. Documentation: http://pkg-build.racket-lang.org/doc/gregor/index.html Source: https://github.com/97jaz/gregor -Jon -- 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] problems with sql-timestamp and date*
On Sat, Aug 22, 2015 at 4:02 PM, Jon Zeppieri zeppi...@gmail.com wrote: (require gregor) (require racket/match) (define (sql-timestamp-moment t) (match-define (sql-timestamp y mo d h mi s n tz) t) (moment y mo d h mi s n #:tz (or tz 0))) Actually, a sql-timestamp with a #f tz means that the timestamp doesn't have any zone info, so that would actually correspond to gregor's `datetime` (instead of `moment`, which includes tz info). -Jon -- 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] problems with sql-timestamp and date*
Where exactly do you see sql-timestamp-srfi-date failing? In your examples, what I'm seeing is incorrect translation from UTC to UTC-4, but I don't see where the translation from sql-timestamp to date* is going wrong. Could you point to exactly where you see the problem? As far as offsetting time zones properly, Racket's built-in libraries will not help you there. You might want to check out my library, gregor: http://pkg-build.racket-lang.org/doc/gregor/index.html. You'd still need to write your own sql-datetime-moment function, but that's not difficult. In fact: (require gregor) (require racket/match) (define (sql-timestamp-moment t) (match-define (sql-timestamp y mo d h mi s n tz) t) (moment y mo d h mi s n #:tz (or tz 0))) Unfortunately, since sql-timestamp only represents time zones as offsets from UTC, you're a bit limited from the start. Gregor certainly can use UTC offsets as TZs but prefers to use IANA names (e.g., America/New_York). -Jon On Sat, Aug 22, 2015 at 3:45 PM, George Neuner gneun...@comcast.net wrote: Ok, reading the docs more carefully, I realized that seconds-date takes a boolean and not a time zone offset, but that doesn't explain why sql-timestamp-srfi-date is not working properly. I'm now offsetting the time with (seconds-date (+ (date*-seconds ts #f) (* timezone 60 60)) #f)) which gives me the right time, but in the wrong time zone. Just how do I offset time zones properly? Do I need to construct the date* piecemeal? Thanks, 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.
Re: [racket-users] problems with sql-timestamp and date*
On Sat, Aug 22, 2015 at 5:50 PM, Jon Zeppieri zeppi...@gmail.com wrote: On Sat, Aug 22, 2015 at 4:36 PM, George Neuner gneun...@comcast.net wrote: [Sorry, I bungled the this part of the email.] Maybe I'm confused, but my understanding is that the database timestamp is in UTC, and you want a date* representing the same point in time, but in specified UTC offset. In other words, Your first example here starts with First, instead of in specified UTC offset, it should read, with the specified UTC offset [in your example, UTC-5]. Second, I have no idea what I was going to write after In other words. :) -Jon -- 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] problems with sql-timestamp and date*
On Sat, Aug 22, 2015 at 4:36 PM, George Neuner gneun...@comcast.net wrote: The latter code using date works properly (modulo the time zone field) and gives consistent results, but the former using date* gives inconsistent results. E.g.,: with timezone = -5 = expires #(struct:sql-timestamp 2015 8 22 21 56 33 805346000 0) = expires #(struct:date* 33 56 21 22 8 2015 6 233 #f 0 805346000 ) = expires #(struct:date* 58 9 17 22 8 2015 6 233 #f 0 34600 UTC) = expires #(struct:sql-timestamp 2015 8 22 22 23 45 95751000 0) = expires #(struct:date* 45 23 22 22 8 2015 6 233 #f 0 95751000 ) = expires #(struct:date* 20 25 17 22 8 2015 6 233 #f 0 75100 UTC) These both look wrong to me. Maybe I'm confused, but my understanding is that the database timestamp is in UTC, and you want a date* representing the same point in time, but in specified UTC offset. In other words, Your first example here starts with 2015-08-22T21:56:33.805346Z. Your end result is 2015-08-22T17:09:58.346, which is clearly not exactly 5 hours offset. In the second example, you start with 2015-08-22T22:23:45.95751000Z and wind up with 2015-08-22T17:25:20.751, which is also wrong, but by a considerably smaller margin. I actually can't reproduce the problem in the second example, but I'm also running 6.2.0.2. It looks to me like date-seconds roundtrips correctly w.r.t. seconds-date but date*-seconds does not: ``` d (date* 33 56 21 22 8 2015 6 233 #f 0 805346000 ) (seconds-date (+ (* -5 60 60) (date-seconds d #f)) #f) (date* 33 56 16 22 8 2015 6 233 #f 0 0 UTC) ;; correct, modulo nanoseconds (seconds-date (+ (* -5 60 60) (date*-seconds d #f)) #f) (date* 58 9 17 22 8 2015 6 233 #f 0 34600 UTC) ;; incorrect ``` So, yeah, I'd say that there's a bug in date*-seconds: ``` (date-seconds d #f) 1440280593 (date*-seconds d #f) 1440281398 173/500 ``` Let's see what this looks like in gregor's terms: ``` (define d (moment 2015 8 22 21 56 33 805346000 #:tz UTC)) d #moment 2015-08-22T21:56:33.805346Z[UTC] (adjust-timezone d (* -5 60 60)) #moment 2015-08-22T16:56:33.805346-05:00 (-posix d) 1440280593 402673/50 ``` -Jon -- 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] For/lists: where is #:continue?
I think you're looking for #:when / #:unless. On Mon, Jul 13, 2015 at 3:12 PM, Pekka Niiranen pekka.niira...@pp5.inet.fi wrote: Hello users, What is the proper design pattern to skip invalid values when using for/list? The programs below fails because #:continue is not recognized: for/list ([i (in-range 0 1000)]) (let ((value (vector-ref vector i))) (if ( 0 (length value)) value #:continue))) Sure, I could bypass this limitation by building the list explicitely with plain for + cons or: (define result-list (for/list ([i (in-range 0 1000)]) (let ((value (vector-ref vector i))) (if ( 0 (length value)) value empty = then filter empties from result-list with another loop... -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.
Re: [racket-users] For/lists: where is #:continue?
Also, since you're not actually interested in the value of i, you should probably use in-vector rather than in-range. The whole example would be: (for/list ([value (in-vector vector)] #:when ( 0 (length value))) value) On Mon, Jul 13, 2015 at 3:18 PM, Jon Zeppieri zeppi...@gmail.com wrote: I think you're looking for #:when / #:unless. On Mon, Jul 13, 2015 at 3:12 PM, Pekka Niiranen pekka.niira...@pp5.inet.fi wrote: Hello users, What is the proper design pattern to skip invalid values when using for/list? The programs below fails because #:continue is not recognized: for/list ([i (in-range 0 1000)]) (let ((value (vector-ref vector i))) (if ( 0 (length value)) value #:continue))) Sure, I could bypass this limitation by building the list explicitely with plain for + cons or: (define result-list (for/list ([i (in-range 0 1000)]) (let ((value (vector-ref vector i))) (if ( 0 (length value)) value empty = then filter empties from result-list with another loop... -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.
Re: [racket-users] For/lists: where is #:continue?
In that case, you probably want to make use of in-value to bind single-value sequences in your for*/list: (for*/list ([(start end) (in-parallel 1 1000)] [i (in-range start (sub1 end))] [s (in-value (vector-ref vector i))] [columns (in-value (string-split s ,))] [col# (in-value (length columns))] #:when ( 2 col#)) (first columns)) On Mon, Jul 13, 2015 at 3:46 PM, Pekka Niiranen pekka.niira...@pp5.inet.fi wrote: Hello Sir. all true, but my example was bad simplification from the original code. The ugly part is to insert the multi-step function into #:when -clause and in case of success use function's internal parameter (columns) only. My imperative mind wants to use continue in the place empty below: (for*/list ([(start end) (in-parallel 1 1000)] [i (in-range start (sub1 end))]) (let* ((columns (string-split (vector-ref vector i) ,)) (col# (length columns))) (if ( 2 col#) (first columns) empty))) On 7/13/15 10:26 PM, Jon Zeppieri wrote: Also, since you're not actually interested in the value of i, you should probably use in-vector rather than in-range. The whole example would be: (for/list ([value (in-vector vector)] #:when ( 0 (length value))) value) On Mon, Jul 13, 2015 at 3:18 PM, Jon Zeppieri zeppi...@gmail.com wrote: I think you're looking for #:when / #:unless. On Mon, Jul 13, 2015 at 3:12 PM, Pekka Niiranen pekka.niira...@pp5.inet.fi wrote: Hello users, What is the proper design pattern to skip invalid values when using for/list? The programs below fails because #:continue is not recognized: for/list ([i (in-range 0 1000)]) (let ((value (vector-ref vector i))) (if ( 0 (length value)) value #:continue))) Sure, I could bypass this limitation by building the list explicitely with plain for + cons or: (define result-list (for/list ([i (in-range 0 1000)]) (let ((value (vector-ref vector i))) (if ( 0 (length value)) value empty = then filter empties from result-list with another loop... -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.
Re: [racket-users] How to specify fallbacks for generic interfaces without going into an infinite loop?
Use define/generic: #lang racket/base (require racket/generic) (define-generics foo (a foo) (b foo) (c foo) #:fallbacks [(define/generic gen-a a) (define/generic gen-b b) (define (a foo) (displayln a-fallback) (gen-b foo)) (define (b foo) (displayln b-fallback) (gen-a foo))]) (struct foo-struct () #:methods gen:foo [(define (a foo) 1)]) (b (foo-struct)) On Mon, Jul 6, 2015 at 9:50 PM, Alexander D. Knauth alexan...@knauth.org wrote: What is the proper way to do this? This goes into an infinite loop: #lang racket/base (require racket/generic) (define-generics foo (a foo) (b foo) (c foo) #:fallbacks [(define (a foo) (displayln a-fallback) (b foo)) (define (b foo) (displayln b-fallback) (a foo))]) (struct foo-struct () #:methods gen:foo [(define (a foo) 1)]) (b (foo-struct)) -- 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: Converting a heterogenous list into a string
On Sun, Jun 21, 2015 at 7:36 PM, Matthias Felleisen matth...@ccs.neu.edu wrote: I think the proper way of thinking Racket-y is to re-consider the input representation: (define our-list '((a 1) (b 2.5) (c #t) (d hi))) (string-join (map (match-lambda [`(,l ,v) (format [~a=~a] l v)]) our-list)) You really want labels and values to be clearly paired, and the above representation does that. Absolutely -- the problem is ill-defined for flat lists with odd lengths. (This is also a problem for `hash` and friends, which is why I expressed doubt that it was a happy accident that `hash` also happens to accept a flat list.) I was just assuming that the input format was non-negotiable. -- 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: Converting a heterogenous list into a string
On Sun, Jun 21, 2015 at 7:13 PM, Bahman Movaqar b.mova...@gmail.com wrote: On Monday, 22 June 2015 02:34:43 UTC+4:30, Bahman Movaqar wrote: Assuming (define my-list (a 1 b 2.5 c #t d hi)) what is the idiomatic way to convert `my-list` into the following? [a=1][b=2.5][c=#t][d=hi] I thought of `FORMAT` but apparently the `{}` (for recursion) are not available. For example, in CL `(format nil ~{[~a:~a]~} my-list)` would do the trick. This is what I've come up with so far; but it doesn't feel idiomatic at all :-) (string-join (unfold null-list? (lambda (x) (format [~a=~a] (first x) (second x))) (lambda (x) (cdr (cdr x))) my-list) ) This might be a bit more rackety: (apply string-append (for/list ([(k v) (apply hash my-list)]) (format [~a=~a] k v))) It relies on the (happy?) accident that `hash` happens to accept a flat list. This also makes it more expensive than a version that doesn't use a hash. Here's a hash-less alternative (though this one does use an unstable library): (require unstable/sequence) (apply string-append (for/list ([slice (in-slice 2 my-list)]) (format [~a=~a] (car slice) (cadr slice) -- 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: Fast way to map over a list many times, changing ONE element each time?
If you're willing to use vectors, then maybe you're also willing to use a custom data structure? You could get much better performance that way. Here's a half-baked example of what I mean. `map-once/h`, below, returns a (normal list) of hole-lists. (hole-list is not a good name. The offset doesn't really designate a hole in the list, but the offset where the function should be applied.) === #lang racket/base (require racket/match) (struct hole-list (xs hole-offset fn)) (define (hole-list-empty? hxs) (match hxs [(hole-list (? pair?) _ _) #f] [_ #t])) (define (hole-list-nonempty? hxs) (not (hole-list-empty? hxs))) (define (hcar hxs) (match hxs [(hole-list (cons x _) 0 fn) (fn x)] [(hole-list (cons x _) _ _) x])) (define (hcdr hxs) (match hxs [(hole-list (cons _ xs) n fn) (hole-list xs (sub1 n) fn)])) (define-match-expander hcons (syntax-rules () [(_ x xs) (and (? hole-list?) (? hole-list-nonempty?) (app hcar x) (app hcdr xs))])) (define-match-expander hnull (syntax-rules () [(_) (and (? hole-list?) (? hole-list-empty?))])) (define (hole-list-list hxs) (match hxs [(hnull) '()] [(hcons x xs) (cons x (hole-list-list xs))])) (define (map-once/h fn xs) (for/list ([i (in-range (length xs))]) (hole-list xs i fn))) On Fri, Jun 19, 2015 at 4:33 PM, Luke Miles rashreportl...@gmail.com wrote: I timed all these with `sqr` on a list of 1 `(random)`. Luke's (my) first one: cpu time: 4706 real time: 4699 gc time: 3673 Luke's second one: cpu time: 5401 real time: 5393 gc time: 4136 Jon's first one: cpu time: 9734 real time: 9728 gc time: 8007 Jon's second one (tested on a vector of course): cpu time: 1198 real time: 1195 gc time: 883 Jens' first one: cpu time: 5622 real time: 5618 gc time: 4800 Jens' second one: cpu time: 4393 real time: 4391 gc time: 3935 I thought Jens' second one would be faster. The vector's results are promising. -- 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] Fast way to map over a list many times, changing ONE element each time?
It's unlikely that an implementation using continuations would be faster than one that does not. An idiomatic solution might look like: (define (map-once fn xs) (for/list ([i (in-range (length xs))]) (for/list ([(x j) (in-indexed (in-list xs))]) (cond [(= i j) (fn x)] [else x] But it's not terribly fast. If you're willing to use vectors instead of lists, then maybe: (define (map-once fn xs) (build-vector (vector-length xs) (λ (i) (define v (vector-copy xs)) (vector-set! v i (fn (vector-ref v i))) v))) On Fri, Jun 19, 2015 at 3:24 PM, Luke Miles rashreportl...@gmail.com wrote: Say I have a list ls and I want to produce a list of lists where the i'th list has the i'th element of ls tripled, but all other elements are the same. e.g. '(3 5 7) = '((9 5 7) (3 15 7) (3 5 21)) What is a fast way to do this? I could do a loop with appending. (define (map-once f ls) (let M ([sooner null] [later ls]) (if (null? later) null (cons (append sooner (list (f (car later))) (cdr later)) (M (append sooner (list (car later))) (cdr later)) - (map-once sqr '(4 5 6)) '((16 5 6) (4 25 6) (4 5 36)) Unfortunately, this is very slow messy. I have to do 2 big appends for every element is the return list. Here is a cleaner-looking, but still slow way: (define (list-set ls i new-val) (let-values ([(sooner later) (split-at ls i)]) (append sooner (list new-val) (cdr later (define (map-once f ls) (for/list ([i (in-naturals)] [elm (in-list ls)]) (list-set ls i (f elm I'm thinking a good implementation might use continuations somehow? Maybe of vector-set (without the exclamation point) existed, I could use it? -- 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] prop:procedure, prop:match-expander, and contract blame
On Thu, Apr 16, 2015 at 7:32 AM, Alexander D. Knauth alexan...@knauth.org wrote: On Apr 15, 2015, at 2:29 PM, Jon Zeppieri zeppi...@gmail.com wrote: I'm trying to provide a struct, the struct type of which uses prop:procedure and prop:match-expander, and I'd like the procedure to have a contract. On Apr 15, 2015, at 10:12 PM, Jon Zeppieri zeppi...@gmail.com wrote: It's an instance of a struct. Here's the background: I have a struct type, created with `struct`, which has its own constructor and match expander. However, I don't want to use that constructor or match expander as part of the public interface. (The struct contains some fields that should be treated as private.) Now, the only way I know to provide a single identifier that can act as both a struct constructor and a match expander is to use a struct. So, in this case, I need to use a *different* struct type, an instance of which can be used, on one hand, as a procedure to construct an instance of the original struct type, and on the other, as a match expander (also for the original struct type). So If I understand correctly what you’re doing, you have a normal struct A, at “runtime” with a transformer binding like normal structs have. Then you have a compile-time struct B, which has prop:procedure and prop:match-expander, where you want an instance of B to be the right-hand side of a (define-syntax identifier (B ….))? Is that correct? And the prop:procedure in B will expand to something like (A ….), and the prop:match-expander in B will expand to (A ….) as a match pattern? Or am I misunderstanding what you’re trying to do? On Apr 15, 2015, at 11:02 PM, Jon Zeppieri zeppi...@gmail.com wrote: You got it. So do you want to put a contract on the instance of B, or do you want to put a contract on what it expands to? What it expands to, with correct blame ascription. If you want to put it on what it expands to, then you could look at this: http://docs.racket-lang.org/syntax/exprc.html Or this: http://docs.racket-lang.org/unstable/wrapc.html Thanks, I'll take a look. By the way, why wouldn’t you just use define-match-expander instead of defining the B struct? Because I need the same identifier to expand either to a procedure or to a match expander, and I don't know how to do that using define-match-expander. -Jon -- 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] prop:procedure, prop:match-expander, and contract blame
On Thu, Apr 16, 2015 at 8:02 AM, Jon Zeppieri zeppi...@gmail.com wrote: On Thu, Apr 16, 2015 at 7:32 AM, Alexander D. Knauth alexan...@knauth.org wrote: By the way, why wouldn’t you just use define-match-expander instead of defining the B struct? Because I need the same identifier to expand either to a procedure or to a match expander, and I don't know how to do that using define-match-expander. A message I received from Matthias prompted me to take a closer look at the docs for define-match-expander, and I realized that it actually accepts two syntax transformers, where the second (optional) one is for when the identifier is used in an expression context. So, in fact, I can use define-match-expander. -Jon -- 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] prop:procedure, prop:match-expander, and contract blame
You got it. On Apr 15, 2015, at 10:19 PM, Alexander D. Knauth alexan...@knauth.org wrote: On Apr 15, 2015, at 10:12 PM, Jon Zeppieri zeppi...@gmail.com wrote: On Wed, Apr 15, 2015 at 9:35 PM, Alexander D. Knauth alexan...@knauth.org wrote: On Apr 15, 2015, at 2:29 PM, Jon Zeppieri zeppi...@gmail.com wrote: I'm trying to provide a struct, the struct type of which uses prop:procedure and prop:match-expander, and I'd like the procedure to have a contract. If I simply (provide identifier) Is this identifier the constructor function, or an instance of this struct? If it’s the constructor function, then couldn’t you use (provide (contract-out [struct id ([field contract] …)])) for that? If it’s an instance, then are you doing something different to define it as a transformer binding? It's an instance of a struct. Here's the background: I have a struct type, created with `struct`, which has its own constructor and match expander. However, I don't want to use that constructor or match expander as part of the public interface. (The struct contains some fields that should be treated as private.) Now, the only way I know to provide a single identifier that can act as both a struct constructor and a match expander is to use a struct. So, in this case, I need to use a *different* struct type, an instance of which can be used, on one hand, as a procedure to construct an instance of the original struct type, and on the other, as a match expander (also for the original struct type). So If I understand correctly what you’re doing, you have a normal struct A, at “runtime” with a transformer binding like normal structs have. Then you have a compile-time struct B, which has prop:procedure and prop:match-expander, where you want an instance of B to be the right-hand side of a (define-syntax identifier (B ….))? Is that correct? And the prop:procedure in B will expand to something like (A ….), and the prop:match-expander in B will expand to (A ….) as a match pattern? Or am I misunderstanding what you’re trying to do? -- 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] prop:procedure, prop:match-expander, and contract blame
On Wed, Apr 15, 2015 at 9:35 PM, Alexander D. Knauth alexan...@knauth.org wrote: On Apr 15, 2015, at 2:29 PM, Jon Zeppieri zeppi...@gmail.com wrote: I'm trying to provide a struct, the struct type of which uses prop:procedure and prop:match-expander, and I'd like the procedure to have a contract. If I simply (provide identifier) Is this identifier the constructor function, or an instance of this struct? If it’s the constructor function, then couldn’t you use (provide (contract-out [struct id ([field contract] …)])) for that? If it’s an instance, then are you doing something different to define it as a transformer binding? It's an instance of a struct. Here's the background: I have a struct type, created with `struct`, which has its own constructor and match expander. However, I don't want to use that constructor or match expander as part of the public interface. (The struct contains some fields that should be treated as private.) Now, the only way I know to provide a single identifier that can act as both a struct constructor and a match expander is to use a struct. So, in this case, I need to use a *different* struct type, an instance of which can be used, on one hand, as a procedure to construct an instance of the original struct type, and on the other, as a match expander (also for the original struct type). -- 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 plugin to remove trailing whitespace on save?
So, just to be clear, because there have been a number of +1s for a whitespace-highlighting feature: that's not what I'm doing. A bunch of people want that, so someone should write it, but I'm not going in that direction. (In fact, one of my emacs configurations does this in ruby-mode, and I keep meaning to find the setting to turn it off. Whenever the highlight appears, I compulsively save the buffer just to strip the whitespace and get rid of the highlight.) -Jon On Mon, Apr 13, 2015 at 9:13 PM, Neil Van Dyke n...@neilvandyke.org wrote: After editing a Racket source file in DrRacket, I usually end up going into Emacs to clean up formatting of the code and comments. This is a combination of `quack-tidy-buffer` (see docs below), semi-automated re-filling of any messy comment/docs, adjusting of line breaks in ways that are easier to do with Emacs's richer editing controls, and any checking and moving stuff around and such that's easier to see/manipulate in an Emacs window than a DrRacket window. It *might* be nice if DrRacket did some no-brainer whitespace cleanup on manual file saves (e.g., remove trailing whitespace at end of lines and end of file, force newline at end of file). But, in my case, I'm going to have to clean up the file in Emacs anyway, so I'm indifferent. An DrRacket editor indicator of irrelevant whitespace at end of lines would probably be a distraction that I would disable. quack-tidy-buffer is an interactive compiled Lisp function in `quack.el'. (quack-tidy-buffer) Tidy the formatting of the current Scheme buffer. This reindents, converts tabs to spaces, removes trailing whitespace on lines, removes formfeed characters, removes extraneous blank lines, and makes sure the buffer ends with a newline. This can conceivably corrupt multi-line string literals, but not in any way they wouldn't be corrupted by Usenet, various mailers, typesetting for print, etc. This may also result in large diffs when the tidied file is commited back to a version control or configuration management system. Consider making a VC or CM delta that consists only of changes made by `quack-tidy-buffer'. 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.
Re: [racket-users] DrRacket plugin to remove trailing whitespace on save?
On Mon, Apr 13, 2015 at 1:06 PM, John Clements cleme...@brinckerhoff.org wrote: On Apr 13, 2015, at 2:29 AM, Jon Zeppieri zeppi...@gmail.com wrote: It's supposed to have the same effect as emacs's `delete-trailing-whitespace`. I still need to add a preference setting to turn it on or off. (Maybe that should be based on the editor's mode?) I’d really like to use this tool. Here’s one problem that I see: there’s a hidden invariant in DrRacket (and all editors) that when a buffer is unchanged, saving it won’t change the file on disk. Actually, I think you can state this in a bunch of different ways. I forsee hard-to-understand errors arising from a silent change-on-save (unless I’m misreading your code?). Personally, I think I’d be more likely to use a tool that requests permission to scrub trailing whitespace when saving a file. I also think that this should probably be limited to racket and scribble files, and I’m guessing that the easiest way to distinguish these would be to use the filename extension. Please don’t let me stop you from doing this, though, this is something I’ve wanted for quite a while! Many thanks, John Good point. `delete-trailing-whitespace` is just a normal function in emacs, and if you want this to happen when saving a file, you use a before-save-hook. (This is a pretty common thing to do, though.) Exposing this as a method on text% is simple, I think. Then you could bind a keyboard shortcut to it or bring up a model on save (though personally I would find the latter pretty irritating). But, yes, different modes of use are important, I think. So I need to add a way of setting preferences for it. -Jon -- 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 plugin to remove trailing whitespace on save?
On Mon, Apr 13, 2015 at 1:27 PM, Robby Findler ro...@eecs.northwestern.edu wrote: Preferences are here for the prefs library: http://docs.racket-lang.org/framework/Preferences__Textual.html and here for adding check boxes to the prefs dialog: http://docs.racket-lang.org/framework/Preferences.html?q=editor-add#%28def._%28%28lib._framework%2Fmain..rkt%29._preferences~3aadd-to-editor-checkbox-panel%29%29 hth, Robby Thanks! -Jon -- 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 plugin to remove trailing whitespace on save?
Robby, This is my first crack at a DrRacket tool (not to mention an uncommon foray into Racket's class system), so what I'm doing may not be... sane. But if you're willing to take a look: [https://github.com/97jaz/drwhitespace]. At any rate, it isn't a lot of code. I based the general structure on Asumu Takikawa's drracket-vim-tool. It's supposed to have the same effect as emacs's `delete-trailing-whitespace`. I still need to add a preference setting to turn it on or off. (Maybe that should be based on the editor's mode?) -Jon On Sun, Apr 12, 2015 at 6:14 PM, Robby Findler ro...@eecs.northwestern.edu wrote: No but Max changed the way return works so there should be less whitespace added going forward. Writing a script to trim whitespace from line-endings would work well if it were to use text% IMO. Use load-file to get a file and then the paragraph methods to find line endings and then delete stuff and ace the file again. Robby On Sunday, April 12, 2015, Jon Zeppieri zeppi...@gmail.com wrote: Does such a think already exist? -Jon -- 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] DrRacket plugin to remove trailing whitespace on save?
If you mean: don't remove entire lines that consist of only whitespace, then I agree. If you mean: don't remove any trailing whitespace from lines that consist only of whitespace, then I do not. -Jon On Sun, Apr 12, 2015 at 7:01 PM, Alexis King lexi.lam...@gmail.com wrote: If you decide to do this, please make it so it doesn’t trim whitespace from whitespace-only lines. For some reason a lot of IDEs do this, and it’s a pet peeve of mine. On Apr 12, 2015, at 15:14, Robby Findler ro...@eecs.northwestern.edu wrote: No but Max changed the way return works so there should be less whitespace added going forward. Writing a script to trim whitespace from line-endings would work well if it were to use text% IMO. Use load-file to get a file and then the paragraph methods to find line endings and then delete stuff and ace the file again. Robby On Sunday, April 12, 2015, Jon Zeppieri zeppi...@gmail.com wrote: Does such a think already exist? -Jon -- 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] DrRacket plugin to remove trailing whitespace on save?
Does such a think already exist? -Jon -- 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] ANN: Gregor, a date and time library
On Thu, Mar 26, 2015 at 3:56 PM, John Clements cleme...@brinckerhoff.org wrote: On Mar 25, 2015, at 6:55 PM, Jon Zeppieri zeppi...@gmail.com wrote: I recently uploaded Gregor, a date and time library, to the package server. Can I use this instead of SRFI 19? That would be wonderful. John Clements Please do, and let me know what additions or changes you'd like. -Jon -- 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] ANN: Gregor, a date and time library
On Thu, Mar 26, 2015 at 4:57 PM, Vincent St-Amour stamo...@ccs.neu.edu wrote: At Thu, 26 Mar 2015 14:30:28 -0400, Jon Zeppieri wrote: [ snip] Since, IIUC, periods need to be anchored to a specific point in time, that would make them a bit more heavyweight to create. I could see durations being nice for that reason, and their use may not be too problematic if they're only used up to the week level, up to which there are reasonable, uniform conversion factors. (I.e. for dealing with unanchored durations, ignoring leap seconds is probably fine.) The anchor really only needs to be supplied when you do something with a period -- so it doesn't need to be part of the data structure. You can carry around a bucket that says 5 years, 3 weeks, and 40 hours, but the precise number of seconds inside the bucket is indeterminate until you pour it over a date-provider. (No, not a great metaphor.) - Assuming that periods are useful, what operations on them do we want? Arithmetic, probably; maybe the `period-nanoseconds` function I just mentioned; maybe convenience functions based on the current time (e.g., `ago`, `from-now`). Anything else? I think arithmetic is really the big one. Yep. - How do we represent a period? The obvious choice: I think a struct that implements `gen:dict` would be a nicer interface. I don't really like `duration-between`'s current interface. I like that idea. Again, really cool work! Vincent Thanks! -Jon -- 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] ANN: Gregor, a date and time library
On Thu, Mar 26, 2015 at 5:27 PM, Robby Findler ro...@eecs.northwestern.edu wrote: On Thu, Mar 26, 2015 at 4:13 PM, Jon Zeppieri zeppi...@gmail.com wrote: You can carry around a bucket that says 5 years, 3 weeks, and 40 hours, but the precise number of seconds inside the bucket is indeterminate until you pour it over a date-provider. (No, not a great metaphor.) I have a feeling I'm going to regret this :), but why can't you know the precise number of seconds in that case? Is it because of leap years? Would 3 weeks and 40 hours always be a precise number of seconds? Robby Yes, leap years. 3 weeks and 40 hours will always have a fixed number of seconds, but not 5 years. Similarly, N months doesn't have a fixed duration, because months can be 28, 29, 30, or 31 days long. -Jon -- 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] ANN: Gregor, a date and time library
Gregor shares the near-universal disdain for UTC exhibited by operating systems and date/time libraries alike. Seriously, though: Gregor doesn't keep UTC time, so there are no leap seconds. I mentioned in the docs that if there's a real demand for UTC, I'll implement it. - Jon On Mar 26, 2015, at 5:41 PM, Jens Axel Søgaard jensa...@soegaard.net wrote: 2015-03-26 22:30 GMT+01:00 Jon Zeppieri zeppi...@gmail.com: On Thu, Mar 26, 2015 at 5:27 PM, Robby Findler Would 3 weeks and 40 hours always be a precise number of seconds? Robby What about leap seconds? /Jens Axel -- 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] ANN: Gregor, a date and time library
On Thu, Mar 26, 2015 at 10:51 AM, Vincent St-Amour stamo...@ccs.neu.edu wrote: This is really cool! Do you have plans for operations on durations? Vincent More vague thoughts than plans. So-- there's a useful distinction (that comes out of Joda-Time) between a duration, which is directly convertible to some number of (nano)seconds, and a period, which contains units like years and months that have no fixed duration. The Gregor function `duration-between` actually computes a period, according to this terminology. This raises a few questions (for me, anyhow): - Is a duration data structure, distinct from some number of nanoseconds, useful? In Joda it seems largely a way of (a) adding convenience functions for translating some number of years, months, days, etc. into a number of nanoseconds, and (b) converting some fixed duration to a period. Since both kinds of translation are lossy, I don't know how useful this is -- all the more so because, if we had some period data structure, we could always provide `period-nanoseconds`. - Assuming that periods are useful, what operations on them do we want? Arithmetic, probably; maybe the `period-nanoseconds` function I just mentioned; maybe convenience functions based on the current time (e.g., `ago`, `from-now`). Anything else? - How do we represent a period? The obvious choice: (struct period (sign years months ...)) - Then what happens to the interface of `duration-between`? Maybe it returns a period where non-requested field values are #f. Do I still request fields by providing a list of symbols? I do like the fact that, in the current interface, the symbol you pass in to request that a field appear in the output is the key that you use to access that field in the result (which is currently an alist). It's not that I love alists, but I haven't come up with a struct-based interface that I like better. So maybe a period just is an alist (as described by the range contract of `duration-between`)? I am absolutely open to any thoughts you, or anyone else on the list, has. Since this conversation might not be of general interest, we could move it over to gregor's github site and use the issue tracker. Most of all, thank you for your interest. -Jon At Wed, 25 Mar 2015 21:55:31 -0400, Jon Zeppieri wrote: I recently uploaded Gregor, a date and time library, to the package server. Features: - representations for and generic operations on: - dates - times (as in, time-of-day) - datetimes (combined date and time) - moments (combined datetime and IANA/Olson timezone) - date arithmetic - localized formatting and parsing, using CLDR data As you might expect from the name, Gregor uses a (proleptic) Gregorian calendar. Documentation: http://pkg-build.racket-lang.org/doc/gregor/index.html Source and bug tracking: https://github.com/97jaz/gregor -Jon -- 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] ANN: Gregor, a date and time library
I've used a library like this before [https://github.com/jeremyw/stamp], and realized that there were two things I didn't like about it: (1) potential ambiguity in the (user-)chosen exemplar date/time and (2) my tendency to mistake the exemplar date for an actual piece of data in the program. Go's approach probably helps with both problems. On Thu, Mar 26, 2015 at 6:43 PM, Sam Tobin-Hochstadt sa...@cs.indiana.edu wrote: On Thu, Mar 26, 2015 at 4:26 PM Jon Zeppieri zeppi...@gmail.com wrote: On Thu, Mar 26, 2015 at 3:56 PM, John Clements cleme...@brinckerhoff.org wrote: On Mar 25, 2015, at 6:55 PM, Jon Zeppieri zeppi...@gmail.com wrote: I recently uploaded Gregor, a date and time library, to the package server. Can I use this instead of SRFI 19? That would be wonderful. John Clements Please do, and let me know what additions or changes you'd like. One cool feature I've seen [1] is formatting dates based on existing formatted dates. IOW, something like this: (~t (today) 1/1/2000) [1] Go does a variant of this but it looks like it has to be one specific date in 2006: http://golang.org/pkg/time/#pkg-constants -- 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] ANN: Gregor, a date and time library
On Thu, Mar 26, 2015 at 5:30 PM, Jon Zeppieri zeppi...@gmail.com wrote: 3 weeks and 40 hours will always have a fixed number of seconds... And this is because Gregor isn't faithful to UTC, of course. Otherwise, this wouldn't be true. -- 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] ANN: Gregor, a date and time library
On Thu, Mar 26, 2015 at 5:27 PM, Robby Findler ro...@eecs.northwestern.edu wrote: On Thu, Mar 26, 2015 at 4:13 PM, Jon Zeppieri zeppi...@gmail.com wrote: You can carry around a bucket that says 5 years, 3 weeks, and 40 hours, but the precise number of seconds inside the bucket is indeterminate until you pour it over a date-provider. (No, not a great metaphor.) I have a feeling I'm going to regret this :), but why can't you know the precise number of seconds in that case? Is it because of leap years? Would 3 weeks and 40 hours always be a precise number of seconds? Robby Yes, leap years. 3 weeks and 40 hours will always have a fixed number of seconds, but not 5 years. Similarly, N months doesn't have a fixed duration, because months can be 28, 29, 30, or 31 days long. -Jon -- 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] ANN: Gregor, a date and time library
On Thu, Mar 26, 2015 at 10:51 AM, Vincent St-Amour stamo...@ccs.neu.edu wrote: This is really cool! Do you have plans for operations on durations? Vincent More vague thoughts than plans. So-- there's a useful distinction (that comes out of Joda-Time) between a duration, which is directly convertible to some number of (nano)seconds, and a period, which contains units like years and months that have no fixed duration. The Gregor function `duration-between` actually computes a period, according to this terminology. This raises a few questions (for me, anyhow): - Is a duration data structure, distinct from some number of nanoseconds, useful? In Joda it seems largely a way of (a) adding convenience functions for translating some number of years, months, days, etc. into a number of nanoseconds, and (b) converting some fixed duration to a period. Since both kinds of translation are lossy, I don't know how useful this is -- all the more so because, if we had some period data structure, we could always provide `period-nanoseconds`. - Assuming that periods are useful, what operations on them do we want? Arithmetic, probably; maybe the `period-nanoseconds` function I just mentioned; maybe convenience functions based on the current time (e.g., `ago`, `from-now`). Anything else? - How do we represent a period? The obvious choice: (struct period (sign years months ...)) - Then what happens to the interface of `duration-between`? Maybe it returns a period where non-requested field values are #f. Do I still request fields by providing a list of symbols? I do like the fact that, in the current interface, the symbol you pass in to request that a field appear in the output is the key that you use to access that field in the result (which is currently an alist). It's not that I love alists, but I haven't come up with a struct-based interface that I like better. So maybe a period just is an alist (as described by the range contract of `duration-between`)? I am absolutely open to any thoughts you, or anyone else on the list, has. Since this conversation might not be of general interest, we could move it over to gregor's github site and use the issue tracker. Most of all, thank you for your interest. -Jon At Wed, 25 Mar 2015 21:55:31 -0400, Jon Zeppieri wrote: I recently uploaded Gregor, a date and time library, to the package server. Features: - representations for and generic operations on: - dates - times (as in, time-of-day) - datetimes (combined date and time) - moments (combined datetime and IANA/Olson timezone) - date arithmetic - localized formatting and parsing, using CLDR data As you might expect from the name, Gregor uses a (proleptic) Gregorian calendar. Documentation: http://pkg-build.racket-lang.org/doc/gregor/index.html Source and bug tracking: https://github.com/97jaz/gregor -Jon -- 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.