This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns muster.core | |
| (:use clojure.set)) | |
| ;; Aufgabe 1 | |
| (defn calc' [a op b & rest] | |
| (if-not (seq rest) | |
| (op a b) | |
| (apply calc' (op a b) rest))) | |
| (defmacro calc [bindings & term] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| summe [] = 0 | |
| summe (x:xs) = x + summe xs | |
| prod [x] = x | |
| prod (x:xs) = x * prod xs | |
| factorial 0 = 1 | |
| factorial n = n * factorial (n-1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns repl.core) | |
| (def x -3) | |
| (comment | |
| ;; --- Wiederholung | |
| ;; ----------------------------------------------------------------------------------------------- | |
| ;; Performance tuning: type hints |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns repl.core) | |
| (defn new-thread [f] (.start (Thread. f))) | |
| (comment | |
| ;; --- Wiederholung | |
| ;; Vars & Concurrency |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns muster.core) | |
| (set! *print-length* 25) | |
| ;; Aufgabe 1 | |
| (def nat (iterate inc 0)) | |
| (def even-nat (filter even? nat)) | |
| (def primes (remove | |
| (fn [a] (some #(= 0 (mod a %)) (range 2 (/ 2 a)))) | |
| (iterate inc 2))) | |
| (def partial-sum (reductions + nat)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns repl.core | |
| (:refer-clojure :exclude [replace]) | |
| (:require [clojure.test :as t]) | |
| (:use [clojure.string :only (replace join)] | |
| [clojure.repl :rename {dir ls}] | |
| repl.greeter.friendly-hello) | |
| (:import (java.util Date Timer Random) | |
| java.io.File | |
| (javax.swing JFrame JPanel) )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns muster.core) | |
| ;; Aufgabe 1 | |
| (defn rev-interleave [col n] | |
| (apply map list (partition n col))) | |
| (defn myflatten [col] | |
| (mapcat #(if (coll? %) (myflatten %) [%]) col)) | |
| ;; Aufgabe 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns muster.core) | |
| ;Aufgabe 1 | |
| (defn flip [f] (fn [& args] (apply f (reverse args)))) | |
| (defn mycomp [& fs] | |
| (fn [& args] (reduce (fn [a f] (f a)) | |
| (apply identity args) | |
| (reverse fs)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns repl.core) | |
| (comment | |
| ;; atom | |
| (def foo (atom 2)) | |
| foo | |
| (deref foo) | |
| @foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns repl.core) | |
| (comment | |
| ;; Atoms | |
| (def foo (atom {})) | |
| foo | |
| (defn store [k v] (swap! foo assoc ,,,, k v)) |