john saylor | 12 Aug 2012 00:51
Picon
Gravatar

scheme student perplexed by failures ...

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)

Thomas Chust | 12 Aug 2012 02:01
Picon

Re: scheme student perplexed by failures ...

On Sat, 11 Aug 2012, john saylor wrote:
> [...]
> and here is my propsed solution:
> define js-reverse
>    (lambda (ls)
>        ((reverse-rec ls '()))))
> [...]

Hello John,

your code above lacks an opening paranthesis before the define and it has 
an extraneous pair of parentheses around the call to reverse-rec.

> [...]
> (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))))))
> [...]

Again, there is an extraneous pair of parentheses around the use of the if 
syntax.

In Scheme, parentheses are relevant syntax that indicate uses of syntax or 
calls to procedures. The expression

   ((reverse-rec ls '()))

(Continue reading)


Gmane