-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
288 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
; | ||
; Copyright (C) 2024 The Goldfish Scheme Authors | ||
; | ||
; Licensed under the Apache License, Version 2.0 (the "License"); | ||
; you may not use this file except in compliance with the License. | ||
; You may obtain a copy of the License at | ||
; | ||
; http://www.apache.org/licenses/LICENSE-2.0 | ||
; | ||
; Unless required by applicable law or agreed to in writing, software | ||
; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
; License for the specific language governing permissions and limitations | ||
; under the License. | ||
; | ||
|
||
(define-library (liii queue) | ||
(import (liii list) | ||
(liii base) | ||
(srfi srfi-9) | ||
(liii error)) | ||
(export | ||
queue | ||
queue? queue-empty? | ||
queue-size queue-front queue-back | ||
queue-pop! queue-push! | ||
queue->list) | ||
(begin | ||
|
||
(define-record-type :queue | ||
(make-queue data) | ||
queue? | ||
(data get-data set-data!)) | ||
|
||
(define (%queue-assert-type q) | ||
(when (not (queue? q)) | ||
(type-error "Parameter q is not a queue"))) | ||
|
||
(define (%queue-assert-value q) | ||
(when (queue-empty? q) | ||
(value-error "q must be non-empty"))) | ||
|
||
(define (queue . l) | ||
(if (null? l) | ||
(make-queue '()) | ||
(make-queue l))) | ||
|
||
(define (queue-empty? q) | ||
(%queue-assert-type q) | ||
(null? (get-data q))) | ||
|
||
(define (queue-size q) | ||
(%queue-assert-type q) | ||
(length (get-data q))) | ||
|
||
(define (queue-front q) | ||
(%queue-assert-type q) | ||
(%queue-assert-value q) | ||
(first (get-data q))) | ||
|
||
(define (queue-back q) | ||
(%queue-assert-type q) | ||
(%queue-assert-value q) | ||
(last (get-data q))) | ||
|
||
(define (queue-push! q x) | ||
(%queue-assert-type q) | ||
(let1 data (get-data q) | ||
(set-data! q (append data (list x))))) | ||
|
||
(define (queue-pop! q) | ||
(%queue-assert-type q) | ||
(%queue-assert-value q) | ||
(let1 data (get-data q) | ||
(set-data! q (cdr data)) | ||
(car data))) | ||
|
||
(define (queue->list q) | ||
(get-data q)) | ||
|
||
) ; end of begin | ||
) ; end of library | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,6 @@ | ||
; 0-clause BSD | ||
; Bill Schottstaedt | ||
; from S7 source repo: r7rs.scm | ||
|
||
(define-library (srfi srfi-9) | ||
(import (scheme base)) | ||
(export define-record-type) | ||
(begin | ||
|
||
(define-macro (define-record-type type make ? . fields) | ||
(let ((obj (gensym)) | ||
(typ (gensym)) ; this means each call on this macro makes a new type | ||
(args (map (lambda (field) | ||
(values (list 'quote (car field)) | ||
(let ((par (memq (car field) (cdr make)))) | ||
(and (pair? par) (car par))))) | ||
fields))) | ||
`(begin | ||
(define (,? ,obj) | ||
(and (let? ,obj) | ||
(eq? (let-ref ,obj ',typ) ',type))) | ||
|
||
(define ,make | ||
(inlet ',typ ',type ,@args)) | ||
|
||
,@(map | ||
(lambda (field) | ||
(when (pair? field) | ||
(if (null? (cdr field)) | ||
(values) | ||
(if (null? (cddr field)) | ||
`(define (,(cadr field) ,obj) | ||
(let-ref ,obj ',(car field))) | ||
`(begin | ||
(define (,(cadr field) ,obj) | ||
(let-ref ,obj ',(car field))) | ||
(define (,(caddr field) ,obj val) | ||
(let-set! ,obj ',(car field) val))))))) | ||
fields) | ||
',type))) | ||
|
||
) ; end of begin | ||
) ; end of define-library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.