joelmccracken
2019-5-25 20:24:26

Is there a way to define global variables? I am working with Pollen. I have written a script (build.rkt) which I need to have some state which can be accessed via my tag helpers (e.g. those in pollen.rkt)


soegaard2
2019-5-25 20:25:33

where are your tag helpers defined?


joelmccracken
2019-5-25 20:25:43

pollen.rkt


soegaard2
2019-5-25 20:26:29

Define them in pollen.rkt and in pollen.rkt provide them.


soegaard2
2019-5-25 20:26:38

Then require pollen.rkt in build.rkt.


joelmccracken
2019-5-25 20:28:00

ah


joelmccracken
2019-5-25 20:28:20

and then set them in build.rkt?


soegaard2
2019-5-25 20:28:31

yes


joelmccracken
2019-5-25 20:28:42

niiice tyvm!


soegaard2
2019-5-25 20:29:11

But note that unless you set them to something in pollen.rkt, they are provided as unsettable variables.


soegaard2
2019-5-25 20:29:31

So in pollen.rkt do something like:


joelmccracken
2019-5-25 20:29:43

make a set-state! function


soegaard2
2019-5-25 20:29:50

(define foo 42) (set! foo 42)


joelmccracken
2019-5-25 20:30:22

awesome ty


joelmccracken
2019-5-25 20:30:24

tryin it


joelmccracken
2019-5-25 20:37:46

maybe i’m misunderstanding but it doesnt seem to be working


sorawee
2019-5-25 20:37:56

What did you do?


joelmccracken
2019-5-25 20:38:25

gonna push my code, one min


joelmccracken
2019-5-25 20:40:37

joelmccracken
2019-5-25 20:41:02

here is that function which I am using from build.rkt: https://gitlab.com/JoelMcCracken/joelmccracken.com/blob/master/src/pollen.rkt#L10


joelmccracken
2019-5-25 20:41:31

and here is where I am trying to retireve the value that i want to set from build: https://gitlab.com/JoelMcCracken/joelmccracken.com/blob/master/src/pollen.rkt#L43


soegaard2
2019-5-25 20:42:19

And what was the error?


joelmccracken
2019-5-25 20:43:56

well there isn’t an error exactly, just when I am tryign to access the root-dir at that point it is the original value “YES”, Here is the output:


joelmccracken
2019-5-25 20:43:59
 ./build.rkt
testing: Hi THIERE
compiling else about.html.pmd
done compiling else about.html.pmd
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
AM HERE
YES
compiling post entries/fp-jargon.html.pm
done compiling post entries/fp-jargon.html.pm
compiling post entries/haskell-fud.html.pm
done compiling post entries/haskell-fud.html.pm
compiling else index.html.pp
done compiling else index.html.pp
Complete

joelmccracken
2019-5-25 20:44:34

hmm i wonder if render-to-file could be forking a new process or something…?


sorawee
2019-5-25 20:45:15

I’m pretty sure that’s what happened.


joelmccracken
2019-5-25 20:45:30

ahhhhhh


soegaard2
2019-5-25 20:49:32

So how can we get the expected behaviour?


joelmccracken
2019-5-25 20:50:45

i just ran getpid in both places, and they have the same pid


joelmccracken
2019-5-25 20:51:38

its not an issue because I am requiring like (require "pollen.rkt") is it?


sorawee
2019-5-25 20:51:49

Yeah, that’s definitely what happened. Try (displayln "hello") at the top level of pollen.rkt. You will see something like

compiling post entries/fp-jargon.html.pm
hello
done compiling post entries/fp-jargon.html.pm
hello
compiling post entries/haskell-fud.html.pm
hello
done compiling post entries/haskell-fud.html.pm
hello

sorawee
2019-5-25 20:52:24

If they are really shared, there should be only one hello


joelmccracken
2019-5-25 20:52:27

yeah


joelmccracken
2019-5-25 20:52:44

well its not a fork, or i dont thin it is, because a fork would have another pid right?


soegaard2
2019-5-25 20:52:46

The docs of render mentions the use of eval.


joelmccracken
2019-5-25 20:52:55

hmm


joelmccracken
2019-5-25 20:53:15

well so i had been going down the path of storing the data in a data.rktd file


joelmccracken
2019-5-25 20:53:30

but I then was running into problems where the current-dir is different in different places


joelmccracken
2019-5-25 20:53:43

so i was having trouble locating data.rktd


soegaard2
2019-5-25 20:53:50

