cperivol
2021-11-29 15:46:21

Hello, I would like to make a parameter that must be explicitly initialized. My initial implementation was to (make-parameter 'must-initialize-storage-to-a-dict) but I would like it to throw a helpful error when accessed. Is that possible?


laurent.orseau
2021-11-29 15:51:25

Maybe you can add a guard to the parameter, and ensure it has a good value by setting it to its own value: (p (p)) #lang racket/base (define p (make-parameter #f (λ (x) (unless (number? x) (error "Not a number:" x)) x))) (p (p))



cperivol
2021-11-29 16:07:45

That looks pretty good, Thanks!


cperivol
2021-11-29 16:08:01

This works too for me, thank you!


soegaard2
2021-11-29 16:12:14

Just remember, at the guard doesn’t return a boolean - it returns the new element. So the example needs to be: (define p (make-parameter #f (λ (x) (unless (number? x) (error "Not a number:" x)) x))) I got bit by that bug last week :slightly_smiling_face:


laurent.orseau
2021-11-29 16:19:33

thanks, edited.


capfredf
2021-11-29 17:08:35

I’m trying to submit a package to the official catalog, but I am either getting a message that simply says “save failed” or getting back to a fresh submission page


capfredf
2021-11-29 17:17:34

NVM. I figured out. The name of the package in the form should not contain spaces