Changeset 38029 in project


Ignore:
Timestamp:
12/23/19 06:23:43 (7 months ago)
Author:
Ivan Raikov
Message:

added elt-slice to yasos collections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/yasos/trunk/collections.scm

    r37736 r38029  
    44  (collection? random-access? empty? size gen-keys gen-elts do-elts
    55   do-keys do-items map-elts map-keys map-items for-each-key for-each-elt
    6    elt-ref elt-set! elt-take elt-drop reduce reduce* reduce-items
     6   elt-ref elt-set! elt-take elt-drop elt-slice reduce reduce* reduce-items
    77   reduce-items* sort! sort make-vector-generator list->generator
    88   vector->generator string->generator hash-table->generator
     
    5252;; elt-take
    5353;; elt-drop
    54 ;;
     54;; elt-slice
    5555
    5656 
     
    148148        (lambda (k) (hash-table-set! result k (hash-table-ref <collection> k)))
    149149        (list-drop keys n))
     150       result))
     151    (else
     152     (error "operation not supported: elt-take"))
     153    ))
     154 
     155 (define-operation (elt-slice <collection> m n);; random access collection
     156  ;; default behavior
     157   (cond                     
     158    ((vector? <collection>) (subvector <collection> m n))
     159    ((list?   <collection>) (list-take (list-drop  <collection> m) (- n m)))
     160    ((string? <collection>) (substring  <collection> m n))
     161    ((hash-table? <collection>)
     162     (let ((keys (hash-table-keys <collection>))
     163           (result (make-hash-table)))
     164       (for-each
     165        (lambda (k) (hash-table-set! result k (hash-table-ref <collection> k)))
     166        (list-take (list-drop keys m) (- n m)))
    150167       result))
    151168    (else
Note: See TracChangeset for help on using the changeset viewer.