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
;;; | |
;;; Comparison of efficiency of EXP and EXPT | |
;;; on SBCL 1.4.2 (x86-64) or Clozure CL 1.11.5 (x86-64) | |
;;; | |
(defconstant +base+ 180d0) | |
(defconstant +logbase+ (log +base+)) | |
;; the followings are equivalent (except for floating-point error) | |
(defun test1 (r) (exp (* +logbase+ r))) |
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
;; {}: Map literal like Clojure | |
;; Note: | |
;; 1. Equality operator is #'eql. | |
;; 2. {} is a literal here though it is a constructor in Clojure: | |
;; Clojure: | |
;; (:b {:a 1 :b (+ 1 2)}) => 3 | |
;; CL: | |
;; (gethash :b {:a 1 :b (+ 1 2)}) => (+ 1 2) |
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
;;; | |
;;; Detect a constant form in compiler-macro | |
;;; | |
;; Example: faster expt when base is fixed | |
(defun fast-expt (base power) | |
(expt base power)) | |
(define-compiler-macro fast-expt (&whole form base power) | |
"Ver. 1 regards only a float literal as constant." | |
(if (and (floatp base) (> base 0)) |
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
;;; -*- encoding: utf-8 -*- | |
;; When I rewrote a code for array-to-list conversion on Stack | |
;; Overflow, I noticed that a simple recursion that returned at the | |
;; end of the tree was slower than a recursion that looked CDRs and | |
;; returned immediately before the end of the tree. Then I examined it | |
;; in detail. | |
(eval-when (:compile-toplevel :load-toplevel :execute) | |
(defparameter OPT '(optimize (speed 3) (safety 0))) |
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
;; -*- encoding: utf-8 -*- | |
;;; | |
;;; Get/Set a text from/to clipboard on Windows. | |
;;; | |
;;; sbcl --load clipboard-win32.lisp --quit | |
(eval-when (:compile-toplevel :load-toplevel :execute) | |
(ql:quickload :cffi)) |
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
;; | |
;; Handle temporary file with UIOP | |
;; | |
(eval-when (:compile-toplevel :load-toplevel :execute) | |
(ql:quickload :cl-ftp) | |
(ql:quickload :quri)) | |
(defparameter *dat-url* (quri:uri "ftp://ftp.cs.joensuu.fi/pub/color/spectra/mspec/munsell380_800_1.asc.gz")) | |
(defparameter *dat-filename* "munsell-joensuu-matt1.dat") |
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
;;; A difference between DECLARE TYPE and CHECK-TYPE produces an | |
;;; optimization problem on SBCL. | |
(declaim (inline add-with-declaring-type!)) | |
(defun add-with-declaring-type! (vector1 vector2) | |
(declare (vector vector1 vector2)) | |
(loop for idx below (length vector1) | |
do (incf (aref vector1 idx) (aref vector2 idx)) | |
finally (return vector1))) |
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
#include <windows.h> | |
#include <wininet.h> | |
#include <stdio.h> | |
/* | |
Roswell on Windows signals an error when download_simple() is called | |
for some HTTPS pages: HttpSendRequest() fails. (Error code is 12029.) | |
This code is a rough reproduction of download_windows.c | |
https://github.com/roswell/roswell/blob/master/src/download_windows.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
;; Get the download counts for all the released assets in a GitHub repo. | |
;; Usage example: | |
;; (count-downloads "froggey" "Mezzano") | |
(eval-when (:compile-toplevel :load-toplevel :execute) | |
(ql:quickload '(:dexador :jsown))) | |
(defun count-downloads (user repository) | |
(let ((releases-dat (jsown:parse (dex:get (format nil "https://api.github.com/repos/~A/~A/releases" user repository))))) |
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
#!/bin/sh | |
#|-*- mode:lisp -*-|# | |
#| | |
exec ros -Q -- $0 "$@" | |
|# | |
;; | |
;; Get the download counts for all the released assets in a GitHub repo. | |
;; Usage: ./query-download-count.ros <user> <repository> | |
;; |
OlderNewer