12 Aug 2012 00:51
scheme student perplexed by failures ...
john saylor <js0000 <at> gmail.com>
2012-08-11 22:51:37 GMT
2012-08-11 22:51:37 GMT
hi been working through 'yet another scheme tutorial' [http://www.shido.info/lisp/idx_scm_e.html], and have come up against something i cannot figure out. here is the "answer:" (define (my-reverse ls) ;(my-reverse-rec ls ())) (my-reverse-rec ls '())) (define (my-reverse-rec ls0 ls1) (if (null? ls0) ls1 (my-reverse-rec (cdr ls0) (cons (car ls0) ls1)))) works great- reverses the list. and here is my propsed solution: define js-reverse (lambda (ls) ((reverse-rec ls '())))) (define js-reverse-rec (lambda (asc dsc) ((if (null? asc) dsc ;(js-reverse-rec (cdr asc) (list dsc (car asc))))))) (js-reverse-rec (cdr asc) (cons (car asc) dsc))))))(Continue reading)
RSS Feed