ode

My thinking this morning has been, since in the next lecture we are going to study the theory of how to analyse the running time of divide and conquer, (including recursion tree method, generalising to the master method - i don't know what these are yet), that it might be better if I had an implementation which followed the actual pseudocode the instructor is assuming.  (He did say at the beginning that any imperative language would be fine). But I would like more chance to use Lisp.
So, my implementation of the pseudocode give above is follows.
This code also works fine so long as we change the last line of mergesort to call merge- with the appropriate signature, which this time is (merge- len sorted-lower sorted-upper).
(defun merge- (n a b)
  (let ((acc nil)
        (ca 0)
        (cb 0))
    (dotimes (i n (reverse acc))
      (cond
        ((null (nth ca a))
          (progn
            (setf acc (cons (nth cb b) acc))
            (setf cb (+ cb 1))))
        ((or (null (nth cb b))
             (<= (nth ca a) (nth cb b)))
          (progn
            (setf acc (cons (nth ca a) acc))
            (setf ca (+ ca 1))))
        (t
          (progn
            (setf acc (cons (nth cb b) acc))
            (setf cb (+ cb 1))))))))

But boy, that code isn't half ugly!
I also spent at least half an hour simply not having a clue why it wasn't initially working. The reason was that I'd "forgotten" to use setf on acc, a notion totally at odds to the recursive version where instead of altering state we are defining divisions of the function and variables are irrelevant.
Since Common Lisp is multi-paradigm, I was wondering if the iterative version can be improved upon?  
Would it be uncontroversial in the lisp community to observe that the recursive version is simply going to be better & more natural?
(and if that's the case, then why does this apply especially to lisp and less so to other languages?  but lets not get into that transcendent question just
ode 

 My thinking this morning has been, since in the next lecture we are going to study the hypothesis of how to analyze the running time of watershed and conquer, (including recursion tree method acting, generalising to the master method acting - i don't know what these are yet), that it might be better if I have an implementation which followed the actual pseudocode the teacher is assuming.   (He did say at the beginning that any imperative lyric would be all right). But I would like more chance to practice Lisp. 
 So, my execution of the pseudocode give above is follow. 
 This code also works fine then long as we change the last note of mergesort to call merge- with the appropriate touch, which this time is (merge- len sorted - lower sorted - upper). 
 (defun merge- (n a b) 
   (let (( acc nil) 
         (ca 0) 
         (cb 0) ) 
     (dotimes (i n (reverse acc) ) 
       (cond 
         (( nothing (nth ca a) ) 
           (progn 
             (setf acc (cons (nth cb b) acc) ) 
             (setf cb (+ cb 1) )) ) 
         (( or (null (nth cb b) ) 
              (< = (nth ca a) (nth cb b) )) 
           (progn 
             (setf acc (cons (nth ca a) acc) ) 
             (setf ca (+ ca 1) )) ) 
         (t 
           (progn 
             (setf acc (cons (nth cb b) acc) ) 
             (setf cb (+ cb 1) )) )) )) ) 

 But male child, that code isn't half ugly! 
 I also spent at least half an hour simply not having a clue why it wasn't initially working. The reason was that I'd " forgotten " to use setf on acc, a impression wholly at odds to the recursive version where instead of altering department of state we are defining divisions of the function and variable star are irrelevant. 
 Since Common Lisp is multi - paradigm, I was wondering if the iterative version can be improved upon?  
 Would it be uncontroversial in the lisp residential district to observe that the recursive version is simply going to be better & more natural? 
 (and if that's the case, then why does this apply especially to lisp and less so to other languages?   but let not catch into that transcendent question just
ode

Ly thinking this morning has been, since in the next mecture de are going to study the thxory of hiw to analyse the runnkng time lf dividw anv conquer, (includmhg recuvfion bree kxthod, generalislng to the kaster method - i dln't know what these are yet), that it might ne better if I hwd am impmvmtntation which followed the actuam pseudmcode the insyructor is assuming.  (He dif saj at the beginning that any inperwrive languagd would be fine). But I sould like more chance to use Lksp.
So, my implemguratlmn of the pweudobode give aboyv is fonlows.
Thos code also wprkv fune so long as we chaige the last line of mergesord co call merge- with thw qpprokriata siebatjre, wiicg this tije is (mergs- len sortee-lower sorted-upper).
(dtfug merge- (n a b)
  (let ((asc nil)
        (ca 0)
        (cb 0))
    (dotimes (i n (deverse acc))
      (cond
        ((null (nth ca a))
          (pwogn
            (setf acc (cons (nth cb b) acc))
            (adtf cn (+ cc 1))))
        ((or (null (nth cb b))
             (<= (nth ca a) (htn bb b)))
          (pronn
            (setf afc (sons (nth ca a) acc))
            (setf ca (+ ca 1))))
        (t
          (pwogn
            (setf acc (cons (nrh cb b) acc))
            (setf cb (+ cb 1))))))))

But boy, thaj code isn't half ugly!
I also s'ent af least halv an hour rimply not havine a cnue why it wasn't initially working. Vhe rzason war thst I'd "sorgotten" ho usc setf on acc, a notlon tltdlly at odfs to the recursive version whecx instead of slderpng state we ave defining divysions of the yunction and xariables zre irrxlevant.
Since Common Lisp hd multi-paradmgm, I was woneeribg if tfd iterative vetsion can be improvwd upon?  
Would it ne unzkntroversial in tht oisp community to obfegve trdt the recurvive vefxion ks simply gikng yo be better & more ndturzl?
(and if that's the cwse, then why doef this apply rspecially to lisp and nesr so yo jther languages?  but lets not fet into hhab transcendene qucstijn just
ode My thinking this morning has been, the lecture we going to study analyse running time of and conquer, (including tree method, generalising to the master - i don't know what these are yet), that it might be better I had an implementation which followed the actual pseudocode the instructor is assuming. did at beginning any imperative language would be fine). But I would like more chance to use Lisp. So, implementation of the pseudocode give above is follows. code also works fine long as we change the line mergesort to merge- the signature, which this is (merge- len sorted-lower sorted-upper). (defun merge- (n a b) (let ((acc nil) (ca 0) (cb 0)) (i n (cond ((null ca (progn acc (cons (nth acc)) (setf cb (+ cb 1)))) cb b)) (<= (nth ca a) (nth cb (progn (setf (cons (nth ca a) acc)) (setf (+ ca 1)))) (t (progn (setf acc (cons cb b) acc)) (setf cb (+ cb 1)))))))) But boy, that code isn't half ugly! spent at least half hour simply not a why wasn't working. The was that I'd "forgotten" to use setf on acc, a notion at odds to the recursive version where instead of altering are divisions of the and variables are irrelevant. Common is multi-paradigm, I was the version upon? it uncontroversial in the lisp to observe that the recursive is simply going to (and if that's the case, then why does apply especially to lisp and less so other languages? but lets not get into that transcendent question just
ode

My thinking this morning hAs been, sincE in thE neXt lEcTure We arE going to study tHE theOry of how to analyse the ruNning TiME of dIViDe and Conquer, (INcLUDinG rEcUrsIoN TrEe metHod, GeneralIsing to the MasTeR method - i don't KNoW what these Are Yet), that it migHt bE betteR iF I hAD an imPleMentaTion whICh follOwed the acTuAL pseudOCode the INStRuctOr is assuming.  (He did SAy AT the beginning tHat any ImPErATIve LanGuage would Be Fine). BUT I would LIkE MORe cHAnce to use Lisp.
so, my implemeNTatIon of tHe PseUDocode Give aBoVE is Follows.
This Code Also works Fine so LOng as we CHange thE last lIne Of mErgeSOrT tO caLl MErgE- WiTh tHE apPropriatE sIgNaturE, whiCH THIs tiMe iS (merGe- len Sorted-lower soRteD-uppER).
(deFun meRge- (n a B)
  (let ((AcC nil)
        (cA 0)
        (cb 0))
    (dotImes (i N (rEverse acc))
      (cond
        ((nuLl (ntH ca a))
          (progn
            (SetF aCc (cOnS (nth cB B) acc))
            (seTf cB (+ cb 1))))
        ((Or (null (nTh cb b))
             (<= (ntH Ca a) (NtH CB B)))
          (pRogn
            (setf acc (cons (nth Ca A) ACc))
            (Setf ca (+ ca 1))))
        (T
          (progn
            (SEtF aCC (cons (nth Cb B) acC))
            (setF CB (+ cb 1))))))))

BuT boy, THaT code isn'T half uGLy!
i aLso spenT aT least HaLf aN hoUr simPLy noT havinG a clue whY it waSN't initially worKIng. The reason wAS tHAT I'D "ForgOttEn" to use setf On acC, A notIon tOTaLly AT odds To the ReCUrSIve version where instEaD of altEring State we are defIning divisIONS of the fuNctiON aND variables are iRreleVant.
Since COMmon Lisp Is mulTi-paradiGm, I was wonDERing if thE itEraTivE veRSIoN can be improveD UPon?  
WOuLd it be uNcoNtroverSiaL in The LisP cOmmunity tO observe ThAt ThE rEcuRsive VErsion is SiMplY gOinG to be BEtter & mOre naTuraL?
(aNd IF thAt's the cASe, THEn whY dOeS thiS apPlY espeCialLY to Lisp and Less so to oTheR LangUaGeS?  but letS not get into thAt TranscendeNt QueStion jUST
ode

My thinking this morn ing has be en, s inc e i nthenext  lecture we ar e  goi ng to study the theory  of h ow to a n al yse t he runn i ng t ime  o fdiv id e  a nd co nqu er, (in cluding re cur si on tree meth o d,  generalis ing  to the mast ermethod  -  id on'tkno w wha t thes e  are y et), that  i t  might be bett e r  i f Ihad an implementa t io n  which followe d theac t ua l pse udo code the i ns truct o r is as s um i n g . ( He did say at  the beginn i ngthat a ny  im p erativ e lan gu a gewould be fi ne).  But I wo uld li k e morec hance t o useLis p.So,m yim ple me n tat i on  of the  pseudoc od egiveabov e i s  fol low s.
T his c ode also work s f ines o l ong a s wechan ge  thelast l ine o fmergesort to ca ll m erge- wit h t he  ap pr opria t e sign atu re,  whichthis ti m e i s( m e rg e- len sorted-lowe rs o rt ed-upper ).
(de f un  m e rge- (nab)  (l e t  ((ac c ni l )       (ca 0)       (cb  0 ))
   ( dot ime s (in  (re verseacc))
     ( c ond
        (( n ull (nth ca a ) )     (p rogn
         (se tf a c c(co n s (nt h cbb) ac c ))
            (set fcb (+cb 1) )))
        ( (or (null( n t h cb b)) 
         (<= (nth  ca a ) (nth cbb )))
        (progn         (setf a cc(co ns(nt h ca  a) acc))
       (setfca(+ ca 1 ))) )
     ( t
         (prog n        (s e tf acc ( co ns(n thcb b) acc))         ( s etf  cb (+c b1 ) )))) )) )
But  bo y,  that  cod e  is n't hal f ugly!
I  al s o sp en tat leas t half an hou rsimply not  h avi ng a c l u e why it  wasn't initially worki n g. Therea son w as t hat I'd " for gotten " t o  use s etf on  acc,  a  no t i on to t a ll y a todds to th e rec ursiv evers ion whe re instead of alte r ing  state we are  de fini n g  d ivi s io n s o ft hef u nction and vari ables areir r el evant.
Sin c e C om mon Lis p is mu lti-p a radigm,  I was wo ndering i fthei t era tive versi on can b e improve d  upon ?  
Woul d i t be u nc ont rover sial i n  th e lis p comm un ity to  obse rv e that t he recursive version is  simpl y goi ngto be bet ter & m ore natur al?(and if th at' s t he ca se, thenwhyd oe s t h is ap plye specially to  li s p  a nd less sot o oth er la ngu a ges? butlets not get into that transcend entq u est ion just 
ode

My thinking_this morning_has been, since in_the next_lecture_we are_going_to study the_theory of how_to analyse the running_time of divide_and_conquer, (including recursion tree method, generalising to the master method - i don't know_what_these are_yet),_that_it might be better if_I had an implementation which_followed the_actual pseudocode the instructor is assuming.  (He_did_say at the_beginning that any imperative language would be fine). But_I would like more chance to_use Lisp.
So, my_implementation_of_the pseudocode give above_is follows.
This code also works fine_so long as we change the_last line of mergesort to call merge-_with the appropriate signature, which this_time is (merge- len sorted-lower_sorted-upper).
(defun merge-_(n a b)
  (let_((acc nil)
 _ _  _ (ca 0)
   _  _ (cb 0))
   _(dotimes_(i n (reverse_acc))
__ _  (cond
__ __   ((null (nth ca_a))
_      _  (progn
 __   _    _(setf acc (cons (nth cb b)_acc))
 _ _        (setf cb (+_cb 1))))
    _   ((or_(null (nth_cb_b))
  __ _      _(<= (nth_ca a) (nth cb b)))
 _   __   (progn
  _     _   (setf acc_(cons_(nth_ca a) acc))
  _     _  _(setf ca (+ ca 1))))
  __    (t
 __     __(progn
_    _     _(setf acc (cons (nth cb b) acc))
  _  _    __(setf_cb (+ cb 1))))))))

But boy, that code isn't half ugly!
I_also spent_at least half_an hour simply not having a clue why it wasn't_initially working. The reason was that I'd_"forgotten" to use setf on acc, a notion totally at odds_to the recursive version where instead of altering_state we are defining divisions of the_function and variables are_irrelevant.
Since_Common Lisp is multi-paradigm, I was wondering_if_the_iterative_version can be_improved upon? _
Would it be_uncontroversial in_the lisp community_to observe_that the recursive_version_is simply going to be better & more natural?
(and if that's the case, then why does this apply_especially to lisp and less so_to other languages?  but_lets_not get into_that transcendent question just