Skip to content

Instantly share code, notes, and snippets.

@youz
Created February 10, 2012 05:05
Show Gist options
  • Save youz/1786833 to your computer and use it in GitHub Desktop.
Save youz/1786833 to your computer and use it in GitHub Desktop.
xl-open-uri/provider/fizzbuzz.l
(eval-when (:compile-toplevel :load-toplevel :execute)
(require "http-client")
(require "xl-open-uri/package"))
(defpackage :xl-open-uri.provider.fizzbuzz
(:use :lisp :editor))
(in-package :xl-open-uri.provider.fizzbuzz)
(defun open-uri (uri &rest opts)
(let ((i 0) (ul 100))
(when (string-match "^fizzbuzz://\\([0-9]+\\)$" uri)
(setq ul (parse-integer (match-string 1))))
(labels ((reader ()
(when (< i ul)
(format nil "~A~%"
(case (gcd (incf i) 15)
(15 'FizzBuzz)
(5 'Buzz)
(3 'Fizz)
(t i)))))
(closer (abort) nil)
(listener () (< i ul)))
(values #'reader #'closer #'listener (gensym "fizzbuzz-counter"))
)))
(provide "xl-open-uri/provider/fizzbuzz")
;;; xyzzy lisp REPL
user> :req "xl-open-uri"
t
user> :mkp test :use (:lisp :ed :xl-open-uri)
#<package: test>
test> (xl-open-uri.core-extensions:install)
nil
test> (with-open-file (s "fizzbuzz://20")
(loop (format t "~A~%" (read-line s))))
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
EOFに達しました: #<general-input-stream 66655352>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment