From: Reini Urban
Subject: defining tests & defadvice in other packages?
Date: 
Message-ID: <35cb6004.46863746@judy>
I'm right now in development of a free lisp library for a simple, not-
conforming Windows-based lisp. (no names please, the lisp is not free
only the lib)
Anyway, I want to keep it as much CL-alike as possible.

Now I've got a few questions which are not defined in the X3J13 ANSI CL
standard but are defined in some lisps I have some descriptions of. In
particular acl, lww, cmucl, openlisp and clisp.

Is there a general consensus about the syntax of testsuites?
------------------------------------------------------------
I found in most implementations a pairwise ordering of 
  form result

one problem is the need of a progn if i want to define some side-effect
only stuff before.

like:
(progn
  (setq l '(0 1 2 3 4))
  (sort l #'<))
(0 1 2 3 4)

I'd come out with my own syntax with the symbol => before the result
which is for me aestetically more pleasing because the result is obvious
at the first glance and i don't need this progn.

like:
(setq l '(0 1 2 3 4))
(sort l #'<)		=> (0 1 2 3 4)

Comments?
Are there more testsuites around? 
I know only of the islisp testsuite 
  http://www.ilog.fr:8001/Eligis/testfn.zip
clisp/tests (which have at least a pleasing .tst extension)
cmucl/src/tests (not in my linux src distribution unfortunately)
cmu: lang/lisp/code/testing/cover/
cmu: lang/lisp/code/testing/tr/

I also want to develop a scheme to automatically write such test scripts
not to forget important cases. You may get only 10% of possible bugs
anyway, but with some kind of systematic approach it maybe easier.
therefore i defined function (tricky) and argument types and some rules.
the good tests are added by hand then of course. but if you write the
sources and the tests too i'll most likely forget some cases.
If wished I'd post some of my rules and function types.
(side-effect-only numeric-overflow numeric-underflow ...)

Is there anything similar or better around?


What are the counterparts of something like defadvice in Lispworks?
------------------------------------------------------------------
I need a scheme for function overloading such as with defadvice in
Lispworks, which takes :before :around and :after methods.
As with CLOS methods, but for any simple lisp function (I only have
functions, no macros nor methods)
deined is: defadvice, call-next-advice and remove-advice

I couldn't find similar functionality in all the other lisp packages.
This is something I cannot believe.
I originally called my function OVERLOAD because DEFADVICE doesn't tell
the novice user too much. I'd prefer self-explaining names.


Implementors suggestion for TIME
--------------------------------
The printout of TIME is implementation dependant. It usually makes a lot
of noise, which is not customizable. I didn't like that and
implemented a scheme which is similar to the unix time tool. (see
time.info)
It is used to print out the whole stuff of used resources, not only the
elapsed time. There you have a customizable *TIME-FORMAT-STRING* which
takes format specifiers like:

*TIME-FORMAT-STRING* magic characters expanded at output:
      Time:
        %E   Elapsed time in [hours:]min:sec
        %e   Elapsed time in seconds
        %m   Elapsed time in milliseconds
        %g   GC time                         (not yet)
        %U   User time (%E-%g)               (not yet)
      Memory:
        %G   Number of new globals
        ·@   Symbollist of new globals, such as (A B C)
        %N   Number of new consed nodes
        %I   Number of internally used nodes (not yet)
        %f   free nodes                      (not yet)
        %S   new used node segments          (not yet)
        %A   segmentsize                     (not yet)
        %c   number of (gc)                  (not yet)
        %x   Output of (mem)
      IO:
        %O   Number of file opens
        %C   Number of file closes
        %w   Number of bytes written
        %r   Number of bytes read
      Command Info:
        %F   Function printed expression
        %R   Return value

It would make sense to get more info like CPU time, max. and avg. memory
usage per thread and so on, but this impossible on my system for now.

My usual setting is:

;;; Resource testing:
(if (not (boundp '*TIMER-FORMAT-STRING*))
  (if *DEBUG*
    (setq *TIMER-FORMAT-STRING*
	   "\n%F => %R\n: %m ms, %G new globals, %N new nodes")
    (setq *TIMER-FORMAT-STRING* "\n%F \t: %m ms")))

Does this makes sense? Better suggestions?
Are there other abbrevations in use?
I'd like to see this in other implementations as well. :)

---
Reini Urban
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
From: Gareth McCaughan
Subject: Re: defining tests & defadvice in other packages?
Date: 
Message-ID: <86ogtwz7y0.fsf@g.pet.cam.ac.uk>
Reini Urban wrote:

> Implementors suggestion for TIME
> --------------------------------
> The printout of TIME is implementation dependant. It usually makes a lot
> of noise, which is not customizable. I didn't like that and
> implemented a scheme which is similar to the unix time tool. (see
> time.info)
> It is used to print out the whole stuff of used resources, not only the
> elapsed time. There you have a customizable *TIME-FORMAT-STRING* which
> takes format specifiers like:
> 
> *TIME-FORMAT-STRING* magic characters expanded at output:
>       Time:
>         %E   Elapsed time in [hours:]min:sec
>         %e   Elapsed time in seconds
[etc]

I think there's a better way.

<rant>
I really, really dislike interfaces that make certain information
available *only* to humans and not to their programs; or, as in
this case, make it available to programs only with extreme pain[1].
`Do this and time it' facilities are usually examples; there are
others. It shouldn't be necessary to parse text output with
unspecified contents to get at this sort of information.

I don't know what the Right Way to do this for Common Lisp would
have been. Maybe something like this:

Macro WITH-TIMING-INFORMATION

Syntax:
  with-timing-information form proc => result*

Arguments and values:
  form -- a form; evaluated as described below.
  proc -- a procedure of one argument, an association list,
          to be called immediately before the results of
          evaluating <form> are returned.
  results -- the values returned by the form.

Description:
  <with-timing-information> evaluates <form> in the current
  environment (lexical and dynamic). A call to
  <with-timing-information> can be compiled.

  After <form> has been evaluated, but before its values are
  returned to the caller of <with-timing-information>, the
  procedure <proc> is called. Its return values are discarded.
  One argument is passed to <proc>: an association list whose
  elements describe the resources used in the evaluation of
  <form>. The keys of the association list are symbols
  denoting particular resources; the corresponding values
  indicate the amount of the resources used.

  The exact set of keys and values supplied is implementation-
  -defined.

Examples:
  None.

Affected By:
  [much as for TIME, of course]

It would be trivial to layer a definition of TIME[2] on top of
an infrastructure like this; and it would make life much easier
for (say) people wanting to write automated programs for
comparing the resources used by various different ways of
doing something.

I suggest: it is *always* a mistake to make a piece of information
available to the user but not to his/her programs. If it's worth
telling the user, it's worth making the information available
properly. This applies to timing information, warnings, error
reports, call tracing, and probably many many other things.
</rant>


[1] (let ((time-info-string
           (with-output-to-string (*trace-output*)
             (time (...)))))
      ;; try to parse TIME-INFO-STRING here. Ugh.
    )

[2] Either in its present form, or with your suggested
    enhancements.

-- 
Gareth McCaughan       Dept. of Pure Mathematics & Mathematical Statistics,
·····@dpmms.cam.ac.uk  Cambridge University, England.