For some time, I found Common Lispโs pretty printer to be
intimidating, obscure, and complex, and, for as long as Iโve been
comfortable with the basics of FORMAT
I felt able to ignore it, as
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
(defun char-next (char) | |
"Return the next alphabetic character, per CL standard." | |
(assert (char-lessp char #\Z) | |
(char) "No further characters in the standard alphabet.") | |
(let* ((char-num (digit-char-p (char-upcase char) 36)) | |
(char-next (digit-char (1+ char-num) 36))) | |
(if (lower-case-p char) | |
(char-downcase char-next) | |
char-next))) |
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
(require 'json) | |
(require 'url) | |
(require 'url-http) | |
;;; http utilities | |
(defun http-utils-response-json (url) | |
"Retrieve url and parse json response." | |
(with-current-buffer (url-retrieve-synchronously url t) |
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
(defpackage #:handy-math | |
(:use #:cl) | |
(:export #:onep #:twop | |
#:one-over #:1/ #:halve #:/2 #:integer-factor-p #:factorer | |
#:two-fold #:2* #:multiplier | |
#:^ #:2^ #:^2 | |
#:v*) | |
(:documentation "Handy Math | |
Simple, often used arithmatic operations.")) |
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
# Stream of consciousness development. Copy/Paste into pry or irb. | |
require 'stringio' | |
def stream_print(stream, object) | |
stream << object.to_str if object.respond_to?(:to_str) | |
stream | |
end | |
io = StringIO.new |
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
Code.require_file "test_helper.exs", __DIR__ | |
defmodule DecompositionTest do | |
use ExUnit.Case, async: true | |
# "015D;0074;0302;;;" in Decomposition.txt | |
# "0073;0302;015D;" in Composition.txt | |
test "String.equivalent? (LATIN SMALL LETTER S WITH CIRCUMFLEX)" do | |
assert String.equivalent?("\u015D", "\u0073\u0302") # fails, but correct | |
assert String.equivalent?("\u015D", "\u0074\u0302") # passes, but incorrect |
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
;; Per https://twitter.com/wobher/status/726442806353399808 what I'm | |
;; trying to say, all too succinctly, is that structurally an | |
;; expression like "foo |> bar |> baz |> qux" or even | |
;; "foo.bar.baz.qux" is commonly considered syntax for a bunch of | |
;; nested calls: "qux(baz(bar(foo)))". However, in Lisp or any other | |
;; non-infix language, we can see that this need not be the case. | |
;; Lets define a `pipe' function; we'd like the following assertions | |
;; about it to be true: |
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
CL-USER> | |
(defun ๐ช๐ณ (ingredients) | |
(case ingredients | |
(๐พ '๐) | |
(๐ฝ '๐ฟ) | |
(๐ '๐) | |
(๐ '๐) | |
(t '๐ฒ))) | |
(defun ๐ข๐ฑ (thing) |
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
# Exercise for implementing multi-dimesional arrays in Ruby | |
# TODO: | |
# Level 0: Implement `row_major_index` and `to_a`. | |
# Level 1: How could tests be improved? | |
# Level 2: How could the interface of ArrayN be extended? Made more idiomatic? | |
# Multi-dimensional array | |
class ArrayN |