From af2c85b9a409e086dbef11a41993ca0d4a5219a8 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Tue, 28 Jul 2015 22:16:11 -0400 Subject: [PATCH] Added string/vector functions --- docs/Features.md | 6 +++--- scheme/base.sld | 11 ++++++----- scheme/char.sld | 7 ++++++- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/Features.md b/docs/Features.md index 7b27c959..9414b1c8 100644 --- a/docs/Features.md +++ b/docs/Features.md @@ -32,10 +32,10 @@ Section | Status | Comments 6.4 Pairs and lists | Yes | `member` functions are predicates, `member` and `assoc` do not accept `compare` argument. 6.5 Symbols | Yes | 6.6 Characters | Partial | No unicode support, `char-ci` predicates are not implemented. -6.7 Strings | Partial | Many functions are missing. Need to sync up with r7rs. +6.7 Strings | Partial | No unicode support, `string-ci` functions are not implemented. 6.8 Vectors | Yes | -6.9 Bytevectors | | -6.10 Control features | | +6.9 Bytevectors | | Not supported yet. +6.10 Control features | | The `map` functions only support one "data" argument - for example, `string-map` only accepts one string. 6.11 Exceptions | Partial | Need to check against r7rs 6.12 Environments and evaluation | Partial | 6.13 Input and output | | diff --git a/scheme/base.sld b/scheme/base.sld index d45d5fe9..84fdfd4a 100644 --- a/scheme/base.sld +++ b/scheme/base.sld @@ -47,6 +47,7 @@ vector-fill! vector->list vector->string + vector-map make-string string string-copy @@ -54,10 +55,7 @@ string-fill! string->list string->vector - ; TODO: - ;string-upcase - ;string-downcase - ;string-foldcase + string-map make-parameter current-output-port current-input-port @@ -224,7 +222,6 @@ (define (vector->string vec . opts) (let ((lst (apply vector->list (cons vec opts)))) (list->string lst))) - ;; TODO: change to string->list (define (string->list str . opts) (letrec ((len (string-length str)) (start (if (> (length opts) 0) (car opts) 0)) @@ -267,6 +264,10 @@ (string-set! str i fill) (loop (+ i 1))))))) (loop start))) + (define (string-map func str) + (list->string (map func (string->list str)))) + (define (vector-map func vec) + (list->vector (map func (vector->list vec)))) (define (vector-append . vecs) (list->vector (apply append (map vector->list vecs)))) diff --git a/scheme/char.sld b/scheme/char.sld index b71be509..f336e4c8 100644 --- a/scheme/char.sld +++ b/scheme/char.sld @@ -8,6 +8,10 @@ char-upper-case? char-whitespace? digit-value + string-upcase + string-downcase + ; TODO: + ;string-foldcase ) (import (scheme base)) (begin @@ -35,5 +39,6 @@ (if (char-numeric? c) (- (char->integer c) (char->integer #\0)) #f)) - + (define (string-upcase str) (string-map char-upcase str)) + (define (string-downcase str) (string-map char-downcase str)) ))