deactivateduser60718
2020-1-21 16:54:54

Can you define a collection name to act as an alias for another?


deactivateduser60718
2020-1-21 16:55:25

context: I install package foo that provides a collection of the same name. I want to write (require bar) to mean (require foo). Can I define bar as a collection that resolves to foo?


leif
2020-1-21 20:20:16

@mflatt Is the pict/code library supposed to color everything as data in this case:

(code `’,(+ 1 2))


leif
2020-1-21 20:20:22

(code `',(+ 1 2))


leif
2020-1-21 20:21:01

Which seams kind of odd since the DrRacket color lexer doesn’t do that, and: (code `,(+ 1 2)) works fine.


leif
2020-1-21 20:22:27

Oh, and codeblock-pict works fine: (codeblock-pict "`',(+ 1 2)")


mflatt
2020-1-21 20:41:38

No, there’s no way to do that. (Well, you can play games with the module name resolver, but then you will have more problems.)


mflatt
2020-1-21 20:46:00

I would agree that the handling of ' in pict/code is not so great. When I run into problems like that, I end up writing something like (code’#,(code ,(+ 1 2)))`.


shawsumma060
2020-1-21 23:30:26

@shawsumma060 has joined the channel


shawsumma060
2020-1-21 23:36:13

hello all, i am new to slack. having a good ol’ time in racket


soegaard2
2020-1-21 23:47:01

Welcome.


shawsumma060
2020-1-21 23:48:20

so im making a #lang lua and its going to be a slow one


shawsumma060
2020-1-21 23:48:56

i havent figured out goto, continuations are just too slow (i think)


shawsumma060
2020-1-21 23:50:40

another think i could not find is how to make the repl work with my lang


soegaard2
2020-1-21 23:58:51

Depending on how your compiler works “goto” can be tricky. Since Racket is tail-recursive the most natural translation of “goto label” which transfers control to the place named by label, is to use the translation (label) i.e. see “goto” as a call to a thunk (function of no arguments). Some compilers decompose the program in basic blocks. Each basic block can then be compiled to a thunk. https://en.wikipedia.org/wiki/Basic_block


soegaard2
2020-1-21 23:59:13

The second part, getting the repl to work, sounds doable.


shawsumma060
2020-1-21 23:59:51

i’ve used llvm’s basic blocks before and never thought to use them here


shawsumma060
2020-1-21 23:59:56

thats a really good idea


shawsumma060
2020-1-22 00:00:56

i actually know exactly how to make my compiler use basic blocks, it is only 250 lines after all. the sytnax generator that is


soegaard2
2020-1-22 00:02:44

In order to get the REPL to work, you need to look at #%top-interaction . I don’t know the details, but the docs has a little to say: https://docs.racket-lang.org/reference/eval.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._read-eval-print-loop%29%29


shawsumma060
2020-1-22 00:03:02

thank you


soegaard2
2020-1-22 00:04:13

There is a work-through on a Repl for Basic in Beautiful Racket: https://beautifulracket.com/basic-3/the-repl.html


notjack
2020-1-22 01:01:15

Do you want (require bar/something) to also mean (require foo/something) automatically?


notjack
2020-1-22 01:02:17

As in, do you want the entire bar collection and all of the modules in it to be under foo, or just the single bar module?


hj5855586
2020-1-22 01:47:30

@hj5855586 has joined the channel


hj5855586
2020-1-22 01:50:39

hey guys and ladies — how do you generate the front-end of a web-app(eg website) with racket? and how do you connect the server side with the front-end? thank you


gknauth
2020-1-22 02:38:08

I’m stuck. Ideas welcome. (define a (list "m" "z" "c")) (define b (list 1 2 3)) (require rebellion/collection/record) (define (f keys vals) what-goes-here?) (f a b) -> #<record #:m 1 #:z 2 #:c 3>


notjack
2020-1-22 02:42:34

@gknauth Short term solution: use keyword-apply after munging the lists into the right shape. Long term: open a feature request in Rebellion, there’s no good reason not to have better built-in support for that.


gknauth
2020-1-22 02:58:46

Thanks @notjack, @alexknauth told me about keyword-applyand sent me this code:(define (keyword-apply/sort f kws kw-args pos-args) (let* ([kw-lop (map cons kws kw-args)] [sorted-kw-lop (sort kw-lop keyword<? #:key car)] [sorted-kws (map car sorted-kw-lop)] [sorted-kw-args (map cdr sorted-kw-lop)]) (keyword-apply f sorted-kws sorted-kw-args pos-args))) (module+ test (require rackunit) (define (f #:a a #:b b #:c c d e f) (list a b c d e f)) (check-equal? (keyword-apply/sort f '(#:b #:c #:a) '("b" "c" "a") '("d" "e" "f")) (list "a" "b" "c" "d" "e" "f")))`


gknauth
2020-1-22 02:59:43

The only problem above is the ordering of the keywords.


notjack
2020-1-22 03:01:47

What’s the problem with the ordering?


gknauth
2020-1-22 03:06:09

I’m using db to read from a database, let’s say the columns are "M" "Z" "C" and the first row of data is #(1 2 3). I’m trying to build a #<record #:m 1 #:z 2 #:c 3> without changing the ordering of M Z C. If someone wrote SQL that starts SELECT WARNING_AREA_ID, GEOCODE_TYPE, GEOCODE_NAME, BASE_WARNING_CODE I’m trying to honor the ordering of column names the SQL author chose.


notjack
2020-1-22 03:06:38

ahhh, I see what you mean


notjack
2020-1-22 03:07:30

Records are unordered so (record #:a 1 #:b 2) and (record #:b 2 #:a 1) are indistinguishable


notjack
2020-1-22 03:08:20

do you know the columns ahead of time? or are you writing something that needs to work for arbitrary columns known only at runtime?


gknauth
2020-1-22 03:08:21

I can live with the unordering in the record. The trick I think is to make sure the 1 2 3 don’t end up with the wrong keywords.


gknauth
2020-1-22 03:08:35

I do know the column names ahead of time, yes.


notjack
2020-1-22 03:09:00

Oh okay. I think the solution Alex gave makes sure not to get the arguments mixed up with the wrong keywords.


gknauth
2020-1-22 03:09:08

I also want to write something that is generic, that will accept any list of column names and make the right kind of record.


gknauth
2020-1-22 03:09:41

OK, I’ll give Alex’s code an honest try then.


notjack
2020-1-22 03:09:55

You might be interested in using define-record-type from rebellion/type/record. It’s like struct where the names of the fields are fixed at compile time, but it generates a keyword-based constructor.


gknauth
2020-1-22 03:10:24

Ok, thanks, I’ll look at that too.


notjack
2020-1-22 03:17:30