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
; vim: syntax=clojure | |
;Updated based on much feedback on proper smart contract logic construction with Gemini 2.0 Flash Experimental | |
(defn create-dutch-auction [] | |
(deploy | |
`(do | |
(import convex.asset :as asset) | |
(import asset.nft.tokens :as nft) | |
(def auctions {}) |
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
;; *clojure-version* | |
;; (require '[taoensso.encore :as encore]) | |
(let [v [1 2 3 4] | |
x 1 | |
y 2 | |
z 3] | |
(encore/qbench ; Returns fastest of 3 sets of lap times for each form, in msecs | |
1000000 ; Number of laps |
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
;; Using criterium to test performance of Tuples | |
;; | |
;; Benchmark using parts of the core.matrix implementation test suite | |
;; | |
;; =========================================================== | |
;; Common setup: | |
(use '[criterium.core :as c]) | |
(require 'clojure.core.matrix.compliance-tester) |
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
;; ======================================================================= | |
;; Motivation: we are interested in the performance of tiny | |
;; wrapper functions which look like: | |
;; (fn [_ x y] (g x y)) | |
;; | |
;; Question: are they getting the full performance benefits of inlining? | |
(ns test | |
(:require [criterium.core :as c])) |
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
(use '[clojure.core.match :only [match]]) | |
(defn evaluate [env [sym x y]] | |
(match [sym] | |
['Number] x | |
['Add] (+ (evaluate env x) (evaluate env y)) | |
['Multiply] (* (evaluate env x) (evaluate env y)) | |
['Variable] (env x))) | |
(def environment {"a" 3, "b" 4, "c" 5}) |
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
(sample-normal 5) | |
=> (-0.10224658005696823 -0.39374760130345093 -0.9347003327466611 0.027885002566669224 -0.5329681018922551) | |
(view (histogram (sample-normal 1000))) | |
(view (function-plot sin -10 10)) |
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Frequency analysis (implicitly treating a string as a sequence of chars) | |
(frequencies "abracadabra") | |
=> {\a 5, \b 2, \r 2, \c 1, \d 1} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Infinite, lazily calculated sequence of Fibonacci numbers |
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
;; enodyt's solution to Game of Life | |
;; https://4clojure.com/problem/94 | |
(fn [board] | |
(let [dx (count (first board)) | |
dy (count board) | |
neighbours (fn [pos board] | |
(let [xs [[-1 -1] [0 -1] [1 -1] | |
[-1 0] [1 0] | |
[-1 1] [0 1] [1 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
;; Objective | |
;; 1. Learn Clojure by doing Clojure | |
;; | |
;; Pre-requisites | |
;; You need to have a running Clojure REPL | |
;; see: http://clojure.org/getting_started | |
; Hello World in Clojure | |
(println "Hello World") |
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
;; event application with subsequent events | |
;; event :: state -> (state' [event]) | |
(defn update-with-events [state events] | |
(if-let [event (first events)] | |
(let [other-events (rest events) | |
[updated-state new-events] (event game)] | |
(recur updated-state (concat other-events new-events))) | |
state )) |
NewerOlder