splice1.scm 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. (define xa [3 4 5])
  2. (define oarr (object[] 5 4 3))
  3. (define l1 (list @xa 9 @xa))
  4. (format #t "l1: ~w~%" l1)
  5. ;; Output: l1: (3 4 5 9 3 4 5)
  6. (format #t "integer[]-1: ~w ~w~%" (integer[] 66 @oarr 9 @xa) 99)
  7. ;; Output: integer[]-1: [66 5 4 3 9 3 4 5] 99
  8. (format #t "int[]-2: ~w ~w~%" (int[] 66 @xa 9 @oarr) 99)
  9. ;; Output: int[]-2: [66 3 4 5 9 5 4 3] 99
  10. (format #t "sum-xa: ~w~%" (+ @xa))
  11. ;; Output: sum-xa: 12
  12. (format #t "sum-oarr: ~w~%" (+ @oarr))
  13. ;; Output: sum-oarr: 12
  14. (format #t "sum-xb: ~w~%" (+ 100 @xa @xa 13))
  15. ;; Output: sum-xb: 137
  16. ; Call static varargs method:
  17. (display (java.lang.String:format "<x: %s y: %s z: %s>" @oarr)) (newline)
  18. ;; Output: <x: 5 y: 4 z: 3>
  19. ;; Static varargs with non-matching splice:
  20. (define xoarr (object[] "<x: %s y: %s>" @oarr))
  21. (display (gnu.kawa.functions.Format:sprintfToString @xoarr)) (newline)
  22. ;; Output: <x: 5 y: 4>
  23. (define-private (fooz x y z)
  24. (list z y x))
  25. (define (bar x)
  26. (let ((v [4 x]))
  27. (vector (fooz @v 6) 123)))
  28. (format #t "~w~%" (bar 10))
  29. ;; Output: #((6 10 4) 123)
  30. (define (apply-mod x)
  31. (gnu.math.IntNum:modulo @x))
  32. (format #t "mod: ~w~%" (apply-mod [12 5]))
  33. ;; Output: mod: 2