Re: [racket-users] Note: DB layer does not handle Pg enums

2017-10-16 Thread Jay Kominek
On Mon, Oct 16, 2017 at 12:04 PM, David Storrs <david.sto...@gmail.com>
wrote:

> Not a critical issue, but the db package will not handle enums in
> Postgres.  This is clear from the docs but I just now tripped over it
> and thought I'd raise awareness.
>
> Workaround:  make the field of type TEXT and then add a table constraint:
> CONSTRAINT "files_current_state_cns" CHECK (current_state in
> ('INFO','NEW','COPYING','OK')),
>

You can also change your query, instead of the table, with something like:

(query-exec db "insert into files (..., ($1::text)::file_state, ...)" "OK")

that query now expects the client side to provide a text value for $1
(which the racket code is completely capable of); the server will handle
the cast from text to file_state for you. Similarly you can get data in
unsupported types from the database by adding a cast to text in your
selects.

-- 
Jay Kominek

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and 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] db: postgresql current_date - timestamptz

2015-07-20 Thread Jay Kominek
You might be ending up with different timezones set on the different
connections, as libpq clients can automatically set/change some
session settings that the racket library does not. I'd try running
show timezone via both connections, and see what you end up with.

On Mon, Jul 20, 2015 at 12:29 PM, George Neuner gneun...@comcast.net wrote:
 Hi all,

 I'm found something strange with Racket 6.1.1  and Postgresql (9.3.6):  SQL
 that works differently in a Racket query than in the DB console.


 I have a table defined as

create table blah
(
   a  char(15),
   b  char(15),
   created timestamp with time zone,
   expires timestamp with time zone
);

 and an insert query

(set! sql-cmd (string-join `(
  insert into blah (a,b,created,expires)
values ( $1
,$2
,current_date
,current_date + interval ' ,(number-string
 (expire-days))  days'
)
  )))
(query-exec db sql-cmd  some_characters more_characters )

 where the value of (expire-days) is 30.


 When I execute this in Racket, the dates entered into the table are off by 1
 day and have an erroneous hour component:  e.g., today is 7-20, the values
 entered are  created =  2015-07-19 20:00:00-04  and  expires = 2015-08-18
 20:00:00-04.

 Obviously the problem is with current_date, however ...


 When I execute the analogous code directly from the DB console

insert into stats.surveys_restrict (a,b,created,expires)
  values ('some_characters'
 ,'more_characters'
 ,current_date
 ,current_date + interval '30 days')

 I get the expected values:  created = 2015-07-20 00:00:00-04  and  expires =
 2015-08-19 00:00:00-04.


 Since the dates are in the SQL code rather than passed arguments to the
 Racket query call, I don't understand how this is happening ... I would have
 expected to see the same behavior in the console.  Casting the dates to type
 timestamptz in the SQL doesn't change the results (in either Racket or the
 console).

 If I substitute current_timestamp  instead of current_date, the query works
 as expected both in Racket and in the console.  However, the Postgresql docs
 say that current_date is coerced to timestamp and the behavior of the
 console seems to confirm that.  I don't understand why I get a different
 value from the Racket query.

 This isn't a I problem per se as I can substitute current_timestamp without
 issue, but since the program logic currently doesn't need the time
 component, I had thought to use current_date instead.

 Any clues as to what is happening?
 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.



-- 
Jay Kominek

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and 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: Use Parsack to parse a #language?

2015-05-14 Thread Jay Kominek
On Mon, May 11, 2015 at 11:01 PM, Daniel Prager
daniel.a.pra...@gmail.com wrote:
 Once I get my head around what's needed to connect up a custom
 reader, I should be in a position to have a shot ... and ask further
 questions.

I put together a #lang unlambda which has a custom reader, semantics,
provides a color
lexer for DrRacket, and works with the REPL. The code is quite small,
so it ought to serve
as a passable example of those integrations.

https://github.com/jkominek/unlambda

-- 
Jay Kominek

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and 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: [racket] How to call a Julia function from DrRacket?

2015-05-02 Thread Jay Kominek
On Sat, May 2, 2015 at 4:00 PM, Geoffrey Knauth ge...@knauth.org wrote:
 On Friday, May 1, 2015 at 5:53:04 PM UTC-4, Greg Trzeciak wrote:
 It's an old thread but just in case someone is looking for the answer Julia 
 has (now?) C API:
 http://julia.readthedocs.org/en/latest/manual/embedding/

 I hesitate to mention connecting Racket to Fortran some day but I wonder if 
 that's ever been done.  Nine years ago when I worked on parallel programming 
 enhancements to Octave, the free MATLAB-workalike written in C++, Octave 
 leaned heavily on Fortran scientific libraries that had been highly optimized 
 over decades.  Julia is also speedy doing math.

I wrapped a bit of Fortran recently:

https://github.com/jkominek/lbfgsb/

I had to learn more about the Fortran ABI than I cared to, but it's
doable. If you needed to do a lot of it, it would be worth creating
something like ffi/fortran/unsafe with FFI types that map a bit more
directly to Fortran's types, and wrapping _fun with something that
know's about Fortran's quirks.

-- 
Jay Kominek

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and 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

2015-03-26 Thread Jay Kominek
On Thu, Mar 26, 2015 at 2:57 PM, Vincent St-Amour stamo...@ccs.neu.edu wrote:
 At Thu, 26 Mar 2015 14:30:28 -0400, Jon Zeppieri wrote:

 On Thu, Mar 26, 2015 at 10:51 AM, Vincent St-Amour stamo...@ccs.neu.edu 
 wrote:
 - 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`.

Having written a bunch of Python stuff using timeinterval, I'm maybe
98% of the time just trying to shift a date/time/datetime by X
milliseconds, or find out how many milliseconds apart two things are.
Representing that as a fancy structure has almost never been useful.
The one or two times it has been handy are easily outweighed by all
the extra typing it has cost me over the years.

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

I can't remember ever needing to compute how many seconds there were
in some user-friendly period representation. Usually I'm trying to
avoid such things ever becoming seconds, because then I'll end up with
the wrong answer sooner or later.

{,micro,nano}seconds-between has been what I've wanted every time.

On Thu, Mar 26, 2015 at 3:55 PM, Greg Hendershott
greghendersh...@gmail.com wrote:
 - 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?

 1. For scheduling apps people often deal with things like Monday
 every 2 weeks, the 1st and 3rd Wednesday of every month, or the
 last Friday of every month. Maybe Gregor could do that? (Maybe
 parsing and formatting _text_ like that belongs in another package, I
 don't know.)

Some sort of 1st and 3rd wednesday of every month starting from X
sequence generator would be incredible.

Parsing text like that hasn't ever come up for me, but I could imagine
it being useful.

 2. Another useful concept is weekdays. Or more generally (sorry) work
 days. So, a way to specify a set of excluded days (holidays). Of
 course some holidays have weird specifications (the 3rd Thursday of
 November) that could benefit from 1.

Having a package provided implementation of this, and some holiday
checking stuff (maybe with a database of common holidays) would
simplify even further some of the programs I've got on my
rewrite-in-racket list.



Thanks so much for making this!

-- 
Jay Kominek

-- 
You received this message because you are subscribed to the Google Groups 
Racket Users group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.