| 1 |
;; Copyright (C) Marc Nieper-Wißkirchen (2021). All Rights Reserved. |
| 2 |
|
| 3 |
;; Permission is hereby granted, free of charge, to any person |
| 4 |
;; obtaining a copy of this software and associated documentation |
| 5 |
;; files (the "Software"), to deal in the Software without |
| 6 |
;; restriction, including without limitation the rights to use, copy, |
| 7 |
;; modify, merge, publish, distribute, sublicense, and/or sell copies |
| 8 |
;; of the Software, and to permit persons to whom the Software is |
| 9 |
;; furnished to do so, subject to the following conditions: |
| 10 |
|
| 11 |
;; The above copyright notice and this permission notice shall be |
| 12 |
;; included in all copies or substantial portions of the Software. |
| 13 |
|
| 14 |
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 |
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 |
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 17 |
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 18 |
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 19 |
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 20 |
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 |
;; SOFTWARE. |
| 22 |
|
| 23 |
(import (scheme base) |
| 24 |
(srfi 64) |
| 25 |
(srfi 229)) |
| 26 |
|
| 27 |
(test-begin "Tagged Procedures") |
| 28 |
|
| 29 |
(define f |
| 30 |
(lambda/tag 42 |
| 31 |
(x) |
| 32 |
(* x x))) |
| 33 |
|
| 34 |
(test-eqv #t (procedure/tag? f)) |
| 35 |
(test-eqv 9 (f 3)) |
| 36 |
(test-eqv 42 (procedure-tag f)) |
| 37 |
|
| 38 |
(define f* |
| 39 |
(lambda/tag 43 |
| 40 |
(x) |
| 41 |
(* x x))) |
| 42 |
|
| 43 |
(test-eqv #f (eqv? f f*)) |
| 44 |
|
| 45 |
(define g |
| 46 |
(let ((y 10)) |
| 47 |
(lambda/tag y () |
| 48 |
(set! y (+ y 1)) |
| 49 |
y))) |
| 50 |
|
| 51 |
(test-eqv 10 (procedure-tag g)) |
| 52 |
(test-eqv 10 (let ((y 9)) (procedure-tag g))) |
| 53 |
(test-eqv 11 (g)) |
| 54 |
(test-eqv 10 (procedure-tag g)) |
| 55 |
|
| 56 |
(define h |
| 57 |
(let ((box (vector #f))) |
| 58 |
(case-lambda/tag box |
| 59 |
(() (vector-ref box 0)) |
| 60 |
((val) (vector-set! box 0 val))))) |
| 61 |
|
| 62 |
(h 1) |
| 63 |
(test-eqv 1 (vector-ref (procedure-tag h) 0)) |
| 64 |
(test-eqv 1 (h)) |
| 65 |
|
| 66 |
(test-end) |