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

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
?

@mflatt Is the pict/code
library supposed to color everything as data in this case:
(code `’,(+ 1 2))

(code `',(+ 1 2))

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

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

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

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 has joined the channel

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

Welcome.

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

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

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

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

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

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

thats a really good idea

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

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

thank you

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

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

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 has joined the channel

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

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>

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

Thanks @notjack, @alexknauth told me about keyword-apply
and 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")))
`

The only problem above is the ordering of the keywords.

What’s the problem with the ordering?

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.

ahhh, I see what you mean

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

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

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.

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

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

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

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

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.

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