From: Jeremiah Thomas Isaacs
Subject: Lisp version of asserta(x).
Date: 
Message-ID: <5g9nbp$qg6@hermes.acs.unt.edu>
Ive been programming in lisp more and more, and find one thing id like to
do.  In prolog it is fairly easy to use asserta/assertz, but I have failed
to see a way to do this in Lisp.  a horrible workaround is to format text
to a file, and then evaluate the file.  and (although I havent tried it)
another way would  be eval '... (and printing to a file also, to see what
it was asserting at runtime)  but why does using eval make me feel like
I am cheating?  im not the greatest lisp'er, so be gentle if this question
lacks substance.


bonvolu, jeremiah
--
-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-
·······@jove.acs.unt.edu   talk.bizarre.rabbit
http://people.unt.edu/~jti0001

space age, come on, why dont you flex your magic muscle.
space age, come on, why do you hustle and bustle.
space age, come on, why dont you flex your magic muscle.
space age, come on, why dont you just do that.           -capt beefheart

From: Rolf-Thomas Happe
Subject: Re: Lisp version of asserta(x).
Date: 
Message-ID: <r53etze61h.fsf@xtreme.mathematik.uni-freiburg.de>
In article <··········@hermes.acs.unt.edu> ·······@jove.acs.unt.edu 
(Jeremiah Thomas Isaacs) writes:
   do.  In prolog it is fairly easy to use asserta/assertz, but I have failed
   to see a way to do this in Lisp.  a horrible workaround is to format text

I suppose you want to construct a procedure and install it as the 
symbol-function of a symbol of your choice. Silly example:

(defun make-procedure () #'(lambda (x) (list x (random 3)))) 
(setf (symbol-function 'foo) (make-procedure))

[Here FOO is unary.]

rthappe
From: Nathan Sidwell
Subject: Re: Lisp version of asserta(x).
Date: 
Message-ID: <33292758.51F1@pact.srf.ac.uk>
Jeremiah Thomas Isaacs wrote:
> 
> Ive been programming in lisp more and more, and find one thing id like to
> do.  In prolog it is fairly easy to use asserta/assertz, but I have failed
> to see a way to do this in Lisp.  a horrible workaround is to format text
> to a file, and then evaluate the file.  and (although I havent tried it)
> another way would  be eval '... (and printing to a file also, to see what
> it was asserting at runtime)  but why does using eval make me feel like

What you need is a macro, which works by processing its args before they
are
evaluated, the form produced by the macro is evaluated. And conditions
are
a way of adding new error types.

Here are the conditions and macros I use. The names are as they are,
because they're part of a compiler -- modify at your desire.

;;{{{  diagnostics
;;; condition we add
;;{{{  (define-condition compiler-logic (control-error)
(define-condition compiler-logic (control-error)
  ((string :initarg :string))
  (:report
    (lambda (condition stream)
      (format stream "Logic failure '~a'" (slot-value condition
'string)))))
;;}}}
;;{{{  (define-condition compiler-assert (compiler-logic)
(define-condition compiler-assert (compiler-logic)
  ((form :initarg :form))
  (:report
    (lambda (condition stream)
      (format stream "Assertion failure ··@w'" (slot-value condition
'form)))))
;;}}}

;;; macros to invoke these
;;{{{  (defmacro compiler-assert (expr)
(defmacro compiler-assert (expr)
  `(if (not ,expr)
    (error 'compiler-assert :form ',expr)))
;;}}}
;;{{{  (defmacro compiler-logic (string)
(defmacro compiler-logic (string)
  `(error 'compiler-logic :string ',string))
;;}}}

;;}}}

use is
(compiler-assert (this-must-be-non-nil))
will produce an error if the condition is not met.
(compiler-logic "This can't happen")
will always produce an error, use when you think you can't get somewhere

Conditions are described in chapter 29 of cltl2

I have an outermost handler-case wrapper, to catch all these things,
when the code is not being debugged, so I can produce a sensible user
visible diagnostic,

(handler-case
  (my-main-func)
  (error (condition)
    (let ((*print-length* 3) (*print-level* 2))
      (format *error-output* "~&Compiler bug!~&~a~&" condition))
    (compiler-bug-report)
    nil))

hope this helps
nathan

-- 
Nathan Sidwell                    The windy road is more interesting
Chameleon Architecture Group at SGS-Thomson, formerly Inmos
http://www.pact.srf.ac.uk/~nathan/                  Tel 0117 9707182
······@pact.srf.ac.uk or ······@bristol.st.com
From: Rolf-Thomas Happe
Subject: Re: Lisp version of asserta(x).
Date: 
Message-ID: <r5endi2ig6.fsf@xtreme.mathematik.uni-freiburg.de>
Because of the rather obscure impression my midnightly 1st reply gives
me now on rereading, I try for a second time.

[Your question: how to asserta/assertz in Lisp]

In Prolog asserta&z allow to define relations or change the meaning of
relations at runtime by adding clauses to the database (which may have
been built at runtime, too).

So I assume you want to know how to do a similar thing in Lisp, i.e. 
how to define functions (or procedures) at runtime. My suggestion: 
instead of consing up & evaluating defuns, construct function objects 
and add definitions as in the following example (not as foo bar as the
one I gave in my previous post):

;; imagine we are inside a DEFUN
(setf (symbol-function 'foo) (complement #'numberp))
;; or
(let ((not-number-p (complement #'numberp)))
  (defun foo (x) (funcall not-number-p x)))

(Internal DEFUNs affect the global environment).

rthappe