sandbox.scm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ; -*- mode: scheme; coding: utf-8 -*-
  2. ; (c) Daniel Llorens - 2016-2017
  3. ; This library is free software; you can redistribute it and/or modify it under
  4. ; the terms of the GNU General Public License as published by the Free
  5. ; Software Foundation; either version 3 of the License, or (at your option) any
  6. ; later version.
  7. ; Trying things.
  8. (import (newra newra) (newra tools) (rnrs io ports)
  9. (srfi :8) (srfi :26) (ice-9 match) (only (srfi :1) fold)
  10. (only (rnrs base) vector-map))
  11. ; -----------------------
  12. ; can't remember
  13. ; -----------------------
  14. (define ra0 (array->ra #(1 2 3)))
  15. (define ra1 (array->ra #@1(1 2 3)))
  16. (define ra2 (array->ra #2((1 2) (3 4))))
  17. (define ra3 (array->ra #2@1@1((1 2) (3 4))))
  18. (define ra4 (array->ra #3@1@1@-1(((1 2 3) (3 4 5)) ((4 5 6) (6 7 8)))))
  19. (define ra5 (array->ra #0(99)))
  20. (define v #(1 2 3 4))
  21. (define (vector->list-forward v)
  22. (case (vector-length v)
  23. ((0) '())
  24. ((1) (list (vector-ref v 0)))
  25. (else
  26. (let ((first (list (vector-ref v 0))))
  27. (let loop ((last first) (i 1))
  28. (if (= i (vector-length v))
  29. first
  30. (let ((next (list (vector-ref v i))))
  31. (set-cdr! last next)
  32. (loop next (+ i 1)))))))))
  33. ,m (newra newra)
  34. ; call macro with PARAM according to values OPT of TAG
  35. (define-syntax %tag-dispatch
  36. (syntax-rules ()
  37. ((_ tag macro (opt ...) (param ...) args ...)
  38. (case tag ((opt) (macro param args ...)) ... (else (throw 'bad-tag tag))))))
  39. (%tag-dispatch 'TWO display (ONE TWO) ('one 'two))
  40. ; -----------------------
  41. ; generalized selector
  42. ; -----------------------
  43. ; ...
  44. ; -----------------------
  45. ; define-inlinable-case-lambda
  46. ; -----------------------
  47. (import (newra newra) (newra tools) (rnrs io ports)
  48. (srfi :8) (srfi :26) (ice-9 match) (only (srfi :1) fold)
  49. (only (rnrs base) vector-map))
  50. ; -----------------------
  51. ; fold
  52. ; -----------------------
  53. ...
  54. (ra-fold (lambda (a knil) (cons a knil)) '() (ra-iota 3))
  55. ; think I need to extend %op-loop if I want to do this without set!
  56. (let-syntax
  57. ((%fold
  58. (lambda (stx)
  59. (syntax-case stx ()
  60. ((_ op)
  61. (lambda (stx)
  62. (syntax-rules ()
  63. ((_ (a b c) ...)
  64. #,(#'op (list a b c) ...)))))))))
  65. ((%fold list) (1 2 3) (4 5 6)))
  66. (let-syntax
  67. ((%fold
  68. (lambda (stx)
  69. (syntax-case stx ()
  70. ((_ op) #'op)))))
  71. (%fold list))