
@samth I don’t understand. How do I provide a submodule?

And how do I define the submodule to be s-exp
?

I think it has something to do with make-meta-reader

but the documentation gives me headaches

or maybe syntax/module-reader

I tried this: ;; virtual-mpu/mpu.rkt
#lang racket/base
(provide (all-from-out "mpu-lang/lang.rkt")) ;; the expander
(require "mpu-lang/lang.rkt")
(module reader racket/base ;; the reader
(provide read-syntax))
;; some file using my language
#lang virtual-mpu/mpu
(blabla ...)
But I get: default-load-handler: expected a 'module' declaration found: something else

Oh my god I got it working!!

;; virtual-mpu/mpu.rkt
#lang racket/base
(module reader syntax/module-reader virtual-mpu/mpu-lang/lang)

I took inspiration from the code of s-exp: (module reader syntax/module-reader #:language (lambda (p) (read-syntax (object-name p) p)))

if you already have a reader the syntax becomes: #lang racket/base
(module reader reprovide "asm-lang/reader.rkt")

Sorry for spamming the channel, but I think I had to express my issue textually to understand it :slightly_smiling_face: As always, thanks to the Racket community for all your kind answers and pointers. :racket-flat: :heart:

@bcclaro_slack has joined the channel

I made a gist to remember how modules and #lang are handled in Racket: https://gist.github.com/euhmeuh/2f771a5702464741e21388bfcff8b68c

I still don’t understand why readers need to be in submodules. What is the purpose of the main module then?

@jerome.martin.dev the main module defines what the bindings in the language are

yes, but the reader generates a brand new module (from read-syntax) that requires its own expander

so in the end, the bindings are defined by the reference in read-syntax

The bindings are defined by the module that appears in the language position in the (module ...)
form

oh right I get it. This is just an issue with my special case of trying to separate a lang into public/private modules that makes the whole thing redundant

if I add stuff to the public lang module, they’ll be defined as bindings on top of what read-syntax defines by default

but usually I don’t want any so my modules will be just empty with only a reader submod

@jerome.martin.dev really, read-syntax
doesn’t define the bindings

not directly

but it decides what the module lang will be

yes

that’s what I meant

I think I get it now. The whole design makes sense. It’s just difficult to grasp without tutoring, I guess.

There’s not a lot of documentation about how to design public/private separation in Racket. You need to understand the ins and outs of how modules work before being able to design an architecture for your project.

Now that I get it, I’ll try to find some time to write such tutorial, that could be helpful.

Beautiful Racket helped me a lot, but when you get out of the road into your own project, it becomes wild.

I’m not sure what you mean by “public/private separation”, but the usual ways are either “don’t provide the private things from the module” or “put the private modules in a subdirectory named private/
”

yes, but when you start putting modules supposed to be used as #lang
into private/
folders, it becomes hard to provide them correctly.

do you want general clients of your library to use those #lang
s?

or are they just for internal use

usually they start as internal langs, then become public by the time the project grows

I guess I’m still confused about what’s hard

my case is special because the langs couldn’t directly be extracted as a single package out of the project. They had internal dependencies but I still wanted to provide a public interface for them

if you have some language foo/private/my-special-lang
and you want to make it public as foo/special-lang
then you can just create foo/special-lang.rkt
with the following content:

#lang racket/base
(require foo/private/my-special-lang)
(provide (all-from-out foo/private/my-special-lang))
(module reader syntax/module-reader foo/special-lang)

Yes, took me two days to discover exactly that :slightly_smiling_face:

or even: #lang racket/base
(module reader syntax/module-reader foo/private/my-special-lang)

that’s what I did

I was jumping from joy when it finally worked

hmm… is there any reason why define-custom-hash-types
is a dict?
and not hash?

@samth reading the syntax/module-reader
documentation without knowing if it would be useful or not, and without knowing how to use it, was not a brease

yeah, probably that needs another example of the simplest case

I was still not sure until now that you confirm it, that it was the way to go

I just tried it out of despair

like “s-exp seems to work that way, let’s try something stupid and just copy/paste that”

is there a way to make custom hash that would be a hash?
like make-hashtable
in r6rs: https://docs.racket-lang.org/r6rs/r6rs-lib-std/r6rs-lib-Z-H-14.html?q=make-hashtable#node_idx_1182

@jerome.martin.dev any suggestions for how to improve http://docs.racket-lang.org/guide/hash-languages.html would be welcome

Yes, I’ll do some PR on those pages :smile:

I just realised dict
is more generic so it should be no issue - changing all hash-xxx to dict-xxx in my code then

So…I just have to say…lol: https://gist.github.com/LeifAndersen/692f3d27095bd9b78052cf76fc4537f7


(Because yes, I just realized that I did this…)

@hunter.t.joz has joined the channel

@greg I regularly end up in a situation where I hit <Tab> in Racket mode and I get a spinning beachball in emacs

I assume that this is something going wrong, and I should be able to fix it

@samth C-h k and hit <TAB> — does it say <TAB> is bound to indent-for-tab-command
? If so, C-h v and enter tab-always-indent
— what’s the value? complete
, t
, or something else?

@greg it says racket-indent-or-complete

That’s not defined in racket mode. Hmm.

;;; racket-common.el
;; Copyright (c) 2013-2015 by Greg Hendershott.
;; Portions Copyright (C) 1985-1986, 1999-2013 Free Software Foundation, Inc.
;; Author: Greg Hendershott
;; URL: <https://github.com/greghendershott/racket-mode>

:slightly_smiling_face:

maybe i just have a really old racket mode?

I’m on phone with flakey connection now, and no internet for laptop.

I think yes maybe try latest racket mode.

How do I upgrade?

If you installed from melpa use the list-packages UI.

i think i figured it out

now bound to indent-for-tab-command

Newer racket mode gives you better beach balls