Skip to content

Commit

Permalink
Add license notation to procedures and syntaxes copied from Chibi-Scheme
Browse files Browse the repository at this point in the history
Signed-off-by: yamacir-kit <[email protected]>
  • Loading branch information
yamacir-kit committed Sep 19, 2023
1 parent b37d0a7 commit f5c5d2b
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 69 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Subset of R7RS-small.
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make package
sudo apt install build/meevax_0.4.806_amd64.deb
sudo apt install build/meevax_0.4.807_amd64.deb
```

or
Expand Down Expand Up @@ -106,9 +106,9 @@ sudo rm -rf /usr/local/share/meevax

| Target Name | Description
|-------------|-------------
| `all` | Build shared-library `libmeevax.0.4.806.so` and executable `meevax`
| `all` | Build shared-library `libmeevax.0.4.807.so` and executable `meevax`
| `test` | Test executable `meevax`
| `package` | Generate debian package `meevax_0.4.806_amd64.deb`
| `package` | Generate debian package `meevax_0.4.807_amd64.deb`
| `install` | Copy files into `/usr/local` directly

## Usage
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.806
0.4.807
102 changes: 68 additions & 34 deletions basis/r4rs-essential.ss
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,43 @@
close-output-port read read-char peek-char eof-object? write display
newline write-char load)

(begin (define (list . xs) xs)

(define-syntax cond
#|
This library contains many procedure and syntax definitions copied from
Chibi-Scheme's script lib/init-7.scm. The definitions marked
"Chibi-Scheme" in this file are those. Such definitions are subject to the
following Chibi-Scheme license.

---

Copyright (c) 2009-2021 Alex Shinn
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|#

(begin (define (list . xs) xs) ; Chibi-Scheme

(define-syntax cond ; Chibi-Scheme
(er-macro-transformer
(lambda (form rename compare)
(if (null? (cdr form))
Expand All @@ -69,7 +103,7 @@
(cons (rename 'cond) (cddr form))))))
(cadr form))))))

(define-syntax and
(define-syntax and ; Chibi-Scheme
(er-macro-transformer
(lambda (form rename compare)
(cond ((null? (cdr form)))
Expand All @@ -81,7 +115,7 @@
(cddr form))
#f))))))

(define-syntax or
(define-syntax or ; Chibi-Scheme
(er-macro-transformer
(lambda (form rename compare)
(cond ((null? (cdr form)) #f)
Expand All @@ -96,7 +130,7 @@
(cddr form))))
(cadr form)))))))

(define-syntax quasiquote
(define-syntax quasiquote ; Chibi-Scheme
(er-macro-transformer
(lambda (form rename compare)
(define (expand x depth)
Expand Down Expand Up @@ -145,7 +179,7 @@
(every f (cdr xs)))
#t))

(define (map f x . xs)
(define (map f x . xs) ; Chibi-Scheme
(define (map f x a)
(if (pair? x)
(map f
Expand All @@ -162,7 +196,7 @@
(map f x '())
(map* f (cons x xs) '())))

(define (apply f x . xs)
(define (apply f x . xs) ; Chibi-Scheme
(letrec ((apply (lambda (f xs)
(f . xs))))
(if (null? xs)
Expand All @@ -172,7 +206,7 @@
(car xs))))
(reverse (cons x xs))))))

(define-syntax let ; named-let inessential
(define-syntax let
(er-macro-transformer
(lambda (form rename compare)
(if (identifier? (cadr form))
Expand Down Expand Up @@ -202,7 +236,7 @@
(null? x)))
(null? x))))

(define (member o x . c)
(define (member o x . c) ; Chibi-Scheme
(let ((compare (if (pair? c) (car c) equal?)))
(let member ((x x))
(and (pair? x)
Expand All @@ -212,7 +246,7 @@
(define (memv o x)
(member o x eqv?))

(define-syntax case
(define-syntax case ; Chibi-Scheme
(er-macro-transformer
(lambda (form rename compare)
(define (body xs)
Expand All @@ -237,7 +271,7 @@
`(,(rename 'let) ((,(rename 'result) ,(cadr form)))
,(each-clause (cddr form))))))

(define (assoc key alist . compare)
(define (assoc key alist . compare) ; Chibi-Scheme
(let ((compare (if (pair? compare)
(car compare)
equal?)))
Expand Down Expand Up @@ -285,7 +319,7 @@
(define (even? n)
(= (remainder n 2) 0))

(define (max x . xs)
(define (max x . xs) ; Chibi-Scheme
(define (max-aux x xs)
(if (null? xs)
(inexact x)
Expand All @@ -299,7 +333,7 @@
(else (rec (if (< x (car xs)) (car xs) x)
(cdr xs)))))))

(define (min x . xs)
(define (min x . xs) ; Chibi-Scheme
(define (min-aux x xs)
(if (null? xs)
(inexact x)
Expand All @@ -321,7 +355,7 @@
(define (modulo x y)
(% (+ y (% x y)) y))

(define (gcd . xs)
(define (gcd . xs) ; Chibi-Scheme
(define (gcd-2 a b)
(if (zero? b)
(abs a)
Expand All @@ -332,7 +366,7 @@
(if (null? ns) n
(rec (gcd-2 n (car ns)) (cdr ns))))))

(define (lcm . xs)
(define (lcm . xs) ; Chibi-Scheme
(define (lcm-2 a b)
(abs (quotient (* a b) (gcd a b))))
(if (null? xs) 1
Expand All @@ -341,7 +375,7 @@
(if (null? ns) n
(rec (lcm-2 n (car ns)) (cdr ns))))))

(define (char-compare x xs compare)
(define (char-compare x xs compare) ; Chibi-Scheme
(let rec ((compare compare)
(lhs (char->integer x))
(xs xs))
Expand All @@ -350,22 +384,22 @@
(and (compare lhs rhs)
(rec compare rhs (cdr xs)))))))

(define (char=? x . xs)
(define (char=? x . xs) ; Chibi-Scheme
(char-compare x xs =))

(define (char<? x . xs)
(define (char<? x . xs) ; Chibi-Scheme
(char-compare x xs <))

(define (char>? x . xs)
(define (char>? x . xs) ; Chibi-Scheme
(char-compare x xs >))

(define (char<=? x . xs)
(define (char<=? x . xs) ; Chibi-Scheme
(char-compare x xs <=))

(define (char>=? x . xs)
(define (char>=? x . xs) ; Chibi-Scheme
(char-compare x xs >=))

(define (char-ci-compare x xs compare)
(define (char-ci-compare x xs compare) ; Chibi-Scheme
(let rec ((compare compare)
(lhs (char->integer (char-downcase x)))
(xs xs))
Expand All @@ -374,30 +408,30 @@
(and (compare lhs rhs)
(rec compare rhs (cdr xs)))))))

(define (char-ci=? x . xs)
(define (char-ci=? x . xs) ; Chibi-Scheme
(char-ci-compare x xs =))

(define (char-ci<? x . xs)
(define (char-ci<? x . xs) ; Chibi-Scheme
(char-ci-compare x xs <))

(define (char-ci>? x . xs)
(define (char-ci>? x . xs) ; Chibi-Scheme
(char-ci-compare x xs >))

(define (char-ci<=? x . xs)
(define (char-ci<=? x . xs) ; Chibi-Scheme
(char-ci-compare x xs <=))

(define (char-ci>=? x . xs)
(define (char-ci>=? x . xs) ; Chibi-Scheme
(char-ci-compare x xs >=))

(define (string . xs)
(define (string . xs) ; Chibi-Scheme
(list->string xs))

(define (string-map f x . xs) ; r7rs
(define (string-map f x . xs) ; R7RS
(if (null? xs)
(list->string (map f (string->list x)))
(list->string (apply map f (map string->list (cons x xs))))))

(define (string-foldcase s) ; r7rs
(define (string-foldcase s) ; R7RS
(string-map char-downcase s))

(define (string-ci=? . xs)
Expand All @@ -422,7 +456,7 @@
(continuation? x)
(foreign-function? x)))

(define (for-each f x . xs)
(define (for-each f x . xs) ; Chibi-Scheme
(if (null? xs)
(letrec ((for-each (lambda (f x)
(if (pair? x)
Expand All @@ -432,14 +466,14 @@
(begin (apply map f x xs)
(if #f #f))))

(define (call-with-input-file path f) ; r7rs incompatible (values unsupported)
(define (call-with-input-file path f) ; R7RS incompatible (values unsupported)
(define (call-with-input-port port f)
(let ((result (f port)))
(close-input-port port)
result))
(call-with-input-port (open-input-file path) f))

(define (call-with-output-file path f) ; r7rs incompatible (values unsupported)
(define (call-with-output-file path f) ; R7RS incompatible (values unsupported)
(define (call-with-output-port port f)
(let ((result (f port)))
(close-output-port port)
Expand Down
52 changes: 43 additions & 9 deletions basis/r4rs.ss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@
close-output-port read read-char peek-char eof-object? char-ready?
write display newline write-char load)

#|
This library contains many procedure and syntax definitions copied from
Chibi-Scheme's script lib/init-7.scm. The definitions marked
"Chibi-Scheme" in this file are those. Such definitions are subject to the
following Chibi-Scheme license.

---

Copyright (c) 2009-2021 Alex Shinn
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|#

(begin (define-syntax let*
(er-macro-transformer
(lambda (form rename compare)
Expand All @@ -50,7 +84,7 @@
(,(rename 'let*) ,(cdadr form)
,@(cddr form)))))))

(define-syntax do
(define-syntax do ; Chibi-Scheme
(er-macro-transformer
(lambda (form rename compare)
(let ((body `(,(rename 'begin) ,@(cdddr form)
Expand All @@ -72,18 +106,18 @@
(,(rename 'begin) ,@(cdaddr form))
,body)))))))

(define (numerator x)
(define (numerator x) ; Chibi-Scheme
(cond ((ratio? x) (ratio-numerator x))
((exact? x) x)
(else (inexact (numerator (exact x))))))

(define (denominator x)
(define (denominator x) ; Chibi-Scheme
(cond ((ratio? x) (ratio-denominator x))
((exact? x) 1)
((integer? x) 1.0)
(else (inexact (denominator (exact x))))))

(define (rationalize x e) ; from Chibi-Scheme lib/scheme/extras.scm (https://ml.cddddr.org/scheme/msg01498.html)
(define (rationalize x e) ; Chibi-Scheme lib/scheme/extras.scm (https://ml.cddddr.org/scheme/msg01498.html)
(define (simplest-rational x y return)
(let ((fx (floor x))
(fy (floor y)))
Expand All @@ -103,10 +137,10 @@
(e (abs e)))
(simplest-rational (- x e) (+ x e) return)))

(define (make-rectangular x y)
(define (make-rectangular x y) ; Chibi-Scheme
(+ x (* y (sqrt -1))))

(define (make-polar radius phi)
(define (make-polar radius phi) ; Chibi-Scheme
(make-rectangular (* radius (cos phi))
(* radius (sin phi))))

Expand All @@ -116,15 +150,15 @@
(define (imag-part z)
(if (imaginary? z) (cdr z) 0))

(define (magnitude z)
(define (magnitude z) ; Chibi-Scheme
(sqrt (+ (square (real-part z))
(square (imag-part z)))))

(define (angle z)
(define (angle z) ; Chibi-Scheme
(atan (imag-part z)
(real-part z)))

(define (string-fill! s c . o)
(define (string-fill! s c . o) ; Chibi-Scheme
(let ((start (if (and (pair? o)
(exact-integer? (car o)))
(car o)
Expand Down
Loading

0 comments on commit f5c5d2b

Please sign in to comment.