Lein run dose a different thing to lein repl then running (-main)


#1

Hi, I am a beginer at this.
Im writing a html template program.
It reads some data spesifying posts in the form of edn then creates an index.html file which links off to a html file for each post.
If I type
lein run
then onlly the index.html page is produced.
However if I type
lein repl
and then type
(-main)
then all the html pages are produced.

I thorght lein run just loads the project and runs the .core/-main function.
What am i missing hear?
Thanks


#2

Hard to say for sure without seeing your code but I suspect lazy sequences are at work here.

When you run (-main) in the REPL, whatever is returned – the last expression in the function – is going to be fully realized as the REPL prints the value.

When you run lein run, it will run (-main) but it doesn’t care what the function returns (except for setting a shell exit code) so it will not cause a lazy sequence to be realized.

If you are doing something for side-effects, you should either use run! or doseq, depending on how your code is structured. You don’t want to use map.