[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Formal definitions [con'd]



Alex Shinn <alexshinn@x> wrote:

> On Fri, Nov 30, 2012 at 8:29 AM, Jean-Michel HUFFLEN
> <jmhuffle@x>wrote:
> (...)
>> - p. 71, "make-parameter": your definition accepts any positive number
>> of arguments with :
>>
>> (define (make-parameter init . o) ...)
>>
>> Why not using "case-lambda", for "make-parameter" as well as its
>> result?
>
> Because this is actually longer than the cond version.

    OK. But I would remark that in your version, you do not check that  
there is no additional information which would be useless. If we do  
that, that is:

(define (make-parameter init . o)
   (let* ((converter (cond ((null? o) values)
                           ((pair? (cdr o)) (error "bad parameter syntax"))
                           (else (car o))))
          (values (converter init)))
     (lambda args
       (cond ((null? args) value)
             ((and (eq? (car args) <param-set!>) (pair? (cdr args))
                   (null? (cddr args)))
              (set! value (cadr args)))
             ((and (eq? (car args) <parameter-convert>) (null? (cdr args)))
              converter)
             (else (error "bad parameter syntax"))))))

the result is still shorter than the version using "case-lambda", but  
just slightly shorter.

    Yours sincerely,

J.-M.


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports