;; Clojure
(defn add
([] 0)
([x] x)
([x y] (+ x y))
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
(define (evil . args) | |
(set-cdr! args '()) | |
args) | |
(let ((xs '(0 1 2 3))) | |
(display (apply evil xs)) | |
(newline) | |
(display xs) | |
(newline)) |
Edwin Watkeys
2018-11-28
I wrote a tally in Clojure for my profiling library. I'm interested helping out with this.
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
;; 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)) |
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
(define (map proc xs) | |
(let loop ((xs xs) (result '())) | |
(if (null? xs) (reverse result) | |
(loop (cdr xs) | |
(cons (proc (car xs)) result))))) |
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
(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) |
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
;; 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) |
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:
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
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 { |
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
(define (range n) | |
(λ (env) | |
(for-each (λ (i) ((displayed i) env)) | |
(iota n)) | |
env)) | |
(show #f ">>>" (range 10) "<<<" nl) ; => ">>>0123456789<<<\n" |