Skip to content

Instantly share code, notes, and snippets.

@g000001
g000001 / gist:910326c3c6d148b017f1d4f67de7678d
Created September 4, 2023 04:08
tao-here-document-reader.lisp
;;; -*- mode: Lisp; coding: utf-8 -*-
(cl:in-package "CL-USER")
(defvar *standard-readtable* (copy-readtable nil))
(defvar *nest-level* 0)
@g000001
g000001 / lunar-object.lisp
Created May 4, 2023 12:45
lunar-object.lisp
;;; -*- mode: Lisp; coding: utf-8 -*-
#||
Lunar
http://users.rcn.com/david-moon/Lunar/data.html#slots
The last slot in a datum can be a multi-slot whose value is a special kind of succession that is embedded in the datum rather than being a separate datum. This enables variable-length classes. The value of each member of a multi-slot must be a member of the slot's declared type.
The Consistent Slot Order Rule also states that only the last slot in the list can be a multi-slot. Thus no class that contains a multi-slot can have a subclass that adds more slots.
@g000001
g000001 / init-once-slot.lisp
Created April 14, 2023 16:51
:init-once slot
;;; -*- mode: Lisp; coding: utf-8 -*-
(cl:in-package "BCL-USER")
(defclass init-once-slot-class (standard-class)
())
(defmethod clos:process-a-slot-option
((class init-once-slot-class) option value
already-processed-options slot)
@g000001
g000001 / foo.lisp
Created December 11, 2022 06:12
code generation
今回のような場合、マクロでコード生成する(楽をしたい)のであれば関数単位というよりは全体を生成することになるかと思いました。
(defmacro doit ()
`(progn
;; data chunk
(write-chars "data" out-stream)
(write-32le (* nsmpl nch (/ nbits 8)) out-stream) ; size of data chunk
(cond
,@(mapcan (lambda (nch)
(mapcar (lambda (n)
@g000001
g000001 / sumim-bench.lisp
Last active September 13, 2022 01:28
Tarai(inlined)
(defun tarai (x y z)
(declare (optimize (speed 3) (debug 0) (safety 0)))
(labels ((tarai (x y z)
(declare (fixnum x y z))
(the fixnum
(if (> x y)
(tarai (tarai (1- x) y z)
(tarai (1- y) z x)
(tarai (1- z) x y))
y))))
@g000001
g000001 / destructuring.lisp
Created December 24, 2021 19:13
destructuring
;; -*- mode: lisp; package: destructuring; -*-
;;; destructuring-bind.l
;;
;; Copyright (c) 1980, Massachusetts Institute of Technology
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions are
;; met:
@g000001
g000001 / named-instance-class.lisp
Last active September 6, 2021 17:23
named-instance-class
;;; -*- mode: Lisp; coding: utf-8 -*-
(ql:quickload 'closer-mop)
(defpackage named-instance-class
(:use c2cl))
(in-package named-instance-class)
@g000001
g000001 / shadow.lisp
Created March 14, 2020 11:47
shadowing
(progn
#.(set-macro-character #\[ (lambda (srm chr)
(declare (ignore chr))
(read-delimited-list #\] srm T)))
[list 0
1
2
#.(progn
(set-macro-character #\[ (lambda (srm chr)
(declare (ignore chr))
@g000001
g000001 / prog.lisp
Created February 19, 2020 16:32
prog style
;; a la MACLISP
(DEFUN FACTORS (N)
(PROG (FACS SQRTN D)
(SETQ FACS () )
(SETQ D 2)
(GO L1)
L2 (SETQ N (FLOOR N D))
(SETQ FACS (CONS D FACS))
L1 (SETQ SQRTN (ISQRT N))
L (COND ((> D SQRTN) (GO X)))