Fork me on GitHub
#clojure-dev
<
2018-01-30
>
andy.fingerhut00:01:34

Closer to the source, I guess clojure.core/load and clojure.lang.RT/getResource are closer to it for Clojure/Java, and that is perhaps completely defined by the classloader being used.

seancorfield00:01:21

@andy.fingerhut When I watched that talk, I took it to mean that you can choose to organize your code any way you want but what's important is what the REPL sees, essentially -- i.e., the forms that are presented to it in a specific order. All the file structure and name mapping is just convention.

andy.fingerhut00:01:50

I agree that you can get all your code loaded via a REPL without touching the file system for Clojure source files, if you define all the namespaces in the correct order as he mentions.

andy.fingerhut00:01:53

Maybe I am misinterpreting what he said, but I took it to mean that the mapping of say namespace foo.bar to a file named foo/bar.clj (in an appropriate directory) was unnecessary convention.

seancorfield00:01:55

Insofar as dealing with the REPL, yeah, it is unnecessary -- you open the file in your editor, you evaluate it into the REPL. The REPL doesn't care where that code is on the filesystem.

seancorfield00:01:59

If you're working like that, you don't need to follow any conventions for files / folders if you always evaluate forms into the REPL in the bottom-up order because you'd never cause the REPL to try to load namespaces that aren't already in memory.

seancorfield00:01:37

I mean, almost no one is really going to try that... since all sorts of tooling is going to get horribly confused if you don't "follow convention"... and you'd have to make sure you loaded all the code in the right order every time so it would be painful... but, as he said, you could just stick everything in one file and just load that into the REPL.

andy.fingerhut00:01:33

It just seems to me that part of the tooling that will get horribly confused, and/or fail, will be Clojure itself, even in the absence of lein/boot/etc.

andy.fingerhut00:01:52

OK, yeah, in the context of his preceding sentences, it makes sense if the meaning is: "You can get by without a file system for source code in Clojure, if you really want to. It is optional." As soon as you do want to use files for Clojure source code, that is when namespace to file name mappings rear their head.

noisesmith00:01:15

eh, there's load-file

noisesmith00:01:35

but that only works when you are pushing code to clojure, not when clojure goes out looking for it via require and friends

noisesmith00:01:08

and when @seancorfield mentions the editor sending code, that's likely either load-file or load-string

seancorfield00:01:22

Well, whatever mechanism your editor uses to send a form to the REPL to be evaluated...

andy.fingerhut00:01:09

I stand corrected :

andy.fingerhut00:01:29

Too much switching between Skype and Slack

seancorfield00:01:22

Well, whatever mechanism your editor uses to send a form to the REPL to be evaluated...

seancorfield01:01:44

(I'm not actually sure what ProtoREPL uses but with CIDER it would be some nREPL chatter back and forth -- the point was mostly that you can "send code" without the REPL needing to look at the file system)

seancorfield01:01:25

Changing the subject... I was pleasantly surprised to discover that I can start a REPL in a Contrib project using clj and -Sdeps to specify the library as a local dependency

clj -Sdeps '{:paths ["src/main/clojure"] :deps {org.clojure/java.jdbc {:local/root "."}}}'

seancorfield01:01:46

It reads the pom.xml file for dependencies. Very nice!

cfleming02:01:21

@noisesmith Right, if your code isn’t organised according to the package structure, even load-file and load-string will only work if either they contain no requires, or those namespaces have already been required (and I don’t see how the second could have happened if the code isn’t organised as expected).

cfleming02:01:28

So sure, technically it’s true that you don’t have to arrange your code according to convention, but you’re going to be extremely limited - either you reimplement something like require yourself, or you only use single scripts and maintain the dependencies between them in your head.