Where is the function 'definitely-so' ?
Here is what happens when I try sublist_indices:
[sen at gumbie .maxima]$ more sublist_indices.lisp
(defun $sublist_indices (items pred)
(let ((items (require-list items "$sublist_indices")))
(do ((i 0 (1+ i))
(xs items (cdr xs))
(acc '() (if (definitely-so (mfuncall pred (car xs))) (cons
(1+ i) acc) acc)))
((endp xs) `((mlist) ,@(nreverse acc))))))
(%i1) load("sublist_indices");
(%o1) ./sublist_indices.lisp
(%i2) sublist_indices ([a, b, c, e, d, a, b, e, s, a, a], lambda ([x],
x = a));
Maxima encountered a Lisp error:
Error in IF [or a callee]: The function DEFINITELY-SO is undefined.
Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.
TIA,
-sen
On Fri, 5 Jan 2007, Robert Dodier wrote:
> On 1/4/07, Bill Wood <william.wood3 at comcast.net> wrote:
>
>> Here's a bare-bones CL function definition:
>>
>> (defun all-positions-if (items pred)
>> (do ((i 0 (1+ i))
>> (xs items (cdr xs))
>> (acc '() (if (funcall pred (car xs)) (cons i acc) acc)))
>> ((endp xs) (nreverse acc))))
>
> Bill, thanks a lot for your help. I've modified the code as shown below.
>
> (defun $sublist_indices (items pred)
> (let ((items (require-list items "$sublist_indices")))
> (do ((i 0 (1+ i))
> (xs items (cdr xs))
> (acc '() (if (definitely-so (mfuncall pred (car xs))) (cons
> (1+ i) acc) acc)))
> ((endp xs) `((mlist) ,@(nreverse acc))))))
>
> A user could paste this into a Maxima session via
> to_lisp();
> <paste>
> (to-maxima)
>
> or copy it to a file and load it via load(<filename>) .
>
> Examples:
>
> sublist_indices ([a, b, c, e, d, a, b, e, s, a, a], lambda ([x], x = a));
> => [1, 6, 10, 11]
> sublist_indices ([a, b, c, e, d, a, b, e, s, a, a], lambda ([x], x = b));
> => [2, 7]
> sublist_indices ([a, b, c, e, d, a, b, e, s, a, a], lambda ([x], x = b
> or x = a));
> => [1, 2, 6, 7, 10, 11]
> P(x) := not (x = a);
> sublist_indices ([a, b, c, e, d, a, b, e, s, a, a], P);
> => [2, 3, 4, 5, 7, 8, 9]
>
> best
> Robert
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
--
---------------------------------------------------------------------------
| Sheldon E. Newhouse | e-mail: sen1 at math.msu.edu |
| Mathematics Department | |
| Michigan State University | telephone: 517-355-9684 |
| E. Lansing, MI 48824-1027 USA | FAX: 517-432-1562 |
---------------------------------------------------------------------------