Brief introductionUsing Clojure to encapsulate the use of Graphviz, the main implementation of UML is currently drawingUseTake the UML of command mode as an example to demonstrate the use of CdrawInstalling GraphvizCdraw is a simple package for Graphviz, please first install the GraphvizAdd dependency
Create a new Clojure project using Leiningen UML
Add the following dependencies in the PROJECT
Code Path:Https://github.com/bluesilence/Lisp/blob/master/clojure/projects/room-escape/src/room_escape/script.cljExtract Stories to TXTIn order to move the stories from. Clj into. txt, I leveraged Clojure ' s eval function. The steps is as follows:1. Read the contents from the story ' s txt as string;2. Eval each key-value pair of each hostel;3. Sort the rooms by name.This works, but isn't good enough. Beca
Clojure
(Ns r2.test2(: Gen-class: Methods [# ^ {: static true} [getMessage [String]))
(Defn-getMessage [name](Println (str ("hello" name "! "))))
JAVA end
Import com. ociweb. clj. Demo; // class created by compiling Clojure source file
Public class Main {
Public static void main (String [] args ){String message = Demo. getMessage ("Mark ");System. out. println (message );}}
It seems that you can only use it
The core role of microBecause the micro receive parameters can be very complex, and do not evaluate, so you can receive list, in the internal conversion, after processing execution, you can also receive a completely non-Lisp syntax, internally converted to Clojure can execute the list.This allows you to create your own DSL and implement the Clojure macro as a DSL parser.The difference between micro and func
Clojure provides several powerful data structures (collections)I. Types of collections1. VectorEquivalent to an array such as: [2 3 5], ["Ad" "Adas" "Adadsads"]2. ListEquivalent to a linked list, such as: ' (2 3 5), ' ("Ad" "Adas" "Adadsads")Compared to vectors, [] becomes (), and because () the symbol is used for function calls, in order to differentiate, it needs to be preceded by a single quotation mark '3. MapSyntax format such as: {: a 1:b 1}Map
Clojure provides an operation form other than functions and macros. Special form is a limited number and is not implemented by clojure itself.
It mainly includes the following:
Catch, def, do, dot ('.'), finally, FN, if, let, loop,
Monitor-enter, monitor-exit, new, quote, recur, set !, Throw, try, and var.
Complete documentation see: http://clojure.org/special_forms
Vars should be explained here. First,
Label: style Io color OS ar Java for SP
The following content appears in the document on the official website of clojure. This article just summarizes common questions.
1. namespace, Lib, and code file conventions. See the following code:
(nscom.my-company.clojure.examples.my-utils(:importjava.util.Date)(:use[clojure.contrib.def:only(defvar-)])(:require[clojure.contrib.shell-out:asshell]))
Lib is represented as a Java resource. If you have wr
Of course, a complete web app needs to write logs. Here I use slf4j + logback.
First, add two dependencies to the project. CLJ file in the my-website directory: Tools. Logging logback-classic
(defproject my-website "0.1.0-SNAPSHOT" :description "FIXME: write this!" :dependencies [[org.clojure/clojure "1.4.0"] [com.novemberain/monger "1.4.1"] [org.clojure/tools.logging "0.2.4"]
"user=> (time (dorun (pmap inc (range 1 1000))))"Elapsed time: 182.349073 msecs"
Futures and promises
Futures and promises are two slightly more low-level threading constructs, too red by the similar features available in the Java 6 concurrency API. they are simple to understand, simple to use, and provide a very direct way to spawn threads using native clojure syntax.Futures
A clojure future represents a
Clojure-jack-in startup Error
The error message is as follows:
Connecting to swank on port 65280 .. [2 times] Error in process filter: Open-Network-stream: Make client process failed: Connection refused,: Name,Slime lisp,: buffer, nil,: Host, localhost,: Service, 65280,: Nowait, Nil Error in process filter: Make client process failed: Connection refused,: name, slime lisp,: buffer,Nil,: Host, localhost,: Service, 65280,: Nowait, Nil
The sol
Now let's take a look atCode:
The first one is nil, which has the same null value as Java. Like false, nil can express the condition that the condition is not true. The following is an explanation:
Nilnil is a possible value of any data type in clojure. nil has the same value as Java null. the clojure conditional System is based around nil and false, with nil and false representing the values of logi
clojure-basic syntax-function definitionJuly 21:12 PM1. Create function 1.fn anonymous functionExamples are as follows:"hello")#413e8>"hello"))"hello""hello") ; 带参数"hello"user=>The short function can use # (),% to indicate the unique parameter;% 1,%2. Represents the 1th, 2 、.. A parameter;% represents all parameters, as follows:user=> (#(/ % 3) 4)4/3user=> (#(/ % 3) 4);结果为4/34/3user=> (#(/ %2 %1) 3 4);结果为4/34/3user=> (#(apply / %) 3 5 7);结果为3/5/73/35u
Ext.: http://www.linuxidc.com/Linux/2012-10/71557.htmFirst of all, I really have to say that there are many tutorials on the internet like JDK7 installed under Ubuntu. However, most are based on the JDK6 bin file. If you go to the Oracle website now and see it, you will find that it has become a. tar.gz compressed file.In addition this article also incidentally gave clojure download link, filename What of please according to your actual situation chan
Code Path:Https://github.com/bluesilence/Lisp/blob/master/clojure/projects/room-escape/src/room_escape/script.cljExtract Stories to TXTIn order to move the stories from. Clj into. txt, I leveraged Clojure ' s eval function. The steps is as follows:1. Read the contents from the story ' s txt as string;2. Eval each key-value pair of each hostel;3. Sort the rooms by name.This works, but isn't good enough. Beca
) Turn off monitoring(Stop Listner)(. Close listener)* * Synchronous Message Queuing with queue implementation(1) Defining Message Queuing(Def sync-q (m/queue "Sync-q")(2) Customizing message answering methods(Def Respinder (M/respond Sync-q Inc)(3) Send a message@ (m/request sync-q 1)Note: The request will wait until the message is answered before it returns, otherwise it remains blocked.* * Implementing asynchronous messages with topic(1) Definition topic(Def t (m/topic "test-topic"))(2) post
Common Methods for clojure map data structure:
Map sorting
(Println (sorted-map-by> 1 "a", 2 "B", 3 "c"); {3 c, 2 B, 1 };; take one equal value (let [results {: A 1: B 2: C 2: D 5: E 1: F 1}] (println (into (sorted-map-by (fn [key1 key2] (compare (get results key2) (get results key1 )))) results); {: D 5,: C 2,: A 1}; all unequal values (let [results {: A 1: B 2: F 4: E 3: D 6: C 5}] (println (into (sorted-map-by (fn [key1 key2] (compare (get result
This article by larrylgq prepared, reproduced please note the Source: http://blog.csdn.net/larrylgq/article/details/7395261
Author: Lu guiqiang
Email: larry.lv.word@gmail.com
Lisp uses special operators to extend the syntax, but the number of special operators in lisp is fixed. To solve this problem, LISP introduces macros, which do not directly do things, but generate actual services.Code.
Evaluate a macro: If the received S-expression is a parameter, a lisp expansion (ecpansion)
Using existing plug-ins, it is convenient to add the gzip function to clojure.1. Add the dependency on BK/ring-gzip plug-in project. CLJ.: Dependencies [BK/ring-gzip "0.1.1"]2. Add references to the handle file.(: Use your ring.middleware.gzip])3. Add wrap-gzip to the app.(DEF app(-> (Routes app-routes)(Handler/site)(Wrap-base-URL)(Wrap-gzip ))The final compression effect is also obvious.Before compression:After compression: The compression ratio is
4Clojure: 4Clojure Longest ascending sub-sequence algorithmThe description is as follows:
Given a vector of integers, find the longest consecutive sub-sequence of increasing numbers. If the sub-sequences has the same length, use the one of that occurs first. An increasing sub-sequence must has a length of 2 or greater to qualify.
Cases:[1 0 1 2 3 0 4 5] The longest ascending subsequence sequence is [0 1 2 3][5 6 1 3 2 7] The longest ascending subsequence sequence is [5 6] (DEFN t
Common macro infix macro to parse a person's arithmetic writing format and execute(Defmacro infix "Use this macro if you pine for the notation of your childhood" [infixed] (list (second INFI Xed) (first infixed) (last infixed)))So use:(infix (1 + 1)); = 2Check the returned list with MacroexpandIn the above example, the process of removing the last symbol, and then evaluating the remaining list, is actually passed.(+ 1 2), 3 (+ 1 2)To know the list before the final evaluation result comes out,
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.