What if made a new file globals.rkt and put root-dir in that.


joelmccracken
2019-5-25 20:53:51

but maybe i can do it with an environment variable


joelmccracken
2019-5-25 20:54:04

oh so i just like hard-code it?


joelmccracken
2019-5-25 20:54:19

config.rkt


soegaard2
2019-5-25 20:54:19

Then both pollen.rkt and build.rkt can use that.


sorawee
2019-5-25 20:54:24

That won’t work


sorawee
2019-5-25 20:54:36

It’s the same issue


sorawee
2019-5-25 20:54:57

pollen.rkt will see fresh globals.rkt


sorawee
2019-5-25 20:55:10

So whatever you mutate to globals.rkt will be lost


sorawee
2019-5-25 20:56:54

Environment variable definitely works, but it feels too hacky


joelmccracken
2019-5-25 20:57:16

yeah i just tried the env var and it worked


soegaard2
2019-5-25 20:57:33

What if in pollen.rkt a (dynamic-require "globals.rkt") is used?


joelmccracken
2019-5-25 20:58:49

trying that ^^


joelmccracken
2019-5-25 21:01:27

well tryign the dynamic require thing seems to have froze the program, lol


sorawee
2019-5-25 21:05:49

Straightforward dynamic-require is problematic. Pollen works by evaluating each .pm file from its own folder, so if you use dynamic-require in pollen.rkt, only .pm files at the topmost level will work. For those in subdirectories, it won’t find globals.rkt.

But I also don’t see why that would help…


joelmccracken
2019-5-25 21:07:14

Is there no other facitlity for process-level shared state?


soegaard2
2019-5-25 21:10:11

Well, the problem is the use of eval (I think).


sorawee
2019-5-25 21:11:01

Yeah


joelmccracken
2019-5-25 21:11:48

I wonder why it does use every


sorawee
2019-5-25 21:12:03

OK, so I took a look at my own Pollen project that I abandoned several months ago. I have a similar build script, and yes, I use envvars to workaround this very same problem.

https://github.com/sorawee/my-website/blob/master/run.rkt#L43


joelmccracken
2019-5-25 21:15:06

Oh ty


joelmccracken
2019-5-25 21:15:17

I’ll just do that then


joelmccracken
2019-5-25 21:15:35

If someday I figure out something better then great


greg
2019-5-25 21:19:46

@joelmccracken In general, your program can have global variables in the way that @soegaard2 explained. Put them in some file like config.rkt or globals.rkt or whatever, provide them from that file. Then require that file elsewhere your program. That all works fine when it’s your program. But when it’s Pollen’s program, and it’s eval-ing your .pm files one by one, this doesn’t work.


joelmccracken
2019-5-25 21:51:43

gotcha, ty!


joelmccracken
2019-5-25 22:04:08

Just checked out your website btw and got a bad cert error in firefox (assuming this is it: https://sorawee.com/)


joelmccracken
2019-5-25 22:05:27
Websites prove their identity via certificates. Firefox Developer Edition does not trust this site because it uses a certificate that is not valid for <http://sorawee.com\|sorawee.com>. The certificate is only valid for the following names: *.<http://github.com\|github.com>, <http://github.com\|github.com>, *.<http://github.io\|github.io>, <http://github.io\|github.io>

Error code: SSL_ERROR_BAD_CERT_DOMAIN
View Certificate

sorawee
2019-5-25 22:20:00

joelmccracken
2019-5-25 22:20:51

:thumbsup:


ben
2019-5-25 23:49:25

What’s the shortest way to make a cyclic value in Typed Racket? Right now I have a file with #0=(0 . #0#) and am calling file-&gt;value


notjack
2019-5-26 01:11:03

@ben what are you using cyclic values for?


sorawee
2019-5-26 04:02:24

What’s the way to customize equality for hash/set, etc.?

One possible way that definitely works is to create a wrapper struct with gen:equal+hash, but it involves a lot of boilerplate code. Is there any library that automate this process and let me do something like:

(define h (custom-make-hash #:key car))
(custom-hash-set! h (cons 1 2) 3)
(custom-hash-set! h (cons 2 3) 4)
(custom-hash-set! h (cons 1 3) 5)
(custom-hash-ref h (cons 1 10)) ;=&gt; should be 5

? If not, I will create one.


ben
2019-5-26 04:15:31

a regression test



sorawee
2019-5-26 04:16:47

Yeah, that seems to be what I’m looking for. Thanks!


notjack
2019-5-26 04:55:18

ah, gotcha