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, [email protected] | |
; 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
; 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, [email protected], 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, [email protected], 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
;;; -*- Syntax: ANSI-Common-Lisp; Package: (LEXICAL-ANALYZER :USE CL) -*- | |
;; From: https://rosettacode.org/wiki/Compiler/lexical_analyzer#Common_Lisp | |
;; minor changes by Rainer Joswig, [email protected], 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: [email protected], 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
; https://leetcode.com/problems/fair-candy-swap/ | |
(defun candy-swap (a b &aux (sa (reduce #'+ a)) (sb (reduce #'+ b))) | |
(mapc (lambda (x &aux (y (+ x (/ (- sb sa) 2)))) | |
(when (member y b) | |
(return-from candy-swap (values x y)))) | |
a)) |
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
;;; Paper: https://arxiv.org/pdf/2001.02491.pdf | |
;;; Code: https://github.com/cvlab-epfl/n-queens-benchmark | |
;;; Lisp Code: https://github.com/cvlab-epfl/n-queens-benchmark/blob/master/code/queens.lisp | |
;;; Changes/extensions to the original Common Lisp code: Rainer Joswig, [email protected], 2020 | |
;; * using bitvectors is faster than 'boolean' arrays (which typically aren't supported in CL) | |
;;; In Common Lisp | |
;;; * use Quicklisp | |
;;; * compile and load this file |
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
;;; https://www.quora.com/Do-C-developers-find-multiple-inheritance-a-useful-feature-Do-Java-developers-ever-find-themselves-wishing-Java-supported-it/answer/Mario-Galindo-Queralt | |
; Common Lisp: Rainer Joswig, [email protected], 2019 | |
;;; ====================================================== | |
;;; Features | |
(defclass walk () |
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
; https://github.com/netb258/clj-maze/blob/master/src/maze/core.clj | |
; CL version, by Rainer Joswig, [email protected], 2019 | |
; changes | |
; maze is a 2d array, contents are symbols/numbers | |
; pass directions as symbols | |
; use paths as position histories |
NewerOlder