eav db
eav db

Reputation: 595

Writing a "cheating" Quine in Clojurescript

Suppose we wanted to write a cheating quine in clojure, we could do:

(ns cheating-quine)
... stuff here doesn't really matter ...
(println (slurp *file*))

Now, this does not work in Lein Figwheel because the value of file ends up being something like /tmp/form-init########.clj, and contains bootstrapping code of some sort.

Question: how can we get this "cheating" quine to work in clojurescript?

Note: the goal is NOT to write a quine. The goal is to write a cljs program which has access to the file it's defined in. This whole "cheating quine" thing is trying to explain the problem better then my previous failed attempt of

Clojure + Clojurescript: Macro to read code of current file

Upvotes: 0

Views: 212

Answers (1)

Timothy Pratley
Timothy Pratley

Reputation: 10662

A cheating solution is to distribute the source code (e.g. put it in resources and serve it as a file) and compile a bootstrap to load and execute code, and get it to pull down your file, and in the file load the same file... that way it can do a HTTP request for the code that is currently running, and execute it. This is essentially how ClojureScript browser REPLs such as http://clojurescript.io/ work... They compile and execute incoming code on the fly. clojuresript.io is a good working example of ClojureScript bootstrapping if you are interested in it, but a word of caution, there is quite a lot going on so expect to invest quite some time :)

Upvotes: 1

Related Questions