How to set default parameters or additional parameters in a circuit?

I am trying to figure out how to set default parameters or advanced parameters in a circuit.

I tried (define (func a #!optional b) (+ a b)), but I can not find a way to check if the parameter is the default bvalue, because just calling (func 1 2)will give an error:

Error: +: number required, but got #("halt") [func, +]

I also tried (define (func a [b 0]) (+ a b)), but I get the following error:

Error: execute: unbound symbol: "b" [func]

If this helps, I use BiwaScheme as used in repl.it

+4
source share
2 answers

This works fine in Racket:

(define (func a (b 0)) ; same as [b 0]
  (+ a b))

For instance:

(func 4)
=> 4
(func 3 2)
=> 5

... , . , , :

(define (func a . b)
  (+ a (if (null? b) 0 (car b))))

? b - . , , .

+2
+1

All Articles