Skip to content

Instantly share code, notes, and snippets.

#!/usr/local/bin/sbcl --script
;; The exercise in http://d.hatena.ne.jp/eel3/20151102/1446476928
;; https://github.com/mrkkrp/unix-opts/blob/master/example/example.lisp
(load "unix-opts") ; or (ql:quickload "unix-opts")
;;-------------------------------------------------------------------
;; Essential processing
;; Similar to the following Haskell expression, but in somewhat eager:
@nfunato
nfunato / ZenHan.el
Last active July 9, 2016 02:35
Convert numbers, alphabets, and some other characters (except punctuations) from Zenkaku format to Hankaku format.
;; checked under Emacs24
(defun eisuu-hankaku-region (from to &optional ascii-only)
"Convert JP `zenkaku' eisuu ([A-Z0-9a-z]) and some other chars, which does
not include punctuation chars, in the region to `hankaku' chars.
`Zenkaku' chars belong to `japanese-jisx0208'
`Hankaku' chars belong to `ascii' or `japanese-jisx0201-kana'.
NOTE: Optional argument ASCII-ONLY is ignored here."
(interactive "r\nP")
(save-restriction
(narrow-to-region from to)
;;; -*- 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)
;;; 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
;;; 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)
@nfunato
nfunato / fizzbuzz.fth
Last active June 24, 2022 23:09
FizzBuzz in gforth (for code golf)
\ FizzBuzz in Forth by @nfunato on 2015-04-30
\ http://golf.shinh.org/p.rb?FizzBuzz#Forth
\ Execution rule:
\ 1. invoke shell
\ 2. exec gforth this-file -e bye
\ : x
\ 101 1 do
\ 1
@nfunato
nfunato / _sample.lisp
Last active June 21, 2020 06:59
CL utility snippets
;;; CL utility snippets -- MIT LICENSE
;;;
;;; originally starting from porting p59c.hs (https://gist.github.com/nfunato/9559350#file-p59c-hs) to CL,
;;; which uses
;;; delay, force (promise.lisp)
;;; xsequence (xsequence.lisp)
;;; xtranspose (xtranspose.lisp)
;;; groups-of, xsplit, xmerge (groups-of.lisp)
;;; 2015-09-27 tconc and lconc (xconc.lisp, xconc.scm)
;;; 2015-09-29 random test stuff (for-random-test.lisp)
@nfunato
nfunato / cl-ulfe.lisp
Last active August 29, 2015 14:19
Unix-like filter elements in Common Lisp
;;; -*- 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)
@nfunato
nfunato / CL-tips.org.txt
Last active August 29, 2015 14:17
org-mode headings of lisptips.com and slime-tips.tumblr.com -- for remembrance of what are there
* 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?
@nfunato
nfunato / p14.hs
Last active August 29, 2015 14:07
-- 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