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
-- project Euler problem 14 | |
import Data.Array (Array,(!),listArray,assocs) | |
import Data.List (foldl1',unfoldr) | |
import Data.Tuple (swap) | |
type Val = Int -- you might want to use Integer, not Int, for 32bit runtime | |
collatzLengths :: Int -> Array Int Val | |
collatzLengths nmax = arr | |
where arr = listArray (1,nmax) (1:[cL i| i<-[2..nmax]]) | |
cL n = f n 0 | |
where f i c |
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
* Common Lisp tips, by Zach Beane: lisptips.com | |
** Runtime | |
*** The four causes of symbol conflicts | |
*** Putting the R in REPL | |
*** Evaluating the last expression | |
*** Describing objects | |
** Data and Control Flow | |
*** How do I apply AND? |
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
;;; -*- Mode:Lisp ; Syntax:Common-Lisp -*- | |
;;; CL-ULFE: unix-like filter elements, by @nfunato on 2015-04-15 | |
;;; - placed in the public domain unless otherwise noted | |
;;; - usually assumed to be used with CL-PPCRE | |
;(ql:quiciload 'cl-ppcre) | |
(require 'cl-ppcre) | |
(defvar *case-fold-p* 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
;;; Five programming problems every Software Engineer should be able to | |
;;; solve in less than 1 hour | |
;;; Problem 1 (SUM) | |
;;; Write three functions that compute the sum of the numbers in a given | |
;;; list using a for-loop, a while-loop, and recursion. | |
(defun sum-r (l &optional (s 0)) (if(null l) s (sum-r (cdr l)(+ (car l) s)))) | |
(defun sum-for (l) (loop for i in l sum i)) | |
(defmacro while (xs &body body) |
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
;;; CAUTION: this code is not fully tested! | |
(ql:quickload | |
;; FIXME: use lquery rather than plump if preferable | |
'( | |
:drakma ; a full-featured common lisp http client | |
:plump ; a parser for HTML/XML like document | |
:clss ; a DOM traversal engine based on CSS selectors | |
:cl-redis ; a client library for Redis database, an advanced K/V store | |
;; :chirp ; a twitter client library for common lisp |
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
;;; -*- Mode: Lisp; Syntax: Common-Lisp -*- | |
;;; sutra transcribing of cl-overload w/ a bit of re-factoring | |
;;; in order to understand its specification | |
;;; 2015-08-22 @nfunato | |
;;; original code is cl-overload.lisp show-matz/CL-OVERLOAD commit 91af6928e5 | |
;;; (formally 91af6928e538cfcf9634d7cbb47771dc4cfa3dcd) as of 2015-07-26 | |
(provide :cl-overload) |
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
{- ported from and/or filled for | |
"Regular Expressions and Automata using Haskell, Simon Thompson (Jan 2000)", | |
by @nfunato on 2012/04/07 -} | |
{- this code is provided "as-is". -} | |
import Data.List (foldl', nub, sort, sortBy, groupBy, elemIndex, findIndex) | |
import Data.Set (Set, empty, size, singleton, fromList, toList, toAscList, | |
elems, member, findMin, insert, union, intersection,(\\)) | |
import qualified Data.List as L -- L.map |
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
(defvar undesirable-ws-cleanup-wo-choice-modes | |
'(lisp-mode)) | |
(defvar undesirable-ws-cleanup-w-check-modes | |
'(org-mode)) | |
(defun undesirable-ws-cleanup () | |
(interactive) | |
(save-excursion | |
(when (or (member major-mode undesirable-ws-cleanup-wo-choice-modes) |
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
;;; 2012/10/27 @nfunato | |
;;; Probably I first saw them at Xerox PCL about 25 years ago. | |
;;; I think almost same code can be seen in many places, including CLtL2. | |
;;; recons / relist / relist* | |
(defun recons (x a d) | |
(destructuring-bind (xa . xd) x | |
(if (and (eql xa a) (eql xd d)) | |
x |
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 Data.List (transpose, unfoldr, intercalate) | |
import Data.Time.Calendar (gregorianMonthLength, fromGregorian) | |
import Data.Time.Calendar.WeekDate (toWeekDate) | |
-- utilities | |
dow y m d = pred $ trd $ toWeekDate $ fromGregorian y m d where trd(_,_,x) = x | |
groupsOf n | n>0 = unfoldr $ \x -> if null x then Nothing else Just(splitAt n x) | |
-- essential start of cal.hs -------------------------------------- | |
type Month = (Integer,Int) -- a local definition of handy month |
OlderNewer