pocmatos
2022-2-8 14:30:50

@pocmatos has joined the channel


pocmatos
2022-2-8 14:31:22

Was taking a look at the inner workings of Pycket and initial attempts to load a racket file return exn:fail : "can't find primitive make-ephemeron-hasheq"


pocmatos
2022-2-8 14:31:41

does this mean there’s some new primitive used in the racket expander that hasn’t been added to pycket yet?


samth
2022-2-8 14:33:11

probably not in the expander (pycket has a specific version committed), but in the dependencies of racket/base


samth
2022-2-8 14:33:20

you might try running a file written in '#%kernel


pocmatos
2022-2-8 15:01:22

well, i did make expander regexp fasl, which created a couple of files.


samth
2022-2-8 15:01:37

ah that might also have caused the problem


pocmatos
2022-2-8 15:01:52

and I can see the use of that primitive in expander.rktl


samth
2022-2-8 15:01:54

it should be pretty easy to add make-ephemeron-hasheq; I’ll take a look


pocmatos
2022-2-8 15:04:05

could you point me to where pycket is actually expanding a program into a linklet? I was expecting pycket to be interpreting expander.rktl on the source program to expand it, but expander.rktl exports an expand function which afaiu will not create a linklet but a fully expanded program. How/where does it go from here to a linklet?


pocmatos
2022-2-8 15:06:57

pocmatos
2022-2-8 15:07:32

Apparently this commented line has been there for like half a decade. I am curious if there’s a specific reason for it to persist there - i.e. not removing it.


pocmatos
2022-2-8 15:07:50

And this does mean that we are somehow not expanding the original code (maybe instead doing something else)?


samth
2022-2-8 15:10:41

First, that commented line is in a little mini-repl that is only for experiments.


samth
2022-2-8 15:11:38

Second, the expander goes all the way to linklets. The API that the expander relies on is the linklet API described here: https://docs.racket-lang.org/reference/linklets.html


pocmatos
2022-2-8 15:14:13

ah, that explains why the line hasn’t been removed.


pocmatos
2022-2-8 15:14:48

Also, regarding the expander, does that mean that the expand function exported by the linklet is different than the racket expand (which doesn’t generate a linklet) ?


samth
2022-2-8 15:15:56

The expand function exported by the linklet in expander.rktl is the same as the one from racket/base, but that isn’t used by the runtime.


samth
2022-2-8 15:16:21

I think the big thing you’re missing is that the calls go the other way.


pocmatos
2022-2-8 15:18:02

is processing what you said…


samth
2022-2-8 15:18:18

If you do racket -l racket/base, then the runtime (in the racket_entry function) calls the namespace-require function exported by the expander with an appropriate s-expression, and then it’s done.


pocmatos
2022-2-8 15:18:45

ah - now i got it.. and the expander linklet calls the runtime!!!


pocmatos
2022-2-8 15:18:52

that’s why you said it goes the other way.


samth
2022-2-8 15:18:53

The expander then calls functions like compile-linklet which are provided by the runtime


samth
2022-2-8 15:20:06

But compile-linklet does very little — it just turns an s-expression into an AST.


samth
2022-2-8 15:20:35

The expander then calls instantiate-linklet, which runs the evaluation, which is what the runtime knows how to do.


pocmatos
2022-2-8 15:21:40

OK. yes. I know what you mean. And that AST is dependent on what the runtime created at the compile-linklet call and independent of the expander linklet.


samth
2022-2-8 15:21:56

Yes, exactly.


pocmatos
2022-2-8 15:22:24

suddenly - and maybe as a delayed realization - this seems very similar to the interface we have in JS to compile and instantiate wasm modules.


pocmatos
2022-2-8 15:23:35

:bulb:


pocmatos
2022-2-8 15:24:06

Thanks for explaining this. I honestly have been gathering partial pieces of knowledge about this for years and I think I only just pieced this together. :face_palm:


samth
2022-2-8 15:27:59

Yes, although I don’t think the callbacks to JS exist (because WASM doesn’t have macros)


pocmatos
2022-2-8 15:36:13

Yes, that’s correct. You can call from Wasm to JS through wasm module imports but that’s different.