lisp - Rest argument , zero or one argument procedures in racket -
i have procedure:
(define count-calls (let ((count 0)) (lambda char (cond ((null? char) (begin(set! count (+ 1 count)) count)) ((eq? char 'how-many-calls) count) ((eq? char 'reset) (set! count 0))))))
it add together 1 when (count-calls) called when phone call (count-calls 'how-many-calls) doesn't work intended. found if define (lambda (char) instead of (lambda char (eq? ...) part found (lambda char) doesn't seem recognize char.
if dont have parentheses around lambda parameters arguments in list. code comparing 'how-many-calls list.
welcome drracket, version 5.3.3.5 [3m]. language: racket [custom]; memory limit: 8192 mb. > ((lambda args (displayln args)) "a") (a) > ((lambda args (displayln args)) "a" "b") (a b) > ((lambda (args) (displayln args)) "a") > ((lambda (args) (displayln args)) "a" "b") #<procedure>: arity mismatch; expected number of arguments not match given number expected: 1 given: 2 arguments...: "a" "b"
rest lisp arguments scheme racket
No comments:
Post a Comment