Skip to content

Instantly share code, notes, and snippets.

;;; anaphoras and the like
(defmacro aif (tst thn &optional els) `(let ((it ,tst)) (if it ,thn ,els)))
(defmacro awhen (tst &body body) `(let ((it ,tst)) (when it ,@body)))
(defmacro aprog1 (f . fs) `(let ((it ,f)) ,@fs it))
(defmacro acond (&rest cls)
(if (null cls) nil
(let ((cl1 (car cls)) (sym (gensym)))
`(let ((,sym ,(car cl1)))
Python for Lisp Programmers (http://www.norvig.com/python-lisp.html)
by Peter Norvig
邦訳: Lisp プログラマのための Python 入門 (http://www.unixuser.org/~euske/doc/python/python-lisp-j.html)
by Yusuke Shinyama
これはLisp(とPython)の特徴をえぐり出す名文と思っている。翻訳も素晴らしい。
個人的には、以下の段落がとても気に入っている:
Python has the philosophy of making sensible compromises that make
@nfunato
nfunato / _snippets
Last active September 23, 2021 09:35
This gist entry is meant to store uncategorized trivial code snippets and/or toy-programs.

LuaJIT on snabb blog

order by date

  • 2015-07-21 – Code reading: LuaJIT #4 lukego/blog#4
  • 2015-07-24 – Tracing JITs and modern CPUs: double trouble, or, a problem shared is a problem halved? #5 lukego/blog#5
;; some Haskell folding function mimics in Common Lisp
;; (note: string is vector in CL, not list as in Haskell)
(defun seqtyp (seq)
(typecase seq
(list 'list)
(string 'string)
(vector 'simple-vector)
(t (error "Type ~a is not supported in this context." (type-of seq)))))

https://twitter.com/nfunato/status/724555579377635328 の続き:

@phaendal さん

クロージャ変換は通常CPS変換やA正規化の後段に来るクロージャ変数をレジスタ割付けする準備の変換です。古来色んな論文等があります。

クロージャ変換のwikipediaは、https://en.wikipedia.org/wiki/Lambda_lifting にredirectされますが、少し読みにくそうですね。例えば http://matt.might.net/articles/closure-conversion/ などが軽めのようです。これを読むには http://matt.might.net/articles/cps-conversion/ や 両者のMoreResourcesを読みたいかもしれません。どちらも IR上の変換/最適化になります。(この辺で3impとは相容れないかもしれない)

上記で、IRは https://en.wikipedia.org/wiki/Intermediate_representation ですね。住井先生のMin-Camlとその解説もいいかも。これにはA正規形(ANF)と類似のK正規形が出てきます。因みにこの辺のIRでは、letは原始式にしてlambdaで表さないかもしれません。ANFとか正にそういうものです

-- a study for http://morishin.hatenablog.com/entry/haskell-poem-generator
-- 2016-03-09 @nfunato
module Lib (generatePoem) where
import System.Random (randomRIO)
import Data.Maybe (maybe)
import Data.List (foldl', tails)
import Data.Map (Map)
import qualified Data.Map as Map
@nfunato
nfunato / nn2.lisp
Last active January 12, 2016 23:07
;;; -*- coding:utf-8; mode:lisp -*-
;; This is a secondary work for d.hatena.ne.jp/masatoi/20160106/1452057909.
;; See for the article regarding the copyright.
;; 2015-01-09 @nfunato
;; オリジナルに対する本質的な変更は無く、
;; 実質的な変更点は、以下の手法で焦点でない細部を見えないようにしたこと
;; - 数値ベクトルへのarefアクセスは、calc- という関数に分離した
;; - 数値ベクトル以外のarefアクセスはstructure accessor経由にした
原文:[http://www.paulgraham.com/lwba.html Lisp for Web-Based Applications]
;; updated by nfunato on 2015-11-27
----
[http://practical-scheme.net/trans/beating-the-averages-j.html 普通のやつらの上を行け]へのリンクがslashdotにアップされた後に、何人かの読者は、私たちがViawebでLispを使ったことで得られた固有の技術的なアドバンテージについて、さらに詳しく聞きたがった。
興味を持つ人のために、私が2001年4月にマサチューセッツ州ケンブリッジのBBN研究所で行った講演の要約を以下に示す。
----