How to use clojure.tools.macro/name-with-attributes in ClojureScript? - clojure

I would like to give a name to a macro and I can do it in Clojure with this method clojure.tools.macro/name-with-attributes.
What is the equivalent method in ClojureScript ?

Unfortunately you can only define macros in Clojure, not in ClojureScript. But once defined, you can use them in both.
As explained in this answer, macros are applied at compilation. And because the compiler is written in Clojure, macros must be implemented in Clojure as well.
Hope this helps.

Related

Calling Clojure from Java: Why is the "new" style (clojure.java.api.Clojure) better than the "old" one (gen-class)?

Something is puzzling me after reading the this great answer to a related question:
There are two possibilities to share a function that I wrote in Clojure with Java developers
The first one is providing it in a JAR file so that they can call it as if I had written it in Java. Sounds great for Clojure advocacy.
The second one, the purportedly better way, requires those Java developers to use things like clojure.lang.IFn or clojure.lang.RT and invoking functions by passing their names as strings (!) instead of just calling them.
Why is the second approach "the better one"?
You are sorta setting up a false dichotomy here. Every approach involves creating a jar file: that is just how JVM programs are distributed. But there are 3 different ways for Java code to invoke Clojure code contained in a jar:
Use methods in clojure.lang.RT to initialize the runtime, load files, and then look up vars. This is the old, deprecated approach.
Use methods in clojure.java.api.Clojure to look up functions and invoke them. This is the newer version of (1), and hides some of the messy stuff you could accidentally get wrong.
Use gen-class in the Clojure library to define a more Java-friendly interface to the Clojure functions.
You can still do (3) - there's nothing wrong with it exactly. But gen-class is a pretty clunky tool, and except for the simplest examples like exposing a number of static methods, it's just not a lot of fun, and it's not easy to provide an API that "feels" like a Java API using Clojure.
But you know what's great at providing an API that feels like Java? Java! So what I recommend if you want to make a Clojure library easy to use in Java is to include some Java code in your Clojure library. That Java code, written by you, bridges the language gap. It accesses your Clojure code by mechanism (2) above, and presents a Java-friendly facade so the outside world doesn't have to know there's Clojure underneath.
amalloy/thrift-gen is an example of a library I wrote years ago following this approach. It would not be at all easy to write this in pure Clojure, just because traditional Java idioms are very foreign to Clojure, and it doesn't support them all very well. By writing my own Java shim instead, Java clients get a very comfortable interface to work with, and I can just write Clojure that feels like Clojure instead of a bunch of gen-class nonsense.

Can ClojureScript special forms be aliased in a way that is accessible from a REPL?

This project provides an approach to allowing users to use other human language words to replace def defn etc:
https://github.com/echeran/clj-thamil
It uses macros to wrap special forms and macros. However in ClojureScript, macros can only be evaluated at compile time. When using a browser REPL such as http://clojurescript.io/ macros are unavailable.
Is my best option to modify the ClojureScript compiler and create sets of symbols that can be recognized as special forms? My intention is to provide a batteries included learning experience for kids using their own human language. http://timothypratley.github.io/power-turtle/ translating functions is easy, but macros and special forms seem like they require compiler support?

clojure built-in java method

are there any documentation on clojure built-in java method?
for example, .toUpperCase from java.lang.String and .indexOf from clojure.lang.PersistantVector.
Is there anyway I can find useful java method without looking at the source code?
As others have pointed out, you can get the java.* and javax.* documentation online pretty easily as it is part of core Java.
For the clojure.*, your best reference is the source. Even so, I'd recommend not relying on it since this code should really be considered an implementation detail of Clojure. You have no guarantee that the functionality won't change in future versions of Clojure and break any code that depends on it.
How about the Java API? All of Java's classes and methods are listed there. That covers all of the "clojure built-in java methods".
On the other hand, Clojure's classes are documented in here, Clojure's API. You have to learn to distinguish between Clojure's classes and Java's classes. All packages starting with java.* or javax.* belong to Java and are documented in the first link. The packages starting with clojure.* are from Clojure, you'll find their documentation in the second link.
If the package for the class starts with java or javax then you can look it up in the Java documentation on Oracle's website.
For Clojure implementation classes (where the package name starts with clojure) you are probably stuck with looking at the source code. There is documentation for the intended API (the Clojure language) but not for the Java classes implementing it. You may be able to find some articles (like this one) depending on if what you're looking for is something a blogger has taken an interest in.

The very first clojure compiler?

Clojure is written mainly in Clojure, but there had to be a "first" version of a clojure compiler that was written in something else, presumably Java.
Is the code of that compiler available anywhere?
My interest is purely academic, not productional, I'd like to see the way that Rich Hickey handled the chicken/egg problem.
The clojure compiler is written in java, not clojure. So the current version is the one that will satisfy your curiosity. Of course it's a reasonable point of view to say that macros are part of the compiler, and those are indeed written in clojure, but they are not relevant to the chicken/egg problem you mention, which is solved by having the compiler in Java.
Compiler bootstrapping is a common issue when you write your compiler in the same language as that which you are compiling.
In the case of Clojure, however, the compiler is written in Java, so no tricky games required.
For fun historcal reference, GHC, the Haskell compiler (written in Haskell), was originally compiled via Lazy ML.
Not sure if this relates to your interests, but Rich had originally worked on a language called DotLisp and for that he began with a study of JScheme, which he used as a basis for the original code and eventually replaced completely.
DotLisp is here: http://dotlisp.sourceforge.net/dotlisp.htm
JScheme is here: http://jscheme.sourceforge.net/jscheme/main.html
(Trivia: one of the authors of JScheme is Brandeis professor Tim Hickey, no known relation to Rich.)

Design and Implementation of ClojureScript

My question is NOT about how to use ClojureScript to produce JavaScript code.
I am interested in ClojureScript because it implements Clojure \ {eval} within Clojure, and is able to compile it to another language. Thus, I'm interested in the possibility of having ClojureScript target other platforms.
Question: besides the source code, is the Design & Implementation of ClojureScript documented anywhere? I'd like a high level overview of how the various parts of the compiler work together:
* how are the
As far as the documentation for "Clojurescript pipeline and how you can hook into it" is concerned you can check out this blog entry.