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 forfold) | |
;;From racket example | |
;;https://docs.racket-lang.org/reference/for.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for%2Ffold%29%29 | |
;; (for/fold ([acc '()] | |
;; [seen (hash)] | |
;; #:result (reverse acc)) | |
;; ([x (in-list '(0 1 1 2 3 4 4 4))]) | |
;; (cond | |
;; [(hash-ref seen x #f) |
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
;;util function to help with bindings | |
(defun partition (n l) | |
(do ((remaining l (setf remaining (subseq remaining 2))) | |
(acc (list))) | |
((null remaining) (nreverse acc)) | |
(let ((nxt (subseq remaining 0 2))) | |
(if (= (length nxt) n) | |
(push nxt acc) | |
(setf remaining nil))))) | |
;;a dumb struct to wrap a list. solely for custom |
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 picking | |
(:require [clojure.pprint :as pprint])) | |
;original implementation from reddit. | |
(defn pick-best? [pred possible-positions] | |
(let [ps (mapv #(when (pred %) %) possible-positions)] | |
(or (second ps) | |
(first ps) | |
(nth ps 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 bubble | |
(:require [clojure.pprint :as pprint])) | |
;;1.summing up a list of numbers and storing the result | |
(def the-sum | |
(let [xs (range 10)] | |
(reduce + xs))) | |
;;2.iterating through a list looking for a specific value(s) |
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 getting-started.reactlike | |
(:require [fn-fx.fx-dom :as dom] | |
[fn-fx.diff :refer [component defui render should-update?]] | |
[fn-fx.controls :as ui])) | |
(def firebrick | |
(ui/color :red 0.69 :green 0.13 :blue 0.13)) | |
;; The main login window component, notice the authed? parameter, this defines a function | |
;; we can use to construct these ui components, named "login-form" |
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 other-examples.todo | |
(:require [fn-fx.fx-dom :as dom] | |
[fn-fx.diff :refer [component defui render should-update?]] | |
[fn-fx.controls :as ui])) | |
(def main-font (ui/font :family "Helvetica" :size 20)) | |
(defui TodoItem | |
(render [this {:keys [done? idx text]}] | |
(ui/border-pane |
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 other-examples.todo | |
(:require [fn-fx.fx-dom :as dom] | |
[fn-fx.diff :refer [component defui render should-update?]] | |
[fn-fx.controls :as ui])) | |
(def main-font (ui/font :family "Helvetica" :size 20)) | |
(defui TodoItem | |
(render [this {:keys [done? idx text]}] | |
(ui/border-pane |
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
//(decomp/decompile (let [bound 10] | |
// (loop [x 1 | |
// acc (java.util.ArrayList.)] | |
// (if (== bound x) | |
// acc | |
// (recur (unchecked-inc x) | |
// (if (odd? x) (doto ^java.util.ArrayList acc (.add (* x x))) | |
// acc)))))) | |
// Decompiling class: user$fn__13411 |
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 clojure-playground.core) | |
(def samples | |
{"0100110" "1 0 2 3 5 4 6" | |
"01001100111" "No solution" | |
"100001100101000" "0 1 2 3 4 6 5 7 8 11 10 9 12 13 14" | |
}) | |
(def easy "0100110") | |
(def hard "001011011101001001000") |
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 system-example | |
(:require [spork.async.system :as sys] | |
[clojure.core.async :as async :refer [chan]])) | |
(def ins (chan (async/dropping-buffer 1))) | |
(def outs (chan (async/dropping-buffer 1))) | |
(sys/go-push :clock ins (let [res (async/<! (async/timeout 1000))] | |
(System/currentTimeMillis))) |