接口Clojure和Clojurescript [英] Interfacing Clojure and Clojurescript

查看:77
本文介绍了接口Clojure和Clojurescript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使现有的Clojure库可用于clojurescript,并创建可在Clojure和Clojurescript中运行的新应用程序。

I would like to make my existing Clojure libraries usable from clojurescript as well as create new applications which run in both Clojure and Clojurescript.

我了解Clojure和Clojurescript具有它们之间的差异,以及诸如cljx之类的元编程解决方案。但是,我将Clojure代码限制为Clojurescript的兼容子集,而我只是想从clojurescript中调用clojure(反之亦然)。我已经在诸如core.match之类的库中看到了这种可能,但是我无法复制在那里所做的事情。

I understand Clojure and Clojurescript have their differences, and that there are metaprogramming solutions such as cljx. But, I have limited my Clojure code to a compatible subset of Clojurescript and I would simply like to call clojure from clojurescript (and possibly vice-versa). I have seen this possible in libraries such as core.match, but I am unable to replicate what is done there.

我目前得到的是否这样的命名空间,我不确定是否是因为不可能,或者是我的命名空间或目录结构错误,还是其他原因。

I am currently getting No such namespace, I am not sure if it is because it is not possible, or because my namespacing or directory structure is wrong, or some other reason.

为了具体起见,我具有以下形式的目录结构

For concreteness, I have a directory structure of the form

src/
  clj/
    clopjys/
      vector.clj
  cljs/
    cljdemo.cljs

我正在尝试从cljdemo.cljs中使用vector.clj,即:

I am trying to use vector.clj from within cljdemo.cljs, i.e:

(:require
  [clophys.vector :refer [coords std-uniform-vector]])

我的project.clj具有以下内容条目

My project.clj has the following entries

  ...
  :source-paths ["src/clj"]
  :cljsbuild {
      :builds [{
          ; The path to the top-level ClojureScript source directory:
          :source-paths ["src/cljs"]
   ...


推荐答案

由于已编写此问题,因此 Clojure读者条件语言已出现在核心语言中(而 .cljx 是一个库)。

Since this question has been written, Clojure reader conditionals have appeared in the core language (whereas .cljx is a library).

这篇关于接口Clojure和Clojurescript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