Skip to content

Commit

Permalink
rename vlen to vec-len
Browse files Browse the repository at this point in the history
... such that the name is consistent with `vec-ref` and `vec-set!` etc.
  • Loading branch information
Lu, Kuang-Chen committed Aug 31, 2022
1 parent fff99a6 commit 6cc3cf6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions fun/semantics.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
let let*
if and or not true false eq? equal?
begin
ivec vlen vec-ref
ivec vec-len vec-ref
pair left right pair?
+ - * /
zero?
Expand Down Expand Up @@ -77,17 +77,17 @@
(test/pred L (lambda (v) (not (equal~? v R))))]))

(define ivec vector-immutable)
(define vlen vector-length)
(define vec-len vector-length)
(define vec-ref vector-ref)

(define (pair a b)
(ivec a b))
(define (left p)
(unless (= (vlen p) 2)
(unless (= (vec-len p) 2)
(error 'left "argument must be a pair: ~a" p))
(vec-ref p 0))
(define (right p)
(unless (= (vlen p) 2)
(unless (= (vec-len p) 2)
(error 'right "argument must be a pair: ~a" p))
(vec-ref p 1))
(define (pair? v) (and (vector? v) (= (vlen v) 2)))
(define (pair? v) (and (vector? v) (= (vec-len v) 2)))
4 changes: 2 additions & 2 deletions scribblings/smol.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ exotic quoted forms. (If you don't know what these are, ignore them.)

@deftogether[(
@defproc[(ivec (elem Any) ...) Vec]
@defproc[(vlen (expr Vec)) Number]
@defproc[(vec-len (expr Vec)) Number]
@defproc[(vec-ref (vec-expr Vec) (idx-expr Number)) Any]
)]{
The @code{ivec} operation builds an @emph{immutable} vector of the
elements in @code{elem}. Vector elements need not be of the same
type. @code{vlen} computes its length, while @code{vec-ref} indexes
type. @code{vec-len} computes its length, while @code{vec-ref} indexes
into it (starting from @code{0}).
}

Expand Down
4 changes: 2 additions & 2 deletions state/semantics.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
(define (mpair a b)
(mvec a b))
(define (set-left! p v)
(unless (= (vlen p) 2)
(unless (= (vec-len p) 2)
(error 'set-left! "the first argument must be a pair: ~a" p))
(vector-set! p 0 v))
(define (set-right! p v)
(unless (= (vlen p) 2)
(unless (= (vec-len p) 2)
(error 'set-right! "the first argument must be a pair: ~a" p))
(vector-set! p 1 v))
2 changes: 1 addition & 1 deletion state/tests/all.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(test (left p) "x")
(test (right p) "y")

(test (vlen p) 2)
(test (vec-len p) 2)
(test (pair? p) true)
(test (pair? (mvec "g" "h")) true)

Expand Down

0 comments on commit 6cc3cf6

Please sign in to comment.