[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: select-item-from-list
- To: BRIGHT@ENH.NIST.GOV
- Subject: Re: select-item-from-list
- From: lynch@aristotle.ils.nwu.edu (Richard Lynch)
- Date: Fri, 8 Mar 91 11:20:45 CST
- Cc: info-macl@cambridge.apple.com
>
>Could someone please send me a simple example or two of a formatted
>print function for the :table-print-function when using
>(select-item-from-list )? I just can't get one to work. I'm using
>MACL 1.3.2.
>
>
>Thanks v. much
>Dave Bright
>
>
Well, you did say simple. :-)
;;;Example 1.
(select-item-from-list (list 'a 'b 'c)
:table-print-function
(nfunction table-print-function
(lambda (value stream)
;This can be any form(s) that gets value out to stream.
(format stream " ~A" value)
) )
)
;;;Example 2.
(defun symbol-print (symbol stream)
;This can be any form(s) that gets value out to stream.
(format stream " ~A" symbol)
)
(select-item-from-list (list 'd 'e 'f)
:table-print-function #'symbol-print
)
;;;Example 3. Usable, but NOT recommended.
(select-item-from-list (list 'g 'h 'i)
:table-print-function
#'(lambda (symbol stream)
;This can be any form(s) that gets value out to stream.
(format stream " ~A" symbol)
)
)
Gotchas for the table-print-function:
1. It must be a function of 2 arguments, and the FIRST one is the value in
the cell, and the SECOND one is the stream. Most Common LISP functions
that do output (e.g. princ) fit this description.
2. DON'T use a quoted form. DO use an nfunction (example 1) or an
honest-to-goodness function (example 2). Use the latter if you've already
defined your function for use elsewhere; use the former if you have not.
The quoted form will work unless you try to make an application. But since
the application does not contain the compiler, it won't work there.
(Somewhere in one of the upgrades, the manual stopped mentioning that you
could use a quoted form for this very reason. But it was never explicitly
mentioned as a 'lost feature' [small loss], and many people get bit by
this.)
3. Example 3 is included for completeness. It will work fine, BUT can
make backtracing hard if (when) you have a bug. That is the only reason it
is not recommended.
Hope this helps!
"TANSTAAFL" Rich lynch@aristotle.ils.nwu.edu