Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference

# Nyquist

- Debugger Shortcuts
- grindef - print the function definition of a closure
- args - print the argument list of a closure
- setfn - define 'alias' names for functions
- display - framework for debug messages

This page will not save you from reading the Nyquist manual, it's a list of things I find useful but frequently have to look them up in the manuals when I haven't worked with Nyquist for a while. Many more useful tricks can be found in the 'Developing and Debugging in Nyquist' chapter in the Nyquist manual.

## Debugger Shortcuts

Some Nyquist/XLISP debugger shortcuts, defined in 'xlinit.lsp' and 'misc.lsp':

`` |
`(bt)`
| → | baktrace
`` |
`(co)`
| → | continue
`` |
`(top)`
| → | top-level
`` |
`(res)`
| → | clean-up
`` |
`(up)`
| → | clean-up

The debugger commands only work if *breakenable* is non-NIL:

`` |
`(bkon)`
| → | (setq *breakenable* t)
`` |
`(bkoff)`
| → | (setq *breakenable* nil)

You can make your own *tracenable* shortcuts like shown here:

    (defun tron ()
      (setq *tracenable* t))

    (defun troff ()
      (setq *tracenable* nil))

See also:

- XLISP 2.0 Manual → Break Loop

Back to top

## grindef

The 'grindef' function prints the Lisp code of a closure [user-defined function or macro]:

    (defun grindef (e)
      (pprint (get-lambda-expression (symbol-function e))))

Example:

    > (grindef 'grindef)
    (LAMBDA (E)
            (PPRINT (GET-LAMBDA-EXPRESSION (SYMBOL-FUNCTION E))))
    NIL

Back to top

## args

The 'args' function prints the name and the argument variables of a closure [user-defined function or macro]:

    (defun args (e)
      (pprint (cons e (second (get-lambda-expression (symbol-function e))))))

Example:

    > (args 'args)
    (ARGS E)
    NIL

Back to top

## setfn

The 'setfn' macro defines 'alias' names for functions:

    (defmacro setfn (a b)
      `(setf (symbol-function ',a) (symbol-function ',b)))

Examples from 'xlinit.lsp':

    (setfn co  continue)
    (setfn top top-level)
    (setfn res clean-up)
    (setfn up  clean-up)

Back to top

## display

'display' is a debugging macro, defined in 'xlinit.lsp'.

    (defmacro display-macro (label &rest items)
      (let ($res$)
        (dolist ($item$ items)
                (setq $res$ (cons
                             `(format t "~A = ~A  " ',$item$ ,$item$)
                             $res$)))
        (append (list 'let nil `(format t "~A : " ,label))
                (reverse $res$)
                '((terpri)))))

    (defun display-on ()
      (setfn display display-macro) t)

    (defun display-off ()
      (setfn display or) nil)

Usage:

    (display "heading" var1 var2 ...)

expands into:

    (let ()
      (format t "~A: " "heading")
      (format t "~A = ~A  " ',var1 ,var1)
      (format t "~A = ~A  " ',var2 ,var2)
       ... )

and then prints:

    heading : VAR1 = value1 VAR2 = value2 ...

Using the 'display' macro in a function like shown here:

    (defun hello ()
      (let ((local-var 'hello))
        (display "debug message" local-var)
        local-var)) ; return value

Now the 'debug message' can be switched on and off without changing the code:

    > (display-on)
    T

    > (hello)
    debug message : LOCAL-VAR = HELLO
    HELLO

    > (display-off)
    NIL

    > (hello)
    HELLO

Back to top

Nyquist / XLISP 2.0 - Contents | Tutorials | Examples | Reference