Association of symbols with mathematical operators

Is there a way to associate a symbol with a mathematical operator?

for example, if I can associate the letter "b" as an addition, then

(b 2 2)

Output

4

Is it possible? If there are any materials or examples that I can use as a guide?

+3
source share
2 answers

It is quite simple, look:

(define b +)
(b 2 2)
> 4

Now bis an alias for +. You can use the same idea to create aliases for any required procedure with any name (this is not limited to single-character names). Keep in mind that this will not work for other special forms; for example, this will result in an error:

(define my-and and)
+8
source

( ).

Scheme/Racket +, -, * .. , . .

+ , , . , define.

(define plus +) 

plus , +. ,

(define p +)

. - , .

+6