Changeset 40534 in project


Ignore:
Timestamp:
09/13/21 17:58:05 (12 days ago)
Author:
Kon Lovett
Message:

test make unique, some procedures are pure, add type for stack-literal-form, remove never-a-good-idea

Location:
release/5/stack/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • release/5/stack/trunk/stack.egg

    r39926 r40534  
    33
    44((synopsis "Provides LIFO queue (stack) operations")
    5  (version "3.0.7")
     5 (version "3.0.8")
    66 (category data)
    77 (author "Kon Lovett")
  • release/5/stack/trunk/stack.scm

    r39696 r40534  
    11;;;; stack.scm -*- Scheme -*-
     2;;;; Kon Lovett, Sep '21
    23;;;; Kon Lovett, May '17
    34;;;; Kon Lovett, Mar '09
     
    1011
    1112(declare
     13  #; ;never a good idea
    1214  (disable-interrupts)
    1315  (bound-to-procedure ##sys#signal-hook))
     
    8082(define-type stack (struct stack))
    8183
    82 (: make-stack (-> stack))
    83 (: list->stack (list -> stack))
    84 (: stack? (* -> boolean))
    85 (: stack-empty? (stack -> boolean))
    86 (: stack-count (stack -> fixnum))
    87 (: stack-peek (stack #!optional fixnum -> *))
     84(: make-stack (--> stack))
     85(: list->stack (list --> stack))
     86(: stack? (* -> boolean : stack))
     87(: stack-empty? (stack --> boolean))
     88(: stack-count (stack --> fixnum))
     89(: stack-peek (stack #!optional fixnum --> *))
    8890(: stack-empty! (stack -> void))
    8991(: stack-poke! (stack * #!optional fixnum -> void))
     
    9193(: stack-cut! (stack fixnum #!optional fixnum -> list))
    9294(: stack-pop! (stack -> *))
    93 (: stack->list (stack -> list))
     95(: stack->list (stack --> list))
    9496(: stack-fold (stack procedure * -> *))
    9597(: stack-map (stack procedure -> list))
    9698(: stack-for-each (stack procedure -> void))
     99(: stack-literal-form (#!optional symbol -> symbol))
    97100
    98101;; Stack Object
     
    190193(define (stack-count stk) (%stack-count (check-stack 'stack-count stk)))
    191194
    192 (define (stack-peek stk #!optional (idx 0)) (car (%stack-node-ref 'stack-peek (check-stack 'stack-peek stk) idx)))
     195(define (stack-peek stk #!optional (idx 0))
     196  (car (%stack-node-ref 'stack-peek (check-stack 'stack-peek stk) idx)))
    193197
    194198(define (stack-empty! stk) (%stack-empty! (check-stack 'stack-empty! stk)))
    195199
    196 (define (stack-poke! stk obj #!optional (idx 0)) (set-car! (%stack-node-ref 'stack-poke! (check-stack 'stack-poke! stk) idx) obj))
    197 
    198 (define (stack-push! stk #!rest ls) (unless (null? ls) (%stack-push! (check-stack 'stack-push! stk) ls)))
     200(define (stack-poke! stk obj #!optional (idx 0))
     201  (set-car! (%stack-node-ref 'stack-poke! (check-stack 'stack-poke! stk) idx) obj))
     202
     203(define (stack-push! stk #!rest ls)
     204  (unless (null? ls) (%stack-push! (check-stack 'stack-push! stk) ls)))
    199205
    200206(define (stack-cut! stk start #!optional (end (%stack-count stk)))
     
    232238(define (stack->list stk) (%list-copy (%stack-list (check-stack 'stack->list stk))))
    233239
    234 (define (stack-fold stk func init) (%list-fold func init (%stack-list (check-stack 'stack-fold stk))))
     240(define (stack-fold stk func init)
     241  (%list-fold func init (%stack-list (check-stack 'stack-fold stk))))
    235242
    236243(define (stack-map stk func) (map func (%stack-list (check-stack 'stack-map stk))))
    237244
    238 (define (stack-for-each stk proc) (for-each proc (%stack-list (check-stack 'stack-for-each stk))))
     245(define (stack-for-each stk proc)
     246  (for-each proc (%stack-list (check-stack 'stack-for-each stk))))
    239247
    240248;;; Read/Print Syntax
  • release/5/stack/trunk/tests/stack-test.scm

    r39694 r40534  
    1212(test-group "Empty Stack"
    1313  (test-assert (make-stack))
     14  (test-assert (not (eq? (make-stack) (make-stack))))
    1415  (test-assert (stack? (make-stack)))
    1516  (test-assert (stack-empty? (make-stack)))
Note: See TracChangeset for help on using the changeset viewer.