Skip to content

Instantly share code, notes, and snippets.

View sritchie's full-sized avatar
🎯
Focusing

Sam Ritchie sritchie

🎯
Focusing
View GitHub Profile
(clojure.core/fn
[[y47090 y47091 y47092 y47093 y47094]
[p47095 p47096 p47097 p47098 p47099]]
(clojure.core/let
[G0000000000000020
(Math/pow y47094 2.0)
G0000000000000022
(Math/cos y47091)
G0000000000000024
(Math/pow p47097 2.0)
------ ERROR -------------------------------------------------------------------
File: /Users/sritchie/code/clj/programming-2022/src/demo/viewers.cljs:12:16
--------------------------------------------------------------------------------
9 | @sv/!sci-ctx
10 | {:namespaces {'demo.face
11 |
12 | (sci/copy-ns demo.face (sci/create-ns 'demo.face))}})
----------------------^---------------------------------------------------------
Encountered error when macroexpanding sci.core/copy-ns.
NullPointerException: Cannot invoke "clojure.lang.IFn.invoke(Object)" because the return value of "clojure.lang.Var.getRawRoot()" is null
WARNING: update-vals already refers to: #'clojure.core/update-vals in namespace: clojure.tools.analyzer.utils, being replaced by: #'clojure.tools.analyzer.utils/update-vals
WARNING: update-keys already refers to: #'clojure.core/update-keys in namespace: clojure.tools.analyzer.utils, being replaced by: #'clojure.tools.analyzer.utils/update-keys
WARNING: update-vals already refers to: #'clojure.core/update-vals in namespace: clojure.tools.analyzer, being replaced by: #'clojure.tools.analyzer.utils/update-vals
WARNING: update-keys already refers to: #'clojure.core/update-keys in namespace: clojure.tools.analyzer, being replaced by: #'clojure.tools.analyzer.utils/update-keys
WARNING: update-vals already refers to: #'clojure.core/update-vals in namespace: clojure.tools.analyzer.passes, being replaced by: #'clojure.tools.analyzer.utils/update-vals
WARNING: update-vals already refers to: #'clojure.core/update-vals in namespace: clojure.tools.analyzer.passes.uniquify, being replaced by: #'clojure.tools.analyzer.utils
error in process sentinel: Could not start nREPL server: Retrieving io/github/nextjournal/clerk/0.5.346/clerk-0.5.346.pom from clojars
Retrieving lambdaisland/uri/1.10.79/uri-1.10.79.pom from clojars
Retrieving org/apache/maven/resolver/maven-resolver-api/1.4.1/maven-resolver-api-1.4.1.pom from central
Retrieving org/apache/maven/resolver/maven-resolver/1.4.1/maven-resolver-1.4.1.pom from central
Retrieving org/apache/maven/resolver/maven-resolver-spi/1.4.1/maven-resolver-spi-1.4.1.pom from central
Retrieving org/apache/maven/resolver/maven-resolver-util/1.4.1/maven-resolver-util-1.4.1.pom from central
Retrieving org/apache/maven/resolver/maven-resolver-impl/1.4.1/maven-resolver-impl-1.4.1.pom from central
Retrieving org/slf4j/slf4j-api/1.7.29/slf4j-api-1.7.29.pom from central
Retrieving org/slf4j/slf4j-parent/1.7.29/slf4j-parent-1.7.29.pom from central
Retrieving io/github/nextjournal/clerk/0.5.346/clerk-0.5.346.jar from clojars
;; # Custom Viewers with d3-require
^{:nextjournal.clerk/visibility #{:hide-ns}}
(ns mathbox-d3-require
(:require [nextjournal.clerk :as clerk]))
;; This is a custom viewer for a cube rendered
;; with [Mathbox](https://gitgud.io/unconed/mathbox). Note that Mathbox isn't
;; bundled with Clerk but we use a component based
;; on [d3-require](https://github.com/d3/d3-require) to load it at runtime.
;;; ob-mit-scheme.el --- Babel Functions for Scheme -*- lexical-binding: t; -*-
;;;
;;; Modification by Sam Ritchie to get this working with mit-scheme and the
;;; scmutils library.
;;; Requirements:
(require 'ob)
(require 'ob-scheme)
(require 'xscheme)

I did a bunch of work months ago on the polynomial and rational function namespaces; now they can both participate in all of the generic functions, including derivatives and all arithmetic.

I realized today that I could use an ACTUAL polynomial instance in that wacky "find-path" example from pages 22-23 of SICM. Everything is way faster and makes more sense, since find-path returns an actual polynomial.

This function generates a polynomial by passing the (identity) polynomial into the Lagrange interpolation code:

;; Polynomial interpolation in Clojure, written as a fold.
;;
;; This allows you to generate an estimate of the value of some polynomial at x,
;; where you have a sequence of points that the polynomial has to pass through.
;;
;; See [this namespace](https://github.com/sicmutils/sicmutils/blob/main/src/sicmutils/polynomial/interpolate.cljc#L20)
;; for a much longer build-up to these simple functions!
(defn prepare [[x fx]]
[x x fx fx])
@sritchie
sritchie / macro.clj
Last active January 5, 2022 07:52
Macro for generating kahan-babushka-klein folds.
;; general impl of https://en.wikipedia.org/wiki/Kahan_summation_algorithm#Further_enhancements
(defn- klein-term [acc delta]
`[sum# (+ ~acc ~delta)
~delta (if (>= (Math/abs ~(with-meta acc {:tag 'double}))
(Math/abs ~(with-meta delta {:tag 'double})))
(+ (- ~acc sum#) ~delta)
(+ (- ~delta sum#) ~acc))
~acc sum#])
@sritchie
sritchie / notes.clj
Last active December 22, 2021 23:13
(ns tutorial.petageconvert)
;; woohoo, some comments!
;;
;; A note about `pet-multiplier`... for your keys, symbols are great, but
;; Clojure provides an additional idea of keywords over Scheme. Keywords like
;; `:dog` evaluate to themselves, so you don't have to quote them. Symbols are fine, but you have one less thing to remember (the quote).
(def pet-multipler
{'dog 7 'cat 5 'fish 10})