[Bese-devel] Re: admin page currently broken

Marco Baringer mb at bese.it
Tue Aug 9 07:03:31 UTC 2005


William Halliburton <whalliburton at gmail.com> writes:

> This can be replicated with
>
> (setf *form* (walk-form '(mapcar (lambda (a) (+ a 1)) '(1 2 3))))
> (drive-cps (evaluate/cps *form* nil *toplevel-k*))
>
> Looking at (defmethod evaluate/cps ((func free-application-form) env
> k) it looks like a special case needs to be added for mapcar?

we have two options:

1) special case all standard high-order functions

2) use sacla to reimplement them. the plan has always been to use
sacla (a well commented, tested, reimplementation of common-lisp in
common-lisp) for this. try this:

;; define a /cc version of mapcar (can't use defun/cc directly but that's the basic idea)
(setf (get 'mapcar 'defun/cc)
      (make-instance
       'cps-closure
       :code
       (walk-form '(lambda (function list)
                    "Apply FUNCTION to successive elements of lists, return list of results."
                    (do* ((lists (cons list nil))
                          (len (length lists))
                          (args (make-list len) (make-list len))
                          (result (list nil))
                          (splice result))
                         ((do ((l lists (cdr l)) (a args (cdr a)))
                              ((or (null l) (endp (car l))) l)
                            (rplaca a (caar l))
                            (rplaca l (cdar l)))
                          (cdr result))
                      (setq splice
                            (cdr (rplacd
                                  splice
                                  (list (apply function args)))))))
                  nil
                  nil)
       :env
       nil))

(with-call/cc
  (mapcar (lambda (a)
            (+ a 1))
          (list 1 2 3)))
==> (2 3 4)

> Is there a good way to look at the execution of evalutate/cps without tracing?

atm no. however i will be needing to add in a wrapper around each step
of the evaluation of forms, this will make a great point for exactly
that kind of debugging info (and basically step throguh your code for
you).

-- 
-Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
	-Leonard Cohen



More information about the bese-devel mailing list