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
; John McCarthy. Puzzle Solving Program in LISP. Memo 20, Artificial Intelligence Project | |
; http://www.bitsavers.org/pdf/mit/ai/aim/AIM-020.pdf | |
; 1960 | |
; Common Lisp translation: Rainer Joswig, 2016, joswig@lisp.de | |
; basically the code is unchanged, but using s-expression syntax in Common Lisp | |
(defparameter pzl | |
'((a1 (a2 a5) 7.5) | |
(a2 (a1 a5 a9 a3) 3.5) |
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
; Copyright Rainer Joswig, 2023, joswig@lisp.de | |
; simple LABELS replacement, expanding to non-recursive code | |
; the goal is to provide a simple LABELS like operator | |
; which optimizes simple self-tail-recursive code to | |
; to a stack-less jump. | |
; limitations: does not detect when a call is NOT in tail position, | |
; which would require a code walker. |
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 MICRO-MANUAL FOR LISP - NOT THE WHOLE TRUTH, 1978 | |
; John McCarthy, Artificial Intelligence Laboratory, Stanford University | |
; https://www.ee.ryerson.ca/~elf/pub/misc/micromanualLISP.pdf | |
; https://github.com/jaseemabid/micromanual | |
; for CL : Rainer Joswig, joswig@lisp.de | |
; this version runs in a 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
; Implementing a loop via circular code in Common Lisp. | |
; | |
; This code could work with a Lisp interpreter, but not a Lisp compiler. | |
; #n= is a label for a s-expression | |
; #n# references a labeled s-expression | |
; note that we can use SBCL for this, too. We just have to switch to its interpreter. | |
#+sbcl (setf sb-ext:*evaluator-mode* :interpret) |
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
;;; -*- Syntax: ANSI-Common-Lisp; Package: CL-USER -*- | |
;;; Author: Rainer Joswig, joswig@lisp.de, 2022 | |
;;; This code is written in portable Common Lisp. | |
; https://adventofcode.com/2022/day/10 | |
;; This solution makes use of multiple dispatch and standard method combinations of CLOS. | |
(defparameter *input-10* |
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
;;; -*- Syntax: ANSI-Common-Lisp; Package: CL-USER -*- | |
;;; Author: Rainer Joswig, joswig@lisp.de, 2022 | |
;;; This code is written in portable Common Lisp. | |
; https://adventofcode.com/2022/day/5 | |
(defparameter *file05* | |
(if (member :lispm *features*) | |
(pathname "rjmbp:/Users/joswig/Lisp/aoc2022/input-5.txt") |
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
(setf (logical-pathname-translations "LIB") | |
`(("**;*" ,(make-pathname | |
:name :wild | |
:directory (append (pathname-directory | |
(sys:lisp-library-directory)) | |
(list :wild-inferiors)) | |
:defaults (sys:lisp-library-directory))))) | |
; now you can use the logical pathname LIB to refer to LispWorks files: | |
; (compile-file-if-needed "lib:examples;editor;commands;space-show-arglist.lisp" :load 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
;;; -*- Syntax: ANSI-Common-Lisp; Package: (LEXICAL-ANALYZER :USE CL) -*- | |
;; From: https://rosettacode.org/wiki/Compiler/lexical_analyzer#Common_Lisp | |
;; minor changes by Rainer Joswig, joswig@lisp.de, 2022 | |
#+genera | |
(cl:require "GRAY-STREAMS") | |
(cl:defpackage #:lexical-analyzer |
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
; source https://github.com/woodrush/sectorlisp-examples/blob/main/lisp/basic.lisp | |
; Common Lisp translation: joswig@lisp.de, 2022 | |
; https://gist.github.com/lispm/a2f56a1a6dc5599a039eb7134d99cd4a | |
(defun basic-example () | |
(BASICINTERPRETER | |
(QUOTE ( | |
(10 REM FIND AND PRINT PRIME NUMBERS BELOW N_MAX. ) | |
(20 LET N_MAX = (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) ) | |
(30 LET I = (1 1) ) |
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
(defun split-alphanumeric-string (string) | |
(let ((pos0 0) | |
(pos1 0) ) | |
(labels ((end-pos-of (fn) | |
(loop while (and (< pos1 (length string)) | |
(funcall fn (aref string pos1))) | |
do (incf pos1)) | |
pos1)) | |
(loop while (< pos0 (length string)) | |
when (not (digit-char-p (aref string pos0))) |
NewerOlder