1. Quiz! -Reply
- Posted by Jay Turley <jturley at MDC.COM> Oct 20, 1998
- 491 views
After running the code, I think that the following recursive reverse is more intuitively correct than the version you posted. Plus you needed an empty case to bottom out the recursion function r_reverse(sequence in) sequence out -- added this line to bottom the recursion out = {} -- for i = 1 to length(in) do if atom(in[i]) then out = in[i] & out else -- added braces to this line to 'sequencize' the recursed -- sequences -- out = r_reverse(in[i]) & out out = {r_reverse(in[i])} & out end if end for return out end function now r_reverse({"hello","world"}) will return {"dlrow","olleh"} rather than {d,l,r,o,w,o,l,l,e,h} -Jay Turley "bored at work"
2. Re: Quiz! -Reply
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Oct 20, 1998
- 493 views
On Tue, 20 Oct 1998, Jay Turley wrote: > -- added braces to this line to 'sequencize' the recursed > -- sequences > -- out = r_reverse(in[i]) & out > out = {r_reverse(in[i])} & out > > end if > end for > return out > end function > > now r_reverse({"hello","world"}) will return > {"dlrow","olleh"} > rather than > {d,l,r,o,w,o,l,l,e,h} Oops! Caught coding on the fly again! Jay's code is how I intended mine to be... Looks like I didn't even pass my own test! :-S :) Incidentally, it's probably better to use: out = prepend(r_reverse(in[i]), out) rather than out = {r_reverse(in[i])} & out . Semantically equivalent (i.e. they do the same thing), but syntactically tidier. IMHO. Feeling very silly, Carl /me hits self over head with fish. *Splat*. -- Carl R White -- Final Year Computer Science at the University of Bradford E-mail...: cyrek- at -bigfoot.com -- Remove the hyphens before mailing. Ta :) URL......: http://www.bigfoot.com/~cyrek/ Ykk rnyllaqur rgiokc cea nyemdok ymc giququezka caysgr -- B.Q.Vgesa