From 06ef04aede4788813b2d694c5330814e48716595 Mon Sep 17 00:00:00 2001 From: Emin Arslan Date: Tue, 21 Jan 2025 14:20:13 +0300 Subject: [PATCH] Initial Commit --- messing-with-defun.lisp | 45 ++++++++++++++++++++++++++++++++++++++++ messing-with-defun.lisp~ | 4 ++++ 2 files changed, 49 insertions(+) create mode 100644 messing-with-defun.lisp create mode 100644 messing-with-defun.lisp~ diff --git a/messing-with-defun.lisp b/messing-with-defun.lisp new file mode 100644 index 0000000..a29b23c --- /dev/null +++ b/messing-with-defun.lisp @@ -0,0 +1,45 @@ +;; This is just proof-of-concept. +;; This "library" is not meant to be seriously used - but it *can* be used +;; +;; The idea is this: what if you could, actually develop purely from the repl? +;; This idea comes from my (admittedly very briefly) playing with the interlisp medley +;; project. Essentially, you write things into the repl. Function definitions, packages, +;; whatever. Then you call, say, (save-definitions) or some function, and +;; everything you've defined gets saved into a file. +;; Obviously very possible, but I wanted to implement it myself. + +;; whether this is a sane way to develop a program, or if this is desirable +;; in any way whatsoever, is left as an exercise for the reader. + +(defpackage :program-saver + (:use :cl) + (:shadow :defun :defparameter :defvar)) + +(in-package :program-saver) + +;; essentially, we shadow defun, defparameter etc. +;; and replace them with identical ones that add the definition +;; to a global list. +;; I should probably add some more stuff here - +;; everything is just saved as if they're all in the same file. +(defparameter *definitions* nil) + +(defmacro defun (name lambda-list &body body) + (push (list 'defun name lambda-list body) *definitions*) + `(cl:defun ,name ,lambda-list ,@body)) + +(defmacro defvar (name val) + (push (list 'defvar name val) *definitions*) + `(cl:defvar ,name ,val)) +(defmacro defparameter (name val) + (push (list 'defparameter name val) *definitions*) + `(cl:defparameter ,name ,val)) + +(cl:defun reset-defs () + (setf *definitions* nil)) +(cl:defun save-definitions (fname) + (with-open-file (out fname :direction :output) + (dolist (i (reverse *definitions*)) + (print i out)))) + +; now just (use-package :program-saver) diff --git a/messing-with-defun.lisp~ b/messing-with-defun.lisp~ new file mode 100644 index 0000000..d75344d --- /dev/null +++ b/messing-with-defun.lisp~ @@ -0,0 +1,4 @@ + +(defpackage :my-test + (:use :cl) + (:shadow :defun))