Re: [racket-users] Getting JSON to work with the DB module

2019-04-23 Thread Ryan Culpepper
It is not possible, unfortunately. You must do the conversion to and 
from strings yourself.


I've thought about adding a hook for additional conversions based on 
declared types, but there's no declared type information at all for 
parameters, and the declared type for results is fragile: a column name 
has a declared type but no other kind of expression does.


Ryan


On 4/23/19 20:03, David Storrs wrote:
tl;dr  I'm having trouble getting JSON support working in the db module 
when using SQLite and would really appreciate some direction, or 
confirmation that it's impossible.  I suspect that it's impossible, 
since the docs list the accepted Racket types as exact-integer?, real?, 
string?, and bytes?.  I was hoping that having the JSON extension in 
would add conversion ability to this, but it looks like not.



Longer:
SQLite does not natively support JSON, but there's an extension that can 
be dynamically- or statically linked. https://sqlite.org/json1.html


When working with a Postgres database, the DB module will handle 
transforming things (e.g. hashes) to and from JSON on insert/select, 
which is insanely useful and convenient.  I'd like to get the same 
behavior in SQLite, especially since that would let me use the json_agg 
function which would be a reasonable replacement for Pg's ARAAY_AGG 
feature, of which I make heavy use.




Here's what I've done so far:

0. I've read the docs on the db module carefully, which has me concerned 
about whether this is possible at all.  Still, optimism!

1. I've compiled the JSON1 extension into the libsqlite.* files
2. I've verified that JSON is working via the sqlite CLI client (i.e., 
not the Racket db module)
3. I've put the libsqlite.* files in my /Applications/Racket_v7.1/lib 
directory (one of the entries in (get-lib-search-dirs)).


