This file contains hidden or 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 accumulate (combiner null-value term a next b) | |
| (if (> a b) | |
| null-value | |
| (funcall combiner | |
| (funcall term a) | |
| (accumulate combiner null-value term (funcall next a) next b))) | |
| ) | |
| (defun accumulate-iter (combiner null-value term a next b) | |
| (defun iter (a result) | |
| (if (> a b) |
This file contains hidden or 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 product (term a next b) | |
| (if (> a b) | |
| 1 | |
| (* (funcall term a) | |
| (product term (funcall next a) next b)))) | |
| (defun product-iter (term a next b) | |
| (defun iter (a result) | |
| (if (> a b) | |
| result |
This file contains hidden or 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 cube (x) (* x x x)) | |
| (defun sum-iter (term a next b) | |
| (defun iter (a result) | |
| (if (> a b) | |
| result | |
| (iter (funcall next a) (+ result (funcall term a))))) | |
| (iter a 0)) | |
| (defun simp-integral (f a b n) |
This file contains hidden or 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 sum (term a next b) | |
| (if (> a b) | |
| 0 | |
| (+ (funcall term a) | |
| (sum term (funcall next a) next b)))) | |
| (defun cube (x) (* x x x)) | |
| (defun integral (f a b dx) | |
| (defun add-dx (x) (+ x dx)) | |
| (* (sum f | |
| (+ a (/ dx 2.0)) |
This file contains hidden or 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 calc-f (n) | |
| (if (< n 3) | |
| n | |
| (+ (calc-f (- n 1)) | |
| (* (calc-f (- n 2)) 2) | |
| (* (calc-f (- n 3)) 3) | |
| )) | |
| ) | |
| (defun calc-f (n) |
This file contains hidden or 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
| #! /usr/bin/sbcl --script | |
| (load "~/quicklisp/setup.lisp") | |
| (with-open-file (*standard-output* "/dev/null" :direction :output | |
| :if-exists :supersede) | |
| (ql:quickload "cl-json")) | |
| (defmacro rep-item (item rep-cnt) | |
| `(loop for i from 1 to ,rep-cnt collect ,item)) | |
| (let ((gossip-item '((a . liszt)(c . msg1)(ts . 123456))) | |
| (part-item '((nick . liszt)(uid . a1b2c3d4)(loc . "(1234,5678)") |
This file contains hidden or 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
| def sigma(n): | |
| return n and (n + sigma(n-1)) or 0 | |
| def sigma_tail(n, sum=0): | |
| return n and sigma_tail((n-1), (n+sum)) or sum | |
| print sigma(50) | |
| print sigma_tail(50) |
This file contains hidden or 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
| def decode(s, encodings=('gbk', 'utf8', 'windows-1251', 'iso-8859-1')): | |
| for encoding in encodings: | |
| try: | |
| return s.decode(encoding) | |
| except UnicodeDecodeError: | |
| pass | |
| return s.decode('iso-8859-1', 'ignore') | |
This file contains hidden or 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
| curl -vvv -H "Content-Type: xml" -H "charset: utf8" -d"a=b" "http://netease-news.tv.opera.com/xhrproxy/?_proxy_fields=&_proxy_headers=content-type,charset&_proxy_url=http%3A//echo.opera.com" |
This file contains hidden or 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
| ; Now suppose we include, together with addition, | |
| ; operations double, which doubles an integer, | |
| ; and halve, which divides an (even) integer by 2. | |
| ; Using these, design a multiplication procedure analogous to | |
| ; fast-expt that uses a logarithmic number of steps. | |
| (defun fast_times (multiplicand multiplier) | |
| (cond ((= multiplier 0) 0) | |
| ((even? multiplier) | |
| (double (fast_times multiplicand (half multiplier)))) | |
| (else |