Skip to content

Instantly share code, notes, and snippets.

View edw's full-sized avatar

Edwin Watkeys edw

View GitHub Profile
@edw
edw / sample.md
Last active December 11, 2018 13:23
Sketch of how Scheme might be adapted to enhanced, Clojure-style reader

Sketch of how Scheme might be adapted to enhanced, Clojure-style reader

Multiple procedure arities

;; Clojure
(defn add
  ([] 0)
  ([x] x)
 ([x y] (+ x y))
@edw
edw / rest-args.scm
Created December 1, 2018 22:02
Poking Scheme implementations' rest-arg handling bits
(define (evil . args)
(set-cdr! args '())
args)
(let ((xs '(0 1 2 3)))
(display (apply evil xs))
(newline)
(display xs)
(newline))
@edw
edw / straw-poll.md
Last active November 29, 2018 15:55
Orange straw poll notes

Orange straw poll notes

Edwin Watkeys
2018-11-28

Tallys and Histograms

I wrote a tally in Clojure for my profiling library. I'm interested helping out with this.

Integer sets

@edw
edw / brace-expansion.scm
Last active November 27, 2018 15:58
Brace expansion
;; UNIX-style Brace Expansion
;; (A solution to <http://www.rosettacode.org/wiki/Brace_expansion>.)
;;
;; Edwin Watkeys, Thunk NYC Corp.
;; November 26, 2018
;;
;; (expand-braces "It{{em,alic}iz,erat}e{d,}")
;; => ("Itemized" "Italicized" "Iterated" "Itemize" "Italicize" "Iterate")
(import (scheme list) (srfi 130))
@edw
edw / map.scm
Created November 25, 2018 21:14
A simple MAP implementation
(define (map proc xs)
(let loop ((xs xs) (result '()))
(if (null? xs) (reverse result)
(loop (cdr xs)
(cons (proc (car xs)) result)))))
@edw
edw / json.scm
Last active November 26, 2018 13:55
JSON parsing in Chibi Scheme using combinators
(import (chibi parse))
;; JSON Parsing
;; Edwin Watkeys
;; Nov 25, 2018
;;
;; Example usage:
;;
;; (parse datum "{\"foo\": true, \"bar\" : [0,1,2,3.14, .12]}")
;; => (("foo" #t)
@edw
edw / generator-bug.scm
Last active November 21, 2018 18:38
Call-CC Bug in Chibi Scheme?
;; This code displays "(0 1)" in Guile, MIT Scheme, and Scheme48. In
;; Chibi, when evaluated from a REPL, it behaves the same, but subsequent
;; evaluations of `(c0)` signal the following error:
;; > (c0)
;; ERROR in child thread: #<Context 140149901512544>
;; ERROR in travel-to-point! on line 657 of file /usr/local/share/chibi/init-7.scm: non procedure application: #f
;; ERROR in travel-to-point! on line 657 of file /usr/local/share/chibi/init-7.scm: non procedure application: #f
(define (counter n)
@edw
edw / scheme-contra-java.md
Last active November 24, 2018 15:57
Scheme (and Lisp) Contra Java (and Nearly Every Other Programming Language)

Scheme (and Lisp) Contra Java (and Nearly Every Other Programming Language)

Edwin Watkeys

History: Originally written September 8, 2005. Updated December 27, 2005; lightly edited December 20, 2013; revised and retitled[0] November 21, 2018; revised November 24, 2018.

One of the big new features of Java 5.0 was a new syntax for iterating over collections. Instead of tediously typing the following:

@edw
edw / log-scale-svg.swift
Created March 23, 2018 13:42
Log scale SVG in Swift
import Foundation
func printLine(_ x: Double, with stroke: Stroke) {
let scaledX = log10(x) * 100.0
print("""
<line x1="\(scaledX)" x2="\(scaledX)" \(stroke)/>
""")
}
enum Stroke : CustomStringConvertible {
@edw
edw / extend-show.scm
Created March 30, 2017 21:02
Extending Chibi Scheme's SHOW: This works, but is it correct?
(define (range n)
(λ (env)
(for-each (λ (i) ((displayed i) env))
(iota n))
env))
(show #f ">>>" (range 10) "<<<" nl) ; => ">>>0123456789<<<\n"