At this point I tried this:

 > (require json db)
 > (define db (sqlite3-connect #:database "foo.db"))
 > (query db "create temporary table blogsnort (id integer primary key, 
data json))

(simple-result '((insert-id . #f) (affected-rows . 0)))

 > (query db "insert into blogsnort (data) values ($1)" (hash 'a 1))
; query: cannot convert given value to SQL type
;   given: '#hash((a . 1))
;   type: parameter
;   dialect: SQLite
; [,bt for context]

I tried setting the storage class on the 'data' column to TEXT (I wasn't 
sure if the JSON extension added a 'JSON' type but figured it was worth 
trying), but that made no difference.


Am I right that it's simply impossible and that I'll need to manually 
convert to/from strings?




--
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 do I clear this FFI-related build error?

2019-04-23 Thread Matthew Flatt
At Tue, 23 Apr 2019 23:39:04 +0200, Ryan Culpepper wrote:
> It looks like natipkg Racket includes libharfbuzz.so.0, not 
> libharfbuzz.so.1 (see [1]). So try changing the unix line to
> 
>  [(unix) (ffi-lib "libharfbuzz" '("0" ""))]
> 
> instead.

Right.

Just to elaborate a little, there is no "libharfbuzz.so.1", so by using
'("1" "") you end up picking up "libharfbuzz.so" from the OS instead of
the "libharfbuzz.so.0" natipkg build, and the pkg-build OS is old.

I don't know why it's "libharfbuzz.so.0" for Harfbuzz 1.7.6, but
that's how Harfbuzz builds and is normally installed.

-- 
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 do I clear this FFI-related build error?

2019-04-23 Thread Ryan Culpepper

On 4/23/19 23:14, Matthew Butterick wrote:

Some code relies on the `harfbuzz` library, like so:

(define-runtime-lib harfbuzz-lib
   [(unix) (ffi-lib "libharfbuzz" '("1" ""))]
   [(macosx) (ffi-lib "libharfbuzz.0.dylib")]
   [(windows) (ffi-lib "libharfbuzz-0.dll")])


Though this works on my Mac machines, the doc server throws an error: [1]

raco setup:   ffi-obj: couldn't get "hb_buffer_add_codepoints" from 
"libharfbuzz.so" (/usr/lib/x86_64-linux-gnu/libharfbuzz.so: undefined symbol: 
hb_buffer_add_codepoints)


The `hb_buffer_add_codepoints` function was added in Harfbuzz 0.9.31, 
but according to Racket's readme, it ships with Harfbuzz 1.7.6 [2]


Judging by the Harfbuzz path in the error message, I wonder if I'm 
inadvertently invoking some local copy of Harfbuzz (which is out of 
date) rather than the one that ships with Racket (which isn't). But if 
so, I don't know how to change the `define-runtime-lib` incantation to 
make it work.


It looks like natipkg Racket includes libharfbuzz.so.0, not 
libharfbuzz.so.1 (see [1]). So try changing the unix line to


[(unix) (ffi-lib "libharfbuzz" '("0" ""))]

instead.

Ryan

[1] 
https://github.com/racket/libs/tree/master/draw-x86_64-linux-natipkg-3/racket/draw


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


[racket-users] how do I clear this FFI-related build error?

2019-04-23 Thread Matthew Butterick
Some code relies on the `harfbuzz` library, like so:

(define-runtime-lib harfbuzz-lib
  [(unix) (ffi-lib "libharfbuzz" '("1" ""))]
  [(macosx) (ffi-lib "libharfbuzz.0.dylib")]
  [(windows) (ffi-lib "libharfbuzz-0.dll")])


Though this works on my Mac machines, the doc server throws an error: [1]

raco setup:   ffi-obj: couldn't get "hb_buffer_add_codepoints" from 
"libharfbuzz.so" (/usr/lib/x86_64-linux-gnu/libharfbuzz.so: undefined symbol: 
hb_buffer_add_codepoints) 

The `hb_buffer_add_codepoints` function was added in Harfbuzz 0.9.31, but 
according to Racket's readme, it ships with Harfbuzz 1.7.6 [2]

Judging by the Harfbuzz path in the error message, I wonder if I'm 
inadvertently invoking some local copy of Harfbuzz (which is out of date) 
rather than the one that ships with Racket (which isn't). But if so, I don't 
know how to change the `define-runtime-lib` incantation to make it work. 


[1] 
https://pkg-build.racket-lang.org/server/built/fail/quad.txt 


[2] 
https://github.com/racket/racket/blob/709258d88c879c2489a977e85d34f77d760a0008/racket/src/native-libs/README.txt
 


-- 
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 would you implement autoquoted atoms?

2019-04-23 Thread zeRusski
On Tuesday, 23 April 2019 15:57:52 UTC+1, Matthew Flatt wrote:
>
> This response will be rambling, too. :) 


And here I thought I asked an embarrassingly silly question :)

While implementing a "naive" version I ran into two issues that I kind of 
predicted upfront, but just wanted to make sure they indeed would present a 
problem:

#lang prelude/tags

(list 1 #k(foo) 2)
;; => (tag 'foo) as rewritten by our extended reader, 
;; where tag is a struct provided by prelude/tags

(begin-for-syntax
  (list 1 #k(foo) 2))
;; => ; tag: undefined;

This can be solved with (require (for-syntax prelude/tags)) but as with 
other autoquoted types I'd probably want to be able to just write them in 
any phase. Docs say some stuff about namespaces having a scope that crosses 
all phases plus separate scopes for each phase. Is there a way for a 
binding to span all phases without cooperation from the user?

Another problem is with REPL. Above runs fine when I run the module, but 
not if I type in REPL. 

scratch.rkt> (list 1 #k(foo))
; stdin::1273: read-syntax: bad syntax `#k`
; foo: undefined;
;  cannot reference an identifier before its definition
;   in module: "/Users/russki/Code/scratch.rkt"

What's up with that? Does the reader there need to be defined specially 
somehow?

I would be really happy to see someone experiment with these ideas, and 
> I'm pretty sure they could be implemented mostly by changing the 
> expander and reader in "racket/src/expander"


I'd love to see this implemented, but  Racket internals terrify me. As you 
can see above I can barely cope with the basics :)

-- 
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] Question regarding the function printBoard board

2019-04-23 Thread Stefan Schmiedl


"orenpa11" , 23.04.2019, 20:53:

> Hi
> I am using  the functionprintBoard board  (DrRacket  Pretty Big) 
>
> (printBoard  '((0 0 2 0) (0 0 0 0) (0 0 8 0) (0 0 0 0)))
> and the result is 
>
> (0 0 2 0)
> (0 0 0 0)
> (0 0 8 0)
> (0 0 0 0)
> "" 

No, it is not. The *print output* is
(0 0 2 0)
(0 0 0 0)
(0 0 8 0)
(0 0 0 0)
while the *return value* is the empty string "" as
implemented in your code.

> How do I delete the "" ?

How would you change your question given the information above?

s.

> I would like the output to be  
> (0 0 2 0)
> (0 0 0 0)
> (0 0 8 0)
> (0 0 0 0)
>
> P.S. the code is 
>
> (define (buildBoard n)   ;build the started board  
>(cond ((= n 0) '())
>  (else (cons '(0 0 0 0) (buildBoard (sub1 n))
>
> (define (printBoard board) ;print the board
>   (cond ((empty? board) "" ) 
> (else (writeln(first board))
>  (printBoard (rest board)


-- 
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] Question regarding the function printBoard board

2019-04-23 Thread orenpa11
Thanks

On Tuesday, April 23, 2019 at 9:59:35 PM UTC+3, Dexter Lagan wrote:
>
> Hi there!
>
>   You can suppress à function’s output with (void (func ...)) like so:
>
> (void (printBoard  '((0 0 2 0) (0 0 0 0) (0 0 8 0) (0 0 0 0
>
> Or you can modify your original function and replace the “” by (void) like 
> so:
>
> ...
> (cond ((empty? board) (void) ) 
> ...
>
> Dexter
>
> On Apr 23, 2019, at 8:53 PM, orenpa11 > 
> wrote:
>
> Hi
> I am using  the functionprintBoard board  (DrRacket  Pretty Big) 
>
> (printBoard  '((0 0 2 0) (0 0 0 0) (0 0 8 0) (0 0 0 0)))
>
> and the result is 
>
> (0 0 2 0)
> (0 0 0 0)
> (0 0 8 0)
> (0 0 0 0)
> "" 
>
> How do I delete the "" ?
>
> I would like the output to be  
>
> (0 0 2 0)
> (0 0 0 0)
> (0 0 8 0)
> (0 0 0 0)
>
> Thanks
>
>
> P.S. the code is 
>
> (define (buildBoard n)   ;build the started board  
>(cond ((= n 0) '())
>  (else (cons '(0 0 0 0) (buildBoard (sub1 n))
>
> (define (printBoard board) ;print the board
>   (cond ((empty? board) "" ) 
> (else (writeln(first board))
>  (printBoard (rest board)
>
>
>
>  
>
> -- 
> 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...@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] Question regarding the function printBoard board

2019-04-23 Thread Dexter Lagan
Hi there!

  You can suppress à function’s output with (void (func ...)) like so:

(void (printBoard  '((0 0 2 0) (0 0 0 0) (0 0 8 0) (0 0 0 0

Or you can modify your original function and replace the “” by (void) like so:

...
(cond ((empty? board) (void) ) 
...

Dexter

> On Apr 23, 2019, at 8:53 PM, orenpa11  wrote:
> 
> Hi
> I am using  the functionprintBoard board  (DrRacket  Pretty Big) 
> 
> (printBoard  '((0 0 2 0) (0 0 0 0) (0 0 8 0) (0 0 0 0)))
> 
> and the result is 
> 
> (0 0 2 0)
> (0 0 0 0)
> (0 0 8 0)
> (0 0 0 0)
> "" 
> 
> How do I delete the "" ?
> 
> I would like the output to be  
> 
> (0 0 2 0)
> (0 0 0 0)
> (0 0 8 0)
> (0 0 0 0)
> 
> Thanks
> 
> 
> P.S. the code is 
> 
> (define (buildBoard n)   ;build the started board  
>(cond ((= n 0) '())
>  (else (cons '(0 0 0 0) (buildBoard (sub1 n))
> 
> (define (printBoard board) ;print the board
>   (cond ((empty? board) "" ) 
> (else (writeln(first board))
>  (printBoard (rest board)
> 
> 
> 
>  
> -- 
> 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] Question regarding the function printBoard board

2019-04-23 Thread orenpa11
Hi
I am using  the functionprintBoard board  (DrRacket  Pretty Big) 

(printBoard  '((0 0 2 0) (0 0 0 0) (0 0 8 0) (0 0 0 0)))

and the result is 

(0 0 2 0)
(0 0 0 0)
(0 0 8 0)
(0 0 0 0)
"" 

How do I delete the "" ?

I would like the output to be  

(0 0 2 0)
(0 0 0 0)
(0 0 8 0)
(0 0 0 0)

Thanks


P.S. the code is 

(define (buildBoard n)   ;build the started board  
   (cond ((= n 0) '())
 (else (cons '(0 0 0 0) (buildBoard (sub1 n))

(define (printBoard board) ;print the board
  (cond ((empty? board) "" ) 
(else (writeln(first board))
 (printBoard (rest board)



 

-- 
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] Getting JSON to work with the DB module

2019-04-23 Thread David Storrs
tl;dr  I'm having trouble getting JSON support working in the db module
when using SQLite and would really appreciate some direction, or
confirmation that it's impossible.  I suspect that it's impossible, since
the docs list the accepted Racket types as exact-integer?, real?, string?,
and bytes?.  I was hoping that having the JSON extension in would add
conversion ability to this, but it looks like not.


Longer:
SQLite does not natively support JSON, but there's an extension that can be
dynamically- or statically linked.  https://sqlite.org/json1.html

When working with a Postgres database, the DB module will handle
transforming things (e.g. hashes) to and from JSON on insert/select, which
is insanely useful and convenient.  I'd like to get the same behavior in
SQLite, especially since that would let me use the json_agg function which
would be a reasonable replacement for Pg's ARAAY_AGG feature, of which I
make heavy use.



Here's what I've done so far:

0. I've read the docs on the db module carefully, which has me concerned
about whether this is possible at all.  Still, optimism!
1. I've compiled the JSON1 extension into the libsqlite.* files
2. I've verified that JSON is working via the sqlite CLI client (i.e., not
the Racket db module)
3. I've put the libsqlite.* files in my /Applications/Racket_v7.1/lib
directory (one of the entries in (get-lib-search-dirs)).

At this point I tried this:

> (require json db)
> (define db (sqlite3-connect #:database "foo.db"))
> (query db "create temporary table blogsnort (id integer primary key, data
json))
(simple-result '((insert-id . #f) (affected-rows . 0)))

> (query db "insert into blogsnort (data) values ($1)" (hash 'a 1))
; query: cannot convert given value to SQL type
;   given: '#hash((a . 1))
;   type: parameter
;   dialect: SQLite
; [,bt for context]

I tried setting the storage class on the 'data' column to TEXT (I wasn't
sure if the JSON extension added a 'JSON' type but figured it was worth
trying), but that made no difference.

Am I right that it's simply impossible and that I'll need to manually
convert to/from strings?

-- 
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 would you implement autoquoted atoms?

2019-04-23 Thread Alexis King
I find this email fascinating, as about three weeks ago, Spencer Florence and I 
discussed something almost identical, from the module path + symbol protocol 
all the way down to the trouble with `quote`. I had been intending to 
experiment with implementing the idea at some point, but I already have a few 
too many balls in the air right now (from the intdef changes I’ve been 
exploring to the `hash-key` implementation I started fiddling with, plus 
starting the process of looking for a new job), so I probably won’t get to it 
any time soon. But I’ll go on record as being interested in doing so.

> On Apr 23, 2019, at 09:57, Matthew Flatt  wrote:
> 
> This response will be rambling, too. :)
> 
> Especially with your follow-up message, I think you're getting to a
> problem that we've wrestled with for a while. Sometimes we've called it
> the "graphical syntax" problem, because it's related to having non-text
> syntax, such as images in DrRacket (which are currently implemented in
> an ad hoc way). Another example could be adding quaternion literals,
> analogous to complex-number literals. In the cases that we've
> considered, we want the language to be extensible with a new kind of
> literal, but there's not necessary any specific import the language
> extension in the program. That means there's a set of binding,
> evaluation, and composition problems to solve.
> 
> 
> I've discussed the problem the most with William Hatch, and here's as
> far as we got with some ideas.
> 
> There could be a new primitive datatype --- at the levels of symbols,
> pairs, vectors, etc. --- to let the reader and expander communicate.
> Just to have some concrete syntax for the default reader and printer,
> let's say that the new kind of value can be written with `#q`, perhaps
> of the form
> 
>  #q(  )
> 
> The intent of the  and  components is to give
> the value a kind of binding. That binding is analogous to syntax
> objects, but without actually using syntax objects, which is arguably
> the wrong concept to pull into the reader level. The remaining
>  is payload to be interpreted by the  and
>  combination, such as image data or real numbers for the
> components of a quaternion.
> 
> Of course, a reader might construct these values as a result of parsing
> some other text, but the idea is that printing out the result from that
> reader with the default printer would use this `#q` notation, and then
> that printed form could be read back in. That is, the values can be
> consistently marshaled and unmarshaled, just like pairs and vectors and
> numbers.
> 
> The benefit of a new datatype is that it can have its own dispatch rule
> in the expander. Probably a `#q` in an expression position would get
> wrapped by an implicit `#%q-expression`, or something like that, which
> would give a language control over whether it wants to allow arbitrary
> literal values. But the default `#%q-expression` would consult the
> value's "binding" via the  and  to expand the
> value, which might inline an image or quaternion construction, or
> something like that. In effect, the reader form carries its own
> `require` at all times.
> 
> Maybe interning corresponds to an expansion that lifts out a
> calculation (in the sense of `syntax-local-lift-expression`), or maybe
> that's not good enough; I'm not sure.
> 
> We imagined that the primitive `quote` form might do something similar
> to `#%q-expression` in the case that an image or quaternion is part of
> a quoted S-expression. But, then, does there need to be an even
> stronger `quote` that doesn't try to expand the `#q` content? I don't
> know.
> 
> Meanwhile, the  and  combination could also
> identify a value-specific printer, where images might recognize when
> the output context can support rendering the actual image, while
> quaternions might print using "+" and "i" and "j". Or maybe that
> problem should be left to `prop:custom-write`.
> 
> At the level of writing down programs, the examples or images and
> quaternions seem different. For images, DrRacket and other editors have
> to include the concept of images somehow, and they insert values that
> turn into `#q` forms when the program is viewed as a character
> sequence. But quaternions are written with characters, so maybe that
> syntax is more like `@` reading in that a language constructor on the
> `#lang` line would add quaternion syntax to the readtable (which would
> work for S-expression languages).
> 
> 
> Overall, this reply is intended as a kind of endorsement and
> elaboration of your thoughts: Yes, this is an interesting problem, and
> it seems to need something new in Racket. And, yes, adding some new
> datatype (with some default syntax) seems like the right direction,
> mainly because it could trigger a new kind of dispatch in the expander.
> Probably that new datatype should have something built-in that amounts
> to a binding for it's compile-time and run-time realization.
> 
> I would be really happy to see someone 

Re: [racket-users] make extensions or replacements

2019-04-23 Thread William G Hatch

On Tue, Apr 16, 2019 at 04:55:49PM -0400, Hendrik Boom wrote:

On Tue, Apr 16, 2019 at 10:13:47PM +0200, Jens Axel Søgaard wrote:

Hav you tried the make library?

https://docs.racket-lang.org/make/index.html?q=make


If you like Racket's make library but want something a little more
shell-like, I made a toy rash/demo/make language that has something
closer to a traditional `make` feel.  It's definitely a toy now, but I
don't think it would be a huge project to make a version that is more
reasonably useful.

I'm not offering to do that right now, but I'm offering it as an idea
you can chase if you like.  (Someday I'm likely to do it myself.  But
not in the immediate future.)

--
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 would you implement autoquoted atoms?

2019-04-23 Thread Matthew Flatt
This response will be rambling, too. :)

Especially with your follow-up message, I think you're getting to a
problem that we've wrestled with for a while. Sometimes we've called it
the "graphical syntax" problem, because it's related to having non-text
syntax, such as images in DrRacket (which are currently implemented in
an ad hoc way). Another example could be adding quaternion literals,
analogous to complex-number literals. In the cases that we've
considered, we want the language to be extensible with a new kind of
literal, but there's not necessary any specific import the language
extension in the program. That means there's a set of binding,
evaluation, and composition problems to solve.


I've discussed the problem the most with William Hatch, and here's as
far as we got with some ideas.

There could be a new primitive datatype --- at the levels of symbols,
pairs, vectors, etc. --- to let the reader and expander communicate.
Just to have some concrete syntax for the default reader and printer,
let's say that the new kind of value can be written with `#q`, perhaps
of the form

  #q(  )

The intent of the  and  components is to give
the value a kind of binding. That binding is analogous to syntax
objects, but without actually using syntax objects, which is arguably
the wrong concept to pull into the reader level. The remaining
 is payload to be interpreted by the  and
 combination, such as image data or real numbers for the
components of a quaternion.

Of course, a reader might construct these values as a result of parsing
some other text, but the idea is that printing out the result from that
reader with the default printer would use this `#q` notation, and then
that printed form could be read back in. That is, the values can be
consistently marshaled and unmarshaled, just like pairs and vectors and
numbers.

The benefit of a new datatype is that it can have its own dispatch rule
in the expander. Probably a `#q` in an expression position would get
wrapped by an implicit `#%q-expression`, or something like that, which
would give a language control over whether it wants to allow arbitrary
literal values. But the default `#%q-expression` would consult the
value's "binding" via the  and  to expand the
value, which might inline an image or quaternion construction, or
something like that. In effect, the reader form carries its own
`require` at all times.

Maybe interning corresponds to an expansion that lifts out a
calculation (in the sense of `syntax-local-lift-expression`), or maybe
that's not good enough; I'm not sure.

We imagined that the primitive `quote` form might do something similar
to `#%q-expression` in the case that an image or quaternion is part of
a quoted S-expression. But, then, does there need to be an even
stronger `quote` that doesn't try to expand the `#q` content? I don't
know.

Meanwhile, the  and  combination could also
identify a value-specific printer, where images might recognize when
the output context can support rendering the actual image, while
quaternions might print using "+" and "i" and "j". Or maybe that
problem should be left to `prop:custom-write`.

At the level of writing down programs, the examples or images and
quaternions seem different. For images, DrRacket and other editors have
to include the concept of images somehow, and they insert values that
turn into `#q` forms when the program is viewed as a character
sequence. But quaternions are written with characters, so maybe that
syntax is more like `@` reading in that a language constructor on the
`#lang` line would add quaternion syntax to the readtable (which would
work for S-expression languages).


Overall, this reply is intended as a kind of endorsement and
elaboration of your thoughts: Yes, this is an interesting problem, and
it seems to need something new in Racket. And, yes, adding some new
datatype (with some default syntax) seems like the right direction,
mainly because it could trigger a new kind of dispatch in the expander.
Probably that new datatype should have something built-in that amounts
to a binding for it's compile-time and run-time realization.

I would be really happy to see someone experiment with these ideas, and
I'm pretty sure they could be implemented mostly by changing the
expander and reader in "racket/src/expander" --- although some
cooperation from the bytecode writer and reader is probably also needed,
and I'd be happy to help more there.


At Tue, 23 Apr 2019 06:08:05 -0700 (PDT), zeRusski wrote:
> I must apologies for what follows will be more of a rambling than an 
> exercise in clear thinking. That is because I am a bit stuck and thought 
> I'd seek help.
> 
> I have been thinking some about languages and how it isn't always easy to 
> clearly separate language being implemented from the language used to 
> implement it. The picture gets particularly blurry in Lisps. This time 
> around the question that gave me pause was one of implementing symbols. 
> Better still Racket 

Re: [racket-users] db module 'query' does not return insert-id

2019-04-23 Thread David Storrs
On Tue, Apr 23, 2019 at 4:33 AM Ryan Culpepper  wrote:

> On 4/22/19 20:36, David Storrs wrote:
> >  > (require db)
> >  > (define db (postgresql-connect  ...args...))
> >  > (simple-result-info (query db "insert into collaborations (name)
> > values ('foojalskdsfls')"))
> > '((insert-id . #f) (affected-rows . 1))
> >
> >  From the docs on the 'simple-result' struct:
> >
> > "Represents the result of a SQL statement that does not return a
> > relation, such as an INSERT or DELETE statement.
> >
> > The info field is an association list, but its contents vary based on
> > database system and may change in future versions of this library (even
> > new minor versions). The following keys are supported for multiple
> > database systems:
> >
> > #
> >
> > 'insert-id: If the value is a positive integer, the statement was an
> > INSERT statement and the value is a system-specific identifier for the
> > inserted row. For PostgreSQL, the value is the row’s OID, if the table
> > has OIDs (for an alternative, see the INSERT ... RETURNING statement).
> > For MySQL, the value is the same as the result of last_insert_id
> > <
> http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id>
>
> > function—that is, the value of the row’s AUTO_INCREMENT field. If there
> > is no such field, the value is #f. For SQLite, the value is the same as
> > the result of the last_insert_rowid
> > 
> > function—that is, the ROWID
> >  of the inserted
> row."
> >
> >
> > I get the same results with a SQLite connection -- the insert-id is
> > always #f.  I know that it says the contents may change and that it
> > varies per database, but it also specifically calls out 'insert-id as a
> > thing that is supported for both of these DBs.  What am I missing?
>
> On PostgreSQL, my guess is that your table was created without the "WITH
> OIDS" clause. For example:
>
>> (define c (dsn-connect 'pg))
>> (query c "create table words (t text)")
>(simple-result '())
>> (query c "insert into words (t) values ('hello')")
>(simple-result '((insert-id . #f) (affected-rows . 1)))
>
> and here's a example for a table with "WITH OIDS":
>
>> (query c "create table names (t text) with oids")
>(simple-result '())
>> (query c "insert into names (t) values ('Alice')")
>(simple-result '((insert-id . 105197) (affected-rows . 1)))
>
> On SQLite, there is a bug in the db library that suppresses insert-id if
> it is the same as the last reported insert-id (for a different table,
> for example). I'll fix that. But you should see it otherwise. For example:
>
>> (define c (sqlite3-connect #:database 'memory))
>> (query c "create table words (t text)")
>(simple-result '((insert-id . #f) (affected-rows . 0)))
>> (query c "insert into words (t) values ('hello')")
>(simple-result '((insert-id . 1) (affected-rows . 1)))
>
> Ryan
>

+1 Informative.

Thanks, Ryan.

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


Re: [racket-users] db module 'query' does not return insert-id

2019-04-23 Thread George Neuner


On 4/23/2019 4:32 AM, Ryan Culpepper wrote:


On PostgreSQL, my guess is that your table was created without the 
"WITH OIDS" clause. For example:


  > (define c (dsn-connect 'pg))
  > (query c "create table words (t text)")
  (simple-result '())
  > (query c "insert into words (t) values ('hello')")
  (simple-result '((insert-id . #f) (affected-rows . 1)))

and here's a example for a table with "WITH OIDS":

  > (query c "create table names (t text) with oids")
  (simple-result '())
  > (query c "insert into names (t) values ('Alice')")
  (simple-result '((insert-id . 105197) (affected-rows . 1)))


Creating tables with OIDs in Postgresql has been discouraged for a long 
time.

From the manual:

The OID type is currently implemented as an unsigned four-byte integer. 
Therefore, it is not large enough to provide database-wide uniqueness in 
large databases, or even in large individual tables. So, using a 
user-created table's OID column as a primary key is discouraged. OIDs 
are best used only for references to system tables.



That passage has been the same since v7.3.  The system default setting 
been *default_with_oids=FALSE*  (i.e. don't add OIDs when creating 
tables) since version 8.something.


see: https://www.postgresql.org/docs/8.0/datatype-oid.html

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.


Re: [racket-users] Re: How would you implement autoquoted atoms?

2019-04-23 Thread Jens Axel Søgaard
Yes, a global table of all existing keywords are needed.
I would do something along the lines of:

#lang racket
(struct Keyword (string))
(define global-keyword-hash (make-hash))

; keyword : string -> keyword
(define (keyword s)
  (define k (hash-ref global-keyword-hash s #f))
  (or k
  (let ()
(define k (Keyword s))
(hash-set! global-keyword-hash s k)
k)))

(eq? (keyword "a") (keyword "a"))
(eq? (keyword "a") (keyword "b"))
(eq? (keyword "b") (keyword "b"))


Den tir. 23. apr. 2019 kl. 15.22 skrev zeRusski :

> One thought that only just occurred to me is that we certainly want to
> allow creating kws dynamically, so a piece of code may generate some. IIUC
> this means it can no longer be a purely reader-based feature. Either reader
> and runtime have to communicate the global table somehow or the entire
> thing belongs at runtime save for actually parsing text. I wonder how
> taxing such implementation becomes. I feel like Racket keywords and
> interned symbols may have some lower language support that I can't access?
>
> --
> 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.
>


-- 
-- 
Jens Axel Søgaard

-- 
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: How would you implement autoquoted atoms?

2019-04-23 Thread zeRusski
One thought that only just occurred to me is that we certainly want to 
allow creating kws dynamically, so a piece of code may generate some. IIUC 
this means it can no longer be a purely reader-based feature. Either reader 
and runtime have to communicate the global table somehow or the entire 
thing belongs at runtime save for actually parsing text. I wonder how 
taxing such implementation becomes. I feel like Racket keywords and 
interned symbols may have some lower language support that I can't access?

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


[racket-users] How would you implement autoquoted atoms?

2019-04-23 Thread zeRusski
I must apologies for what follows will be more of a rambling than an 
exercise in clear thinking. That is because I am a bit stuck and thought 
I'd seek help.

I have been thinking some about languages and how it isn't always easy to 
clearly separate language being implemented from the language used to 
implement it. The picture gets particularly blurry in Lisps. This time 
around the question that gave me pause was one of implementing symbols. 
Better still Racket keywords, since like many lispy terms "symbol" has so 
many confusing meanings that its nigh impossible to tell what people mean 
exactly. I specifically talk about autoquoted datums. Two interned symbols 
that are equal? are eq?, two keywords that are equal? are eq?, 42 is eq? to 
42, etc. Symbols are bad example cause people often think about 'symbol or 
identifier with semantics being: perform variable lookup.

Someone on this list said everything in Racket is a struct, so lets start 
there.
 
 (struct kw (symbol))

We can also come up with some syntactic representation and extend our 
language with read and read-syntax that translate this new syntax into 
kw-struct as needed. But then we also demand that two syntactically equal 
kws end up being the same value in the language, so no matter where our 
reader encounters #kw(foo) it must produce the same value. This must be 
true across module boundaries, too. Just like Racket keywords. So, what are 
we to do? There's time when the reader runs, followed by expansion. Does 
this mean they need to communicate somehow? Also, the reader "runs", that 
is it is written in Racket (or some derivative) after all, but reader's 
environment isn't one where expansion happens, and that of the final code 
being evaled is different still. Right? 

To ensure eq? of two kws with the same printed representation we'll 
probably want to keep some global table around that keeps track of 
"interned" kws. So, for any two #kw(foo), our reader would have to produce 
something like (lookup-intern-kw  #:symbol 'foo), which at run-time would 
consult the table of kws and return the (kw 'foo) already there, or create 
a fresh entry and return that new struct. Two observations: (a) it follows 
that the global table is one that must exist at runtime - not while the 
reader runs, and (b) we end up relying on the host language for symbol 
equality after all 'foo is eq? 'foo and that allows us to key the table by 
symbols e.g. 'foo.

Is this how you would do it? Is there a better way that involves the reader 
more and relies on the runtime less?

Bonus question. What if we allow families of kws effectively partitioning 
kws into namespaces: #kw(family name). This appears a small variation of 
the above, where you'd simply assemble a compound symbol from family and 
name to use for the table lookup. That is until you allow parameterizing by 
"current-family", so kw declaration can omit the family part and it gets 
inserted as needed - not unreasonable in a language with modules or 
explicit namespaces. We could allow something like this:

#lang racket/kws
#:current-family addams

#kw(morticia)

now any kw within a module without family must translate into one of addams 
family. But also any #kw(addams morticia) in a different module must be eq? 
to the one above and in fact to any one like that anywhere. One exception 
is probably if we send them across Racket spaces which IIUC amount to 
running separate VMs. In the above example the reader would have to be 
aware of #:current-family declaration that may appear at the top of the 
module. We'd probably translate that to some (current-family 'addams) 
parameter setup, or wrap #%module-begin body in parameterize, then every kw 
without explicit family would have to check the (current-family) parameter. 

Is there a way to push this more to the read-time? If there is, what 
happens if we load the module and enter REPL? Could we ensure its reader is 
properly parameterized that it would use appropriate current-family?

How screwed up is my thinking here? Is there a way to leverage the reader 
more and rely on the runtime less? I imagine that'd make kws discussed 
lighter weight? We talk about phases some in Racket, but reader runs 
somewhere or rather sometime, too. I'd like to have a clearer picture in my 
head, I guess.

Thanks

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


[racket-users] How would you implement autoquoted atoms?

2019-04-23 Thread zeRusski
I must apologies for what follows will be more of a rambling than an 
exercise in clear thinking. That is because I am a bit stuck and thought 
I'd seek help.

I have been thinking some about languages and how it isn't always easy to 
clearly separate language being implemented from the language used to 
implement it. The picture gets particularly blurry in Lisps. This time 
around the question that gave me pause was one of implementing symbols. 
Better still Racket keywords, since like many lispy terms "symbol" has so 
many confusing meanings that its nigh impossible to tell what people mean 
exactly. I specifically talk about autoquoted datums. Two interned symbols 
that are equal? are eq?, two keywords that are equal? are eq?, 42 is eq? to 
42, etc. Symbols are bad example cause people often think about 'symbol or 
identifier with semantics being: perform variable lookup.

Someone on this list said everything in Racket is a struct, so lets start 
there.
 
 (struct kw (symbol))

We can also come up with some syntactic representation and extend our 
language with read and read-syntax that translate this new syntax into 
kw-struct as needed. But then we also demand that two syntactically equal 
kws end up being the same value in the language, so no matter where our 
reader encounters #kw(foo) it must produce the same value. This must be 
true across module boundaries, too. Just like Racket keywords. So, what are 
we to do? There's time when the reader runs, followed by expansion. Does 
this mean they need to communicate somehow? Also, the reader "runs", that 
is it is written in Racket (or some derivative) after all, but reader's 
environment isn't one where expansion happens, and that of the final code 
being evaled is different still. Right? 

To ensure eq? of two kws with the same printed representation we'll 
probably want to keep some global table around that keeps track of 
"interned" kws. So, for any two #kw(foo), our reader would have to produce 
something like (lookup-intern-kw  #:symbol 'foo), which at run-time would 
consult the table of kws and return the (kw 'foo) already there, or create 
a fresh entry and return that new struct. Two observations: (a) it follows 
that the global table is one that must exist at runtime - not while the 
reader runs, and (b) we end up relying on the host language for symbol 
equality after all 'foo is eq? 'foo and that allows us to key the table by 
symbols e.g. 'foo.

Is this how you would do it? Is there a better way that involves the reader 
more and relies on the runtime less?

Bonus question. What if we allow families of kws effectively partitioning 
kws into namespaces: #kw(family name). This appears a small variation of 
the above, where you'd simply assemble a compound symbol from family and 
name to use for the table lookup. That is until you allow parameterizing by 
"current-family", so kw declaration can omit the family part and it gets 
inserted as needed - not unreasonable in a language with modules or 
explicit namespaces. We could allow something like this:

#lang racket/kws
#:current-family addams

#kw(morticia)

now any kw within a module without family must translate into one of addams 
family. But also any #kw(addams morticia) in a different module must be eq? 
to the one above and in fact to any one like that anywhere. One exception 
is probably if we send them across Racket spaces which IIUC amount to 
running separate VMs. In the above example the reader would have to be 
aware of #:current-family declaration that may appear at the top of the 
module. We'd probably translate that to some (current-family 'addams) 
parameter setup, or wrap #%module-begin body in parameterize, then every kw 
without explicit family would have to check the (current-family) parameter. 

Is there a way to push this more to the read-time? If there is, what 
happens if we load the module and enter REPL? Could we ensure its reader is 
properly parameterized that it would use appropriate current-family?

How screwed up is my thinking here? Is there a way to leverage the reader 
more and rely on the runtime less? I imagine that'd make kws discussed 
lighter weight? We talk about phases some in Racket, but reader runs 
somewhere or rather sometime, too. I'd like to have a clearer picture in my 
head, I guess.

Thanks

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


Re: [racket-users] Are syntax transformations tree automata?

2019-04-23 Thread Matthias Felleisen


The coimputational power of Racket’s syntax transformation system is equivalent 
to that of Turing machines. [[ The expressive power is a bit limited and we’re 
working on expanding it, but I don’r think you’re asking about this. ]] — 
Matthias




> On Apr 23, 2019, at 7:29 AM, Ilnar Salimzianov  wrote:
> 
> 
> Hi all!
> 
> I was glancing over these books [1] and [2] on tree automata.
> 
> I assume that Racket's macro system / syntax transformations fall under
> the category of tree transducers.
> 
> Can anybody please point me to a paper which describes its expressive
> power in formal terms, if any?
> 
> The reason I ask is that one of the google-summer-of-code projects for
> apertium.org I'm involved with is to implement a recursive transfer
> system for translating natural languages.
> 
> I'm curious how the proposed system compares to racket's of the shelf
> pattern matching's or macros' expressiveness.
> 
> Such a paper will probably be above my head at this time, but if I knew
> that both the transfer system being developed at apertium and Racket's
> pattern matcher are actually, say, something called "synchronous context
> free grammars", it would be clear that there's not much point to develop
> something exactly like that from scratch at apertium.
> 
> Best,
> 
> Ilnar
> -- 
> GPG: 0xF3ED6A19
> 
> [1] https://arxiv.org/abs/1509.06233
> [2]
> https://gforge.inria.fr/frs/?group_id=426_id=3091#tata-_2008-11-title-content
> 
> -- 
> 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] Online IDE’s for Racket ?

2019-04-23 Thread Stephen De Gabrielle
Hi

I found that you can run DrRacket on rollApp virtualisation platform[1].

Are there any other online IDE’s for Racket? I’m interested in both
in-browser repl/editor combinations or virtualised DrRacket.

Stephen

[1] rollApp DrRacket free version does not permit saving. Signup required.
https://www.rollapp.com/app/drracket

-- 


-- 
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] Are syntax transformations tree automata?

2019-04-23 Thread Ilnar Salimzianov


Hi all!

I was glancing over these books [1] and [2] on tree automata.

I assume that Racket's macro system / syntax transformations fall under
the category of tree transducers.

Can anybody please point me to a paper which describes its expressive
power in formal terms, if any?

The reason I ask is that one of the google-summer-of-code projects for
apertium.org I'm involved with is to implement a recursive transfer
system for translating natural languages.

I'm curious how the proposed system compares to racket's of the shelf
pattern matching's or macros' expressiveness.

Such a paper will probably be above my head at this time, but if I knew
that both the transfer system being developed at apertium and Racket's
pattern matcher are actually, say, something called "synchronous context
free grammars", it would be clear that there's not much point to develop
something exactly like that from scratch at apertium.

Best,

Ilnar
-- 
GPG: 0xF3ED6A19

[1] https://arxiv.org/abs/1509.06233
[2]
https://gforge.inria.fr/frs/?group_id=426_id=3091#tata-_2008-11-title-content

-- 
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: Defeating Racket’s separate compilation guarantee

2019-04-23 Thread rocketnia
Thanks for exploring this!

I was tempted down this path earlier this year because I was trying to 
future-proof my structure type definitions by making them cross-phase 
persistent. I see no innate reason for them not to be, so I figured I'd put 
in the effort early and avoid having to make a breaking change later on.

In the end, it turned out I wanted my structure type definitions to use 
certain things like `gen:custom-write` and `gen:equal+hash` that aren't 
supported by cross-phase persistent modules. In fact, the cross-phase 
persistent modules in Racket seem to have very few *specified* exports at 
all[1][2][3], so I was afraid I might rely on some unspecified behavior 
today and find it missing tomorrow. On top of that, even a cross-phase 
persistent module doesn't "persist" across multiple module registries, so 
it doesn't fully match my expectations.

This logger approach looks like it could achieve something just as 
"persistent" as a cross-phase persistent module (unfortunately not 
persisting over multiple module registries or multiple loggers), and with 
very little use of unspecified behavior along the way (although I see you 
still rely on a few exports of `#%kernel`, particularly `gensym`). Of 
course, if it runs up against the separate compilation guarantee, this 
might be the kind of specified behavior that's ruled to be a specification 
error someday.

As for what to do about it...

It seems to me that the separate compilation guarantee's exception for 
"external effects" means it's not a very strict guarantee. As long as 
compile-time code can interact back and forth with the outside world, an 
occasional programmer may rig up a system in the outside world that serves 
no purpose except to be an accomplice in breaking the guarantee.

If the root logger can be that accomplice, should it just be considered 
external (by fiat), essentially documenting that it's an exception to the 
guarantee? I don't suppose many other external effects make it easy to 
round-trip object references in a memory-safe way, so this might make it a 
bit special.

On the other hand, the design of the logging interface seems especially 
prone to abstraction leaks. Isn't logging often thought of as an 
implementation detail? I wouldn't expect to be able to listen to a module's 
logs unless I had power over its code inspector (or something like that).


[1] "The exact set of function bindings exported by `racket/kernel` is 
unspecified and subject to change across versions. 
"

[2] "Primitive modules with names that start with #% [like `#%kernel`] are 
defined, but they are not meant for direct use, and the set of such modules 
can change. "

[3] Admittedly, certain identifiers like `#%declare`, `#%provide`, 
`define-values` and `gensym` are documented to be part of the accepted 
grammar of cross-phase persistent modules, so I suppose it's strongly 
implied that at least some cross-phase persistent modules exist that export 
these bindings.


On Sunday, April 21, 2019 at 3:41:15 AM UTC-7, Alexis King wrote:
>
> Hello all, 
>
> I just published a blog post on defeating Racket’s separate compilation 
> guarantee. While I don’t imagine such a thing is actually a good idea, I 
> think the path to getting there is interesting anyway, and it touches lots 
> of different parts of the Racket system. For those who are interested, the 
> blog post is available here: 
>
> 
> https://lexi-lambda.github.io/blog/2019/04/21/defeating-racket-s-separate-compilation-guarantee/
>  
>
> Comments welcome, 
> Alexis 
>
>

-- 
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 module 'query' does not return insert-id

2019-04-23 Thread Ryan Culpepper

On 4/22/19 20:36, David Storrs wrote:

 > (require db)
 > (define db (postgresql-connect  ...args...))
 > (simple-result-info (query db "insert into collaborations (name) 
values ('foojalskdsfls')"))

'((insert-id . #f) (affected-rows . 1))

 From the docs on the 'simple-result' struct:

"Represents the result of a SQL statement that does not return a 
relation, such as an INSERT or DELETE statement.


The info field is an association list, but its contents vary based on 
database system and may change in future versions of this library (even 
new minor versions). The following keys are supported for multiple 
database systems:


#

'insert-id: If the value is a positive integer, the statement was an 
INSERT statement and the value is a system-specific identifier for the 
inserted row. For PostgreSQL, the value is the row’s OID, if the table 
has OIDs (for an alternative, see the INSERT ... RETURNING statement). 
For MySQL, the value is the same as the result of last_insert_id 
 
function—that is, the value of the row’s AUTO_INCREMENT field. If there 
is no such field, the value is #f. For SQLite, the value is the same as 
the result of the last_insert_rowid 
 
function—that is, the ROWID 
 of the inserted row."



I get the same results with a SQLite connection -- the insert-id is 
always #f.  I know that it says the contents may change and that it 
varies per database, but it also specifically calls out 'insert-id as a 
thing that is supported for both of these DBs.  What am I missing?


On PostgreSQL, my guess is that your table was created without the "WITH 
OIDS" clause. For example:


  > (define c (dsn-connect 'pg))
  > (query c "create table words (t text)")
  (simple-result '())
  > (query c "insert into words (t) values ('hello')")
  (simple-result '((insert-id . #f) (affected-rows . 1)))

and here's a example for a table with "WITH OIDS":

  > (query c "create table names (t text) with oids")
  (simple-result '())
  > (query c "insert into names (t) values ('Alice')")
  (simple-result '((insert-id . 105197) (affected-rows . 1)))

On SQLite, there is a bug in the db library that suppresses insert-id if 
it is the same as the last reported insert-id (for a different table, 
for example). I'll fix that. But you should see it otherwise. For example:


  > (define c (sqlite3-connect #:database 'memory))
  > (query c "create table words (t text)")
  (simple-result '((insert-id . #f) (affected-rows . 0)))
  > (query c "insert into words (t) values ('hello')")
  (simple-result '((insert-id . 1) (affected-rows . 1)))

Ryan

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