
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
)

where are your tag helpers defined?

pollen.rkt

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

Then require pollen.rkt
in build.rkt
.

ah

and then set them in build.rkt?

yes

niiice tyvm!

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

So in pollen.rkt do something like:

make a set-state! function

(define foo 42) (set! foo 42)

awesome ty

tryin it

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

What did you do?

gonna push my code, one min

so here I am setting the value: https://gitlab.com/JoelMcCracken/joelmccracken.com/blob/master/src/build.rkt#L58

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

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

And what was the error?

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:

./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

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

I’m pretty sure that’s what happened.

ahhhhhh

So how can we get the expected behaviour?

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

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

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

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

yeah

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

The docs of render
mentions the use of eval
.

hmm

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

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

so i was having trouble locating data.rktd

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

but maybe i can do it with an environment variable

oh so i just like hard-code it?

config.rkt

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

That won’t work

It’s the same issue

pollen.rkt
will see fresh globals.rkt

So whatever you mutate to globals.rkt
will be lost

Environment variable definitely works, but it feels too hacky

yeah i just tried the env var and it worked

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

trying that ^^

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

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…

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

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

Yeah

I wonder why it does use every

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

Oh ty

I’ll just do that then

If someday I figure out something better then great

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

gotcha, ty!

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

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


:thumbsup:

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->value

@ben what are you using cyclic values for?

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)) ;=> should be 5
? If not, I will create one.

a regression test

@sorawee do define-custom-hash-types
and define-custom-set-types
do what you want? https://docs.racket-lang.org/reference/dicts.html#(form._((lib._racket%2Fdict..rkt)._define-custom-hash-types)) https://docs.racket-lang.org/reference/sets.html#(form._((lib._racket%2Fset..rkt)._define-custom-set-types))

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

ah, gotcha