this post was submitted on 12 Oct 2023
1 points (100.0% liked)

Lisp

53 readers
2 users here now

founded 1 year ago
MODERATORS
 
  1. A program, written in CL, is a huge mutable state. It seems that one can redefine nearly every symbol and there is no immutable data structures. But, as far as I understand, one can modify the language by using macros. So, is it possible to create a macro, which protects data structures from mutation or forbids the usage of mutable operators. For example:
(defmacro with-immutable-scope (&body body)
  ...)
(with-immutable-scope
  (let ((q (list 1)))
    (setf q 1))) => compilation error
  1. A public interface of a CL package consists of symbols. How can I specify and find out, what a symbol from a different package refers to? Should I do the following:

To specify what I export:

(defpackage :foo
  (:use :cl)
  (:export
   ;; macros
   :with-immutable-scope
   ;; functions
   :fetch-data
   ...

To find out what I import:

(describe fetch-data)
  1. When I create a variable binding with `let` and then modify the variable, this modification doesn't propagate through the binding. Example:
(defstruct point x)
 (let* ((point-obj (make-point :x 1))                                                      
        (x-ref (point-x point-obj)))                                                       
  (setf x-ref 2)                                                                          
  (point-x point-obj)) ;; => returns 1 because setf changed the reference to point-x but not the point-x itself

Does it mean that the let-bindings are effectively read-only pointers?

  1. How can I remove a method, which was previously associated with a generic function? For example:
(defgeneric foo (x))
(defmethod foo ((x list))
	   "list")
(defmethod foo ((x integer))
	   "integer")
(fmakeunbound-for-clos-methods '(foo (x integer))) ;; <- need help here
(foo '()) ;; => "list"
(foo 1)   ;; => NO-APPLICABLE-METHOD-ERROR

Does `fmakeunbound-for-clos-methods` exist ?

no comments (yet)
sorted by: hot top controversial new old
there doesn't seem to be anything here