Skip to content

Commit

Permalink
Updates on R7RS library and SRFI 1
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Aug 1, 2024
1 parent cbc6613 commit 441af34
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.xmake/
build/
bin/
bin/goldfish
goldfish/**/*-test.scm
17 changes: 17 additions & 0 deletions goldfish/scheme/base.scm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
square
; String
string-copy
; Vector
vector->string
string->vector
; Input and Output
call-with-port port? binary-port? textual-port?
input-port-open? output-port-open?
Expand All @@ -42,6 +45,20 @@
(substring str (car start_end) (cadr start_end)))
(else (error 'wrong-number-of-args))))

; 0-clause BSD
; Bill Schottstaedt
; from S7 source repo: r7rs.scm
(define* (vector->string v (start 0) end)
(let ((stop (or end (length v))))
(copy v (make-string (- stop start)) start stop)))

; 0-clause BSD
; Bill Schottstaedt
; from S7 source repo: r7rs.scm
(define* (string->vector s (start 0) end)
(let ((stop (or end (length s))))
(copy s (make-vector (- stop start)) start stop)))

(define (string-map p . args) (apply string (apply map p args)))

(define (vector-map p . args) (apply vector (apply map p args)))
Expand Down
10 changes: 9 additions & 1 deletion goldfish/srfi/srfi-1.scm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
take drop take-right drop-right count fold fold-right
reduce reduce-right filter partition remove find
delete delete-duplicates
take-while drop-while)
take-while drop-while
last-pair last)
(begin

; 0 clause BSD, from S7 repo stuff.scm
Expand Down Expand Up @@ -95,6 +96,13 @@
(cons (car lag) (recur (cdr lag) (cdr lead)))
'())))

(define (last-pair l)
(if (pair? (cdr l))
(last-pair (cdr l)) l))

(define (last l)
(car (last-pair l)))

(define (count pred list1 . lists)
(let lp ((lis list1) (i 0))
(if (null-list? lis) i
Expand Down

0 comments on commit 441af34

Please sign in to comment.