This file contains 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
(setf *random-state* (make-random-state t)) | |
(defun dice () | |
(random 2)) | |
(defun roll (n) | |
(let ((x 0) | |
(count 0)) | |
(loop while (< x n) do | |
(incf count) |
This file contains 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
(defconstant +words-filename+ "words.txt") | |
(defun date-to-ms (year month day) | |
(* (encode-universal-time 0 0 0 day month year) 1000)) | |
(defvar *base-date* (date-to-ms 2021 6 19)) | |
(defvar *day-in-ms* 86400000) | |
(defun parse-words-input (pathname) | |
(uiop:read-file-lines pathname)) |
This file contains 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
(def hundred-times (partial * 100)) | |
;; => #'hundred-times | |
(hundred-times 5) | |
;; => 500 | |
(def times (partial *)) | |
;; => #'times | |
(times 1) |
This file contains 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
(def sum-str (comp str +)) | |
;; => #'sum-str | |
(sum-str 8 8 8) | |
;; => "24" | |
(filter (comp not zero?) [0 1 0 2 0 3 0 4]) | |
;; => (1 2 3 4) | |
(def countif (comp count filter)) |
This file contains 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 hello-world.core | |
(:require [goog.dom :as dom] | |
[goog.date :refer [getNumberOfDaysInMonth]] | |
[goog.events :refer [listen]]) | |
(:import [goog.events EventType] | |
goog.Promise)) | |
(def element (dom/getElement "body")) | |
(js/console.log (getNumberOfDaysInMonth 2018 9)) |
This file contains 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
alert("ClojureScript") | |
console.log("Hello") | |
el.innerHtml | |
el["innertHtml"] | |
el.innerHtml = "ClojureScript" | |
el["innerHtml"] = "ClojureScript" |
This file contains 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
;; Invoking methods | |
(js/alert "ClojureScript") | |
(.log js/console "Hello") | |
;; Accessing properties | |
(.-innerHtml el) | |
(aget el "innerHtml") | |
;; Modifying properties | |
(set! (.-innerHtml el) "ClojureScript") |
This file contains 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
(let [c (chan)] | |
(go (dotimes [x 3] | |
(>! c x) | |
(println "Put: " x))) | |
(go (dotimes [x 3] | |
(println "Take: " (<! c))))) | |
;; => Put: 0 | |
;; => Take: 0 | |
;; => Put: 1 |
This file contains 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
(def ch (chan)) ;; ==> Create channel | |
(take! ch #(println "Got a value:" %)) | |
;; => Take value from channel, Asynchronously | |
(put! ch 42) ;; => Asynchronously put value from channel |
This file contains 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
(def numbers (iterate inc 1)) | |
;; => #'numbers | |
(defn square [x] (* x x)) | |
;; => #'square | |
(def squared (map square numbers)) | |
;; => #'squared | |
(take 5 squared) |
NewerOlder