2018年9月30日日曜日

【Javascript】数値の配列を昇順にソートする。

数値の配列を昇順にソートする。

numbers.sort((a, b) => a - b)

もしくは

numbers.sort(function (a, b) {
    return a - b;
  });

2018年9月17日月曜日

【RaspberryPi3】ラズパイでClojure実行環境を作る。【Clojure】

はじめに

Clojureの勉強をしたかったが、ラズパイで行いたかった。ただ、簡単にインストールする方法がなかなか見つからなかった。インストールできたので、その方法をまとめた。

インストールに必要なもの

  • Java (openjdk version "1.8.0_181")
  • maven (Apache Maven 3.3.9)
  • ant (Apache Ant(TM) version 1.9.9 compiled on March 1 2017)

インストール手順

  1. sudo apt-get install default-jre
  2. sudo apt-get install maven
  3. sudo apt-get install ant
  4. git clone https://github.com/clojure/clojure.git
  5. cd clojure
  6. ./antsetup.sh
  7. ant local

実行してみる

$ clojure
Downloading: org/clojure/clojure/1.9.0/clojure-1.9.0.pom from https://repo1.maven.org/maven2/
Downloading: org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.pom from https://repo1.maven.org/maven2/
Downloading: org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.pom from https://repo1.maven.org/maven2/
Downloading: org/clojure/clojure/1.9.0/clojure-1.9.0.jar from https://repo1.maven.org/maven2/
Downloading: org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.jar from https://repo1.maven.org/maven2/
Downloading: org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.jar from https://repo1.maven.org/maven2/
Clojure 1.9.0
user=>

サンプルソースを実行してみる

sample01.clj

(def hello (fn [] (println "Hello world") ))
(hello)
$ clojure sample01.clj
Hello world