Skip Navigation
InitialsDiceBearhttps://github.com/dicebear/dicebearhttps://creativecommons.org/publicdomain/zero/1.0/„Initials” (https://github.com/dicebear/dicebear) by „DiceBear”, licensed under „CC0 1.0” (https://creativecommons.org/publicdomain/zero/1.0/)XH
xhash101 @alien.top
BOT
Posts 1
Comments 0

CL newbie questions

  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 ?

0