How to cancel the declaration declaration?

It seems that most (if not all) of global declarations cannot be returned in the standard ANSI CL way.

For example, once you evaluate (either directly or by downloading a file) a form such as (proclaim '(declaration my-decl)) or (declaim (special *my-var*)) , there is no portable way to do (declare (my-decl ...)) illegal or *my-var* lexical.

Different implementations offer a non-portable way to return a special declaration, usually via (proclaim '(notspecial *my-var*)) or some other trick.

How about declaration proclamation

How do different options cancel? How do you implement it? Do you think (proclaim '(notdeclaration my-decl)) good idea?

Motivation : it would be nice to be modular in the test suite - so that you can return all the effects of the test statements to avoid any possible interference in parts of the test suite. I know this is a week of motivation, because The Right Way is to use packages .

+7
common-lisp
source share
1 answer

One possible way is to create a transaction mechanism (rollback / commit). This is taken from the Xach Naggum archive :

I am missing a transaction object where I can make a number of changes
to a system that are only visible to my multithreaded thread
and then drop them or transfer them all to
once. For example, downloading a file may be such a transcription. alarm
an error during boot can lead to an integer number of operations preceding it to drop it, and not leave the system in a partially altered state. It is not possible to do this on top of an existing system, but it requires considerable effort, so this is what Common System Lisp programmers must do.

You would miss the opportunity to cancel only a subset of declarations, for example (declare A) , (declare B) , (undeclare A) , but given your motivation, this would not be a problem, because you probably want to cancel all possible announcements made in test time.

You can provide a special form for individual "undeclare" declarations. I would call it retract , but in some cases it can be difficult to determine. Suppose you state that x is a string or a number, can you cancel the declaration that says x is a string? What about inline functions, etc.? The deal looks easier to implement, for example, a temporary environment.

+1
source share

All Articles