yilin.wei10
2021-1-15 20:50:06

I’m attempting to use https://docs.racket-lang.org/sql/index.html?q=with#%28part._sql-syntax%29 to do some SQL. For the life of me, I can’t work out how to do select x union ...


yilin.wei10
2021-1-15 20:50:42

I’m attempting to do a recursive query (similar to https://sqlite.org/lang_with.html).


yilin.wei10
2021-1-15 20:51:08

The issue I get is the with form and most other forms expect a select/update/... at the top level.


yilin.wei10
2021-1-15 20:52:49

The grammar says that union /should/ work as a table expr, but even with something like (sql (select a #:from (union (select (values 1)) (select x #:from cnt) #:all)))


soegaard2
2021-1-15 20:53:04

Haven’t tried sql for a while, but according to the grammar, you need something like (union ...).


yilin.wei10
2021-1-15 20:53:07

I get "SELECT a FROM (SELECT (VALUES (1)) UNION SELECT x FROM cnt)" which removes the ALL


yilin.wei10
2021-1-15 20:53:23

Yeah but it doesn’t accept it in the top level.


soegaard2
2021-1-15 20:53:36

Ah.


yilin.wei10
2021-1-15 20:54:10

So (sql (union ...)) isn’t accepted in the grammar.


artemchernyak
2021-1-15 20:55:50

I don’t believe so. It maps pretty close to how you would write sql, and you wouldn’t have a bare union in sql, right?


yilin.wei10
2021-1-15 21:00:40

I thought it would translate it to SELECT * FROM X UNION ...


soegaard2
2021-1-15 21:01:58

If an example would help, then I bet Ryan has some tests in the sql repo on Github.


yilin.wei10
2021-1-15 21:19:36

There’s a few - but they don’t cover it. I think I’ll read through the code in more depth.


pihentagy
2021-1-15 21:46:39

Given this stepper–3–3 function, how can I assign the two values prouced by stepper–3–3 to variables?


sorawee
2021-1-15 21:47:54

(match-define (cons a b) (stepper-3-3 4 7))


sorawee
2021-1-15 21:48:41

or:

(define result-pair (stepper-3-3 4 7)) (define a (car result-pair)) (define b (cdr result-pair)) if you don’t want to use match-define for any reason


yilin.wei10
2021-1-15 21:54:11

OK the ALL thing looks like a bug. I’m no closer to understanding the original question though. I’ve opened a github issue and a PR to fix the bug.


jestarray
2021-1-15 22:30:02

minimal racket doesn’t include the drracket ide right ?


notjack
2021-1-15 22:33:15

right!


jestarray
2021-1-15 22:40:58

the cs binary is hugee. i feel bad for making my users download racket for modding and stuff lol…


laurent.orseau
2021-1-15 23:03:11

Everyone should have Racket installed by default!


jestarray
2021-1-15 23:06:36

#lang racket/base (println "hello world") raco demod hello_world.rkt linkl-exports: contract violation expected: linkl? given: #<linklet> in: the 1st argument of (-> linkl? (listof symbol?)) contract from: <pkgs>/zo-lib/compiler/zo-structs.rkt blaming: <pkgs>/compiler-lib/compiler/demodularizer/name.rkt (assuming the contract is correct) at: <pkgs>/zo-lib/compiler/zo-structs.rkt:61.21 context...: C:\Program Files\Racket\collects\racket\contract\private\blame.rkt:347:0: raise-blame-error C:\Program Files\Racket\collects\racket\contract\private\arrow-val-first.rkt:486:18 C:\Program Files\Racket\share\pkgs\compiler-lib\compiler\demodularizer\name.rkt:9:0: select-names C:\Program Files\Racket\share\pkgs\compiler-lib\compiler\demodularizer\main.rkt:22:0: demodularize body of "C:\Program Files\Racket\share\pkgs\compiler-lib\compiler\demodularizer\batch.rkt" C:\Program Files\Racket\collects\raco\raco.rkt:41:0 body of "C:\Program Files\Racket\collects\raco\main.rkt" playing around with reducing size of some utility binaries and demod is not working on racket cs(latest snapshot), or am I using demod wrong?


badkins
2021-1-15 23:08:31

I’m coding a chess engine in Racket, so speed is of the utmost importance. Would you expect a function like the one below to be inlined, or should I use a macro? (define (is-king? piece) (= (bitwise-and piece piece-type-bits) king-bits))




badkins
2021-1-15 23:11:51

oohhh


badkins
2021-1-15 23:13:05

Thanks :) I started coding this in Julia, but as nice as Julia is for super mathy stuff, as the code grew more and more complicated, I grew more and more dissatisfied :) I’m not sure if Racket will be fast enough for the engine to beat me, but it’ll be fun trying.


sorawee
2021-1-15 23:15:34

No, I think this is a bug, but @mflatt can confirm.


mflatt
2021-1-15 23:16:37

I forgot about raco demod. It can’t work in its present form for CS, because it is based on reading and rewriting bytecode.


badkins
2021-1-15 23:16:39

In the specific case above, it does appear that it was inlined. At least there is no difference in speed between define and define-inline


jestarray
2021-1-15 23:20:58

ahh, so its going to be deprecated for the meantime?


mflatt
2021-1-15 23:29:21

I think it will have to be declared BC-only, at least.


mflatt
2021-1-15 23:31:21

Longer term, I can imagine making it work in combination with compilation to machine-independent mode (as used by the distribution build process), and then recompiling demodularized form to machine code.


badkins
2021-1-15 23:45:19

Are unsafe vectors still boxed in Racket? I’m wondering if I should just use bytes since my data will fit in a byte.


notjack
2021-1-15 23:50:50

Each element of a vector, unsafe or otherwise, is pointer-sized


notjack
2021-1-15 23:52:03

a vector of bytes will get rid of the indirection because a byte is just a fixnum and fixnums are immediate, but each element will still be pointer-sized so you’ll use something like 8x the space that a byte string would use


badkins
2021-1-16 00:06:18

@notjack space isn’t a concern for this particular task. If I’m understanding you correctly, if I use (unsafe-vector-set! vec pos #xff) then the element at position pos will be a pointer sized version of #xff - is that right? i.e. immediate ?


badkins
2021-1-16 00:06:53

oh, sorry, re-read your response, yes that does seem to be the case


badkins
2021-1-16 00:07:18

I guess it comes down to the UI for byte strings vs. vectors since the space isn’t a factor.


badkins
2021-1-16 00:08:52

For this to be performant, I need to minimize allocations, so there will only be one board state (or maybe one per core later), not one per node in the tree.