Gello
Gello

Reputation: 35

Is there a way to print an error message when you try to print a variable?

For example:

CL-USER 1 > (setq l1 '(a b c))
(A B C)

CL-USER 2 > l1
(A B C)

When I type l1, instead of (A B C) I want to print a different message, is that possible? Because is not a manipulation of a function, where I put a condition and instead of the list I print a message.. In this case there's no function.

Upvotes: 0

Views: 70

Answers (1)

Xach
Xach

Reputation: 11829

Symbol macros are a way to evaluate arbitrary code rather than lookup a value when evaluated. For example:

* (define-symbol-macro l1 (error "No peeking!"))
* l1
ERROR: No peeking!

Upvotes: 4

Related Questions