[Openmcl-devel] tagbody and go
Pascal Costanza
pc at p-cos.net
Wed Dec 8 10:08:00 PST 2010
There is no computed goto in Common Lisp, so what you want cannot be expressed with tagbody and go. case/ecase/ccase is the closest you can get in a straightforward way.
An alternative would be to compute a jump table manually. Roughly like this:
(defun table-step (step)
(let ((table (vector (lambda () 0) (lambda () 1) (lambda () 2) ...)))
(funcall (svref table step))))
...of course with the right kind of macrology around. But I doubt this buys you a substantial advantage.
The timings below don't tell you a lot because gostep and runstep don't perform the same kinds of computations.
Pascal
On 8 Dec 2010, at 18:58, Taoufik Dachraoui wrote:
> I run the following test to show that ecase is not jumping directly
> to the given step (less efficient then (go step)):
>
> (defmacro gostep (step)
> `(block nil (tagbody (go ,step)
> ,@(loop for i = 0 then (1+ i)
> while (< i 100)
> append `(,i (return-from nil ,i) (go end)))
> end)))
>
> (defmacro define-runstep ()
> `(defun runstep (step)
> (block nil
> (ecase step
> ,@(loop for i = 0 then (1+ i)
> while (< i 100)
> collect `(,i (return-from nil ,i)))
> ))))
>
> (define-runstep)
>
> ? (time (dotimes (i 10000000) (gostep 99)))
> (DOTIMES (I 10000000) (GOSTEP 99)) took 30 milliseconds (0.030 seconds) to run
> with 2 available CPU cores.
> During that period, 30 milliseconds (0.030 seconds) were spent in user mode
> 0 milliseconds (0.000 seconds) were spent in system mode
> NIL
> ? (time (dotimes (i 10000000) (runstep 99)))
> (DOTIMES (I 10000000) (RUNSTEP 99)) took 988 milliseconds (0.988 seconds) to run
> with 2 available CPU cores.
> During that period, 986 milliseconds (0.986 seconds) were spent in user mode
> 0 milliseconds (0.000 seconds) were spent in system mode
> NIL
>
>
> -Taoufik
>
> On Wed, Dec 8, 2010 at 6:11 PM, Alexander Repenning <ralex at cs.colorado.edu> wrote:
>
> On Dec 8, 2010, at 9:52 AM, Taoufik Dachraoui wrote:
>
> > It is not exactly what I am looking for, I would like to jump directly to the step.
> > The ecase will check all the clauses in order (like cond) until it finds a match.
>
>
> duno what CCL does in this particular case but most compilers could generate a jump and would not have to test all the previous clauses. In other words this is an implementation question.
>
> alex
>
>
>
>
--
Pascal Costanza, mailto:pc at p-cos.net, http://p-cos.net
Vrije Universiteit Brussel
Software Languages Lab
Pleinlaan 2, B-1050 Brussel, Belgium
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20101208/2efabfb6/attachment.htm>
More information about the Openmcl-devel
mailing list