Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting default argument value in Racket

Tags:

Is it possible to set a default value to some of arguments in Racket?

Like so in Python:

def f(arg=0)
    ...
like image 975
Vladimir Keleshev Avatar asked Aug 20 '11 17:08

Vladimir Keleshev


People also ask

Can you set default values to Python arguments?

Python allows function arguments to have default values. If the function is called without the argument, the argument gets its default value.

What is the value of a default argument?

A default argument is a value provided in a function declaration that is automatically assigned by the compiler if the calling function doesn't provide a value for the argument. In case any value is passed, the default value is overridden.

Can a function argument have default value?

Any number of arguments in a function can have a default value.


1 Answers

Yes; take a look at: declaring optional arguments.

For example:

(define (f [arg 0])
  (* arg 2))

Racket also supports functions with keyword arguments. The link should lead to documentation that talks about them too. Good luck!

like image 117
dyoo Avatar answered Oct 30 '22 18:10

dyoo