fork download
  1.  
  2. ; This function will not change the value of x value.
  3. ; increment and decrement operators will change value of variable
  4.  
  5. ;Valdegg@ Solution
  6. (define (increment x)
  7. (+ 1 x)
  8. )
  9. ; defining a variable var with initial value 3
  10. (define var 3)
  11. (display (increment var)) (newline)
  12. (display var) (newline)
  13.  
  14. ;uselpa@ answer
  15. (define-syntax incf
  16. (syntax-rules ()
  17. ((_ x) (begin (set! x (+ x 1)) x))
  18. ((_ x n) (begin (set! x (+ x n)) x))))
  19.  
  20. (define-syntax decf
  21. (syntax-rules ()
  22. ((_ x) (incf x -1))
  23. ((_ x n) (incf x (- n)))))
  24.  
  25. (display (incf var)) (newline)
  26. (display var) (newline)
  27.  
Success #stdin #stdout 0s 7276KB
stdin
Standard input is empty
stdout
4
3
4
4