takeoutweight / clojure-scheme

Clojure to Scheme to C to the bare metal.
566 stars 21 forks source link

Syntax for hosted environment? #2

Closed myguidingstar-zz closed 11 years ago

myguidingstar-zz commented 11 years ago

Hi, I'm going to port clojure.string to clojure-scheme. I'm trying to learn from core.cljscm Can you please explain these

(defn make-array
  ([size] (scm* {:size size :void nil} (make-vector :size :void)))
  ([type size]
     (make-array size)))

I don't understand the use of keywords after scm*. I guest I understand this correctly:

(let [x "foo"] (scm* [x] (string-ref x 0)))

Also, what about:

(scm-boolean* [x] (char? x)))

does that mean "coerce to boolean before returning value"?

takeoutweight commented 11 years ago

The scm pass-through forms are macros defined in core_macros.clj

The (scm* {} ...) form takes a map of placeholders to Clojure forms. These Clojure form will be compiled to scheme and replace their corresponding placeholders in the scheme form, which will remain otherwise untouched. Basically, it functions a quasi-quote for the cljscm->scm compilation.

the scm-boolean* macro annotates the form with a :boolean tag, which allow the compiler to make some optimizations by skipping nil checks. It doesn't do any coercion.

By the way, I've just set up a mailing list which may be more convenient for discussion clojure-scheme: https://groups.google.com/forum/#!forum/clojure-scheme