jerome.martin.dev
2018-6-22 09:03:01

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


jerome.martin.dev
2018-6-22 09:13:51

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


jerome.martin.dev
2018-6-22 09:20:04

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


jerome.martin.dev
2018-6-22 09:20:17

but the documentation gives me headaches


jerome.martin.dev
2018-6-22 09:24:26

or maybe syntax/module-reader


jerome.martin.dev
2018-6-22 09:47:35

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


jerome.martin.dev
2018-6-22 10:04:55

Oh my god I got it working!!


jerome.martin.dev
2018-6-22 10:05:04
;; virtual-mpu/mpu.rkt
#lang racket/base
(module reader syntax/module-reader virtual-mpu/mpu-lang/lang)

jerome.martin.dev
2018-6-22 10:07:26

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


jerome.martin.dev
2018-6-22 10:42:46

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


jerome.martin.dev
2018-6-22 11:51:41

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
2018-6-22 13:22:50

@bcclaro_slack has joined the channel


jerome.martin.dev
2018-6-22 14:35:09

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


jerome.martin.dev
2018-6-22 14:35:43

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


samth
2018-6-22 14:36:26

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


jerome.martin.dev
2018-6-22 14:37:25

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


jerome.martin.dev
2018-6-22 14:38:10

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


samth
2018-6-22 14:39:25

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


jerome.martin.dev
2018-6-22 14:40:31

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


jerome.martin.dev
2018-6-22 14:41:39

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


jerome.martin.dev
2018-6-22 14:42:08

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


samth
2018-6-22 14:42:18

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


jerome.martin.dev
2018-6-22 14:42:32

not directly


jerome.martin.dev
2018-6-22 14:42:43

but it decides what the module lang will be


samth
2018-6-22 14:42:47

yes


jerome.martin.dev
2018-6-22 14:42:53

that’s what I meant


jerome.martin.dev
2018-6-22 14:44:13

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


jerome.martin.dev
2018-6-22 14:46:00

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.


jerome.martin.dev
2018-6-22 14:47:03

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


jerome.martin.dev
2018-6-22 14:47:53

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


samth
2018-6-22 14:48:25

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/


jerome.martin.dev
2018-6-22 14:49:19

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


samth
2018-6-22 14:50:05

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


samth
2018-6-22 14:50:14

or are they just for internal use


jerome.martin.dev
2018-6-22 14:50:55

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


samth
2018-6-22 14:51:55

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


jerome.martin.dev
2018-6-22 14:51:57

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


samth
2018-6-22 14:52:40

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:


samth
2018-6-22 14:53:39
#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)

jerome.martin.dev
2018-6-22 14:53:52

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


samth
2018-6-22 14:54:18

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


jerome.martin.dev
2018-6-22 14:54:39

that’s what I did


jerome.martin.dev
2018-6-22 14:55:13

I was jumping from joy when it finally worked


githree
2018-6-22 14:55:41

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


jerome.martin.dev
2018-6-22 14:56:46

@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


samth
2018-6-22 14:57:02

yeah, probably that needs another example of the simplest case


jerome.martin.dev
2018-6-22 14:57:50

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


jerome.martin.dev
2018-6-22 14:58:16

I just tried it out of despair


jerome.martin.dev
2018-6-22 14:58:54

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


githree
2018-6-22 15:01:25

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


samth
2018-6-22 15:02:07

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


jerome.martin.dev
2018-6-22 15:03:30

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


githree
2018-6-22 15:11:51

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


leif
2018-6-22 20:01:52

leif
2018-6-22 20:01:53

leif
2018-6-22 20:02:08

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


hunter.t.joz
2018-6-22 20:37:34

@hunter.t.joz has joined the channel


samth
2018-6-22 20:45:37

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


samth
2018-6-22 20:45:57

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


greg
2018-6-22 21:10:56

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


samth
2018-6-22 21:12:52

@greg it says racket-indent-or-complete


greg
2018-6-22 21:15:34

That’s not defined in racket mode. Hmm.


samth
2018-6-22 21:16:03
;;; 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>

samth
2018-6-22 21:16:06

:slightly_smiling_face:


samth
2018-6-22 21:16:20

maybe i just have a really old racket mode?


greg
2018-6-22 21:16:45

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


greg
2018-6-22 21:17:18

I think yes maybe try latest racket mode.


samth
2018-6-22 21:17:39

How do I upgrade?


greg
2018-6-22 21:19:22

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


samth
2018-6-22 21:19:44

i think i figured it out


samth
2018-6-22 21:20:26

now bound to indent-for-tab-command


greg
2018-6-22 21:20:59

Newer racket mode gives you better beach balls