From: Barton W. <wi...@un...> - 2014-03-27 22:24:49
|
Comments? (defmspec $push4 (z) (let* ((o (car (pop z))) (x (if z (pop z) (wna-err o))) (l (if z (pop z) (wna-err o))) (ll (meval l))) (if z (wna-err o)) (if (and ($mapatom l) ($listp ll)) (progn (setq ll (cons (meval x) (cdr ll))) ;(mset l (if (rulechk 'mlist) (simplifya (cons '(mlist) ll) t) (cons '(mlist simp) ll)))) (mset l (simplifya (cons '(mlist) ll) t))) (merror "Bogus second argument to push4")))) (defmspec $pop4 (z) (let* ((o (car (pop z))) (l (if z (pop z) (wna-err o))) (ll (meval l))) (if z (wna-err o)) (cond (($listp ll) (if ($emptyp ll) (merror "Pop called on empty list") (prog2 (setq ll (cdr ll)) (pop ll) ;(mset l (if (rulechk 'mlist) (simplifya (cons '(mlist) ll) t) (cons (list 'mlist 'simp) ll)))))) (mset l (simplifya (cons '(mlist) ll) t))))) (t (merror "Bogus argument to pop4"))))) Demo: (%i1) compile_file("push-and-pop.lisp")$ (%i2) (load(second(%)), load(basic))$ (%i3) N : 5*10^4$ (%i4) showtime : all; Evaluation took 0.0000 seconds (0.0000 elapsed) (%o4) all (%i5) (l : [], for i : 1 thru N do push4(x,l), for i : 1 thru N do pop4(l)); Evaluation took 0.4800 seconds (0.4800 elapsed) (%o5) done Put a rule onto mlist and try again: (%i6) matchdeclare(xx,true)$ Evaluation took 0.0000 seconds (0.0000 elapsed) (%i7) tellsimpafter([xx,1],12)$ Evaluation took 0.0000 seconds (0.0000 elapsed) (%i8) (l : [], for i : 1 thru N do push4(x,l), for i : 1 thru N do pop4(l)); Evaluation took 0.8800 seconds (0.8800 elapsed) (%o8) done Try the push and pop from basic--oops 72.8 seconds compared to 0.88 seconds (%i9) (l : [], for i : 1 thru N do push(x,l), for i : 1 thru N do pop(l)); Evaluation took 72.8200 seconds (72.8200 elapsed) (%o9) done (%i10) l : [1]; Evaluation took 0.0000 seconds (0.0000 elapsed) Bug with push: (%o10) [1] (%i11) push(x,l); Evaluation took 0.0000 seconds (0.0000 elapsed) (%o11) [x,1] (%i12) expand(%,0,0); Evaluation took 0.0000 seconds (0.0000 elapsed) (%o12) 12 OK with push4 (%i13) l : [1]; Evaluation took 0.0000 seconds (0.0000 elapsed) (%o13) [1] (%i14) push4(x,l); Evaluation took 0.0000 seconds (0.0000 elapsed) (%o14) 12 |