From 1de88dda3152ba162853a0784d2309be1aed6822 Mon Sep 17 00:00:00 2001 From: erana Date: Mon, 23 Jan 2012 16:20:19 +0900 Subject: [PATCH] scratch - char-continuation functions - 2 --- scsh/scratch/load.scm | 32 ++++++++++++++++++++++++++++++++ scsh/scratch/packages.scm | 2 +- scsh/scratch/pkg-def.scm | 1 + scsh/scratch/scratch.scm | 30 +++++++++++++++++++++++++++--- 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 scsh/scratch/load.scm diff --git a/scsh/scratch/load.scm b/scsh/scratch/load.scm new file mode 100644 index 0000000..04a2a18 --- /dev/null +++ b/scsh/scratch/load.scm @@ -0,0 +1,32 @@ +;;; scratch.scm - a scheme utility library +;;; +;;; Copyright (c) 2011-2012 Johan Ceuppens +;;; +;;; 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 authors may not be used to endorse or promote products +;;; derived from this software without specific prior written permission. +;;; +;;; THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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. + +;; ,open continuations +;;(define call-with-current-continuation call/cc) + +(load "scratch.scm") diff --git a/scsh/scratch/packages.scm b/scsh/scratch/packages.scm index aa3d72e..ee31928 100644 --- a/scsh/scratch/packages.scm +++ b/scsh/scratch/packages.scm @@ -5,4 +5,4 @@ (define-structure thttpd scratch-interface (open scheme) - (files scratch)) + (files load scratch)) diff --git a/scsh/scratch/pkg-def.scm b/scsh/scratch/pkg-def.scm index d8d38ff..83b71a7 100644 --- a/scsh/scratch/pkg-def.scm +++ b/scsh/scratch/pkg-def.scm @@ -8,4 +8,5 @@ (install-file "README" 'doc) (install-file "NEWS" 'doc) (install-string (COPYING) "COPYING" 'doc) + (install-string "load.scm" 'scheme) (install-file "scratch.scm" 'scheme)) diff --git a/scsh/scratch/scratch.scm b/scsh/scratch/scratch.scm index f94c1ed..c987a79 100644 --- a/scsh/scratch/scratch.scm +++ b/scsh/scratch/scratch.scm @@ -26,6 +26,8 @@ ;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF ;;; THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +;; ,open continuations +;;(define call-with-current-continuation call/cc) ;; inner syntax ;; test @@ -33,18 +35,18 @@ (define (list-generate-element lst) - (define (get-char return) + (define (get-el return) (for-each (lambda (element) (set! return (call-with-current-continutation (lambda (r) - (set! get-char r) + (set! get-el r) (return element))))) lst) (return 'end-generate)) (define (gen) - (call-with-current-continuation get-char)) + (call-with-current-continuation get-el)) gen) ;; outer syntax @@ -54,3 +56,25 @@ (syntax-rules () ((_ a ...) (list-generate-element (make-list a ...))))) + + +(define (vector-generate-element lst) + (define (get-el return) + (for-each + (lambda (element) + (set! return (call-with-current-continutation + (lambda (r) + (set! get-el r) + (return element))))) + (vector->list lst)) + (return 'end-generate)) + + (define (gen) + (call-with-current-continuation get-el)) + gen) + +(define-syntax vector-gen + (syntax-rules () + ((_ a ...) + (vector-generate-element (make-list a ...))))) +