[Port `check-arg' from scsh cvs clinton@unknownlamer.org**20100328214034 Ignore-this: c0a200ca1c559be841026318f8189db6 ] addfile ./module/scsh/utilities.scm hunk ./module/scsh/utilities.scm 1 - +;;; Random useful utilities. +;;; Excerpted from SCSH +;;; Copyright (c) 1993 by Olin Shivers. + +(define-module (scsh utilities) + #:export (check-arg)) + +;;; From guile-scsh/loophole.scm +;;; Copyright (c) 1993, 1994 Richard Kelsey and Jonathan Rees. See file COPYING. +;;; original file: alt/loophole.scm. +(define-syntax loophole + (syntax-rules () + ((loophole ?type ?form) + (begin (lambda () ?type) ;Elicit unbound-variable warnings, etc. + ?form)))) + +;;; We loophole the call to ERROR -- the point is that perhaps the +;;; user will interact with a breakpoint, and proceed with a new +;;; value, which we will then pass to a new invocation of CHECK-ARG +;;; for approval. +(define (check-arg pred val caller) + (if (pred val) val + (check-arg pred + (loophole :value (error "Bad argument" val pred caller)) + caller)))