chickadee » srfi-145

srfi-145

Introduction

This egg provides an implementation of SRFI-145.

Author

Vasilij Schneidermann

Repository

https://depp.brause.cc/srfi-145

API

assume

(assume OBJ MESSAGE ...)syntax

Evaluates to the value of OBJ if OBJ evaluates to a true value. It is an error if OBJ evaluates to a false value. In this case the error is reported with the remaining MESSAGE arguments and if possible, including the source location of the source of the error.

(assume OBJ MESSAGE ...) expands to (assert OBJ MESSAGE ...). Therefore the assume form may be optimized away if OBJ is guaranteed to evaluate to a true value and is always elided in unsafe mode. For this reason it is not to be used as a replacement for error or type checking, but as a development tool to document assumptions made about code.

Examples

(import scheme)
(import (chicken base))
(import (srfi 145))

;; adapted from list-utils egg
(define (list-copy* ls #!optional (start 0) (end (length ls)) (fill (void)))
  (unless (<= start end)
    (error 'list-copy* "start > end" start end))
  (let* ((tot (- end start))
         (end (min end (length ls)))
         (len (- end start))
         (ls (take (drop ls start) len)))
    (assume (<= tot len) "Sublist length exceeds list length" tot len)
    (append! ls (make-list (- tot len) fill))))

;; adapted from https://www.upyum.com/cgit.cgi/ensemble/tree/backend/matrix/data.scm#n72
(define (timeline-cons event timeline)
  (assume (timeline-event? event) "Not a timeline event" event)
  (assume (or (not (hole-event? event))
              (null? timeline)
              (checkpoint-event? (car timeline)))
          "Hole event doesn't follow checkpoint event" event)
  (cons event timeline))

License

Copyright (c) 2020, Vasilij Schneidermann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Version history

0.1

Contents »