zoukankan      html  css  js  c++  java
  • clojure配置

    1、转换clojure工程为eclipse工程

    1. Install Counterclockwise plugin in Eclipse (from eclipse marketplace). This brings clojure and leiningen support to eclipse.

    2. Add lein2-eclipse plugin to your project.clj :

      :plugins [[lein2-eclipse "2.0.0"]]

    3. Run following command inside the project directory :

              需要先安装命令 brew install leiningen  

              然后执行命令    lein eclipse

    This generates necessary project files.

    具体是

    Created .classpath
    Created .project

    1. Import the project into eclipse ( File -> Import -> General -> Existing project ).

    2. Right click on the project in eclipse then "Configure > Convert to leiningen project

    2、clojure文件

    http://www.liaoxuefeng.com/article/0014171500694729a42a2c8b7f245e0bd54612c88d78a03000

    3 、clojure----宏语法

    首先说明引号  quoting的情况,quoting分为两种场景,在函数内或者在 macro内,作用影响在两个时期   宏扩展时期,编译时期

    例子,下面函数功能如果 expr为真返回nil,否则执行语句form

    3.1、问题1  quoting的作用域 问题,如果作用于单个关键字或者()

    (defmacro unless [expr form]

       ( list 'if expr nil form))

    by quoting (,you prevent clojure form directly evaluating ( at macro expansion time

    还有注意 quote的作用范围,上例作用于一个关键字if,只会影响这个关键字,如果作用于(,那么会影响整个()

    (defmacro unless-v2 [expr form]

       '(if expr nil form z))

    这个时候 ' 作用于整个() ,所以括号内你可以乱写东西,那些不是参数的东西你都可以写,比如上例中的z

    3.2、逃脱大范围作用域

    当' 作用于括号()的时候,这个作用范围比较大,所以这个时候有个需求,就是希望这个大范围内的一些局部不受引号的控制,这个时候解决办法就是   ` +  ~,

    ~就是那些不受影响的变量

    例如,原始的情况

     >>(defmacro chain-v1 [fun var]

        '(fun var))                           ----------------------所以这个时候也是看到' quoting如果作用范围太大也没什么实际效果了

    希望逃脱作用域

    >>(defmacro chain-v2 [fun var]

      `(~fun ~var 1))

    >>想看效果的话就是看宏扩展

    (macroexpand '(chain-v1 inc 5))

    得到的结果是

    (fun var)

    然后另一个执行

    (macroexpand '(chain-v2 inc 5))

    结果是

    (inc 5)

  • 相关阅读:
    LeetCode-167-两数之和 II
    LeetCode-160-相交链表
    LeetCode-155-最小栈
    [leetcode]7. Reverse Integer反转整数
    [leetcode]4. Median of Two Sorted Arrays俩有序数组的中位数
    [leetcode]2. Add Two Numbers两数相加
    [leetcode]210. Course Schedule II课程表II
    Topological Sorting拓扑排序
    [leetcode]62. Unique Paths 不同路径(求路径和)
    [leetcode]387. First Unique Character in a String第一个不重复字母
  • 原文地址:https://www.cnblogs.com/amazement/p/6597537.html
Copyright © 2011-2022 走看看