unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* srfi-26
@ 2004-01-15  2:17 Alex Shinn
  2004-01-15  9:36 ` srfi-26 Daniel Skarda
  2004-01-15 22:08 ` srfi-26 Kevin Ryde
  0 siblings, 2 replies; 14+ messages in thread
From: Alex Shinn @ 2004-01-15  2:17 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 356 bytes --]

Below is the reference implementation for SRFI-26 from

  http://srfi.schemers.org/srfi-26/cut.scm

adapted to Guile and passing all tests from

  http://srfi.schemers.org/srfi-26/check.scm

The reference implementation is public domain, and in my infinite
generosity I place my three lines of module declaration in the public
domain as well :)

-- 
Alex


[-- Attachment #2: srfi-26.scm --]
[-- Type: application/octet-stream, Size: 4202 bytes --]

; REFERENCE IMPLEMENTATION FOR SRFI-26 "CUT"
; ==========================================
;
; Sebastian.Egner@philips.com, 5-Jun-2002.
; adapted from the posting by Al Petrofsky <al@petrofsky.org>
; placed in the public domain
;
; The code to handle the variable argument case was originally
; proposed by Michael Sperber and has been adapted to the new
; syntax of the macro using an explicit rest-slot symbol. The
; code to evaluate the non-slots for cute has been proposed by
; Dale Jordan. The code to allow a slot for the procedure position
; and to process the macro using an internal macro is based on 
; a suggestion by Al Petrofsky. The code found below is, with
; exception of this header and some changes in variable names,
; entirely written by Al Petrofsky.
;
; compliance:
;   Scheme R5RS (including macros).
;
; loading this file into Scheme 48 0.57:
;   ,load cut.scm
;
; history of this file:
;   SE,  6-Feb-2002: initial version as 'curry' with ". <>" notation
;   SE, 14-Feb-2002: revised for <...>
;   SE, 27-Feb-2002: revised for 'cut'
;   SE, 03-Jun-2002: revised for proc-slot, cute
;   SE, 04-Jun-2002: rewritten with internal transformer (no "loop" pattern)
;   SE, 05-Jun-2002: replace my code by Al's; substituted "constant" etc.
;     to match the convention in the SRFI-document

;; define guile module and export syntax
(define-module (srfi srfi-26)
  :use-module (ice-9 syncase)
  :export-syntax (cut cute srfi-26-internal-cut srfi-26-internal-cute))

(cond-expand-provide (current-module) '(srfi-26))

; (srfi-26-internal-cut slot-names combination . se)
;   transformer used internally
;     slot-names  : the internal names of the slots
;     combination : procedure being specialized, followed by its arguments
;     se          : slots-or-exprs, the qualifiers of the macro

(define-syntax srfi-26-internal-cut
  (syntax-rules (<> <...>)

    ;; construct fixed- or variable-arity procedure:
    ;;   (begin proc) throws an error if proc is not an <expression>
    ((srfi-26-internal-cut (slot-name ...) (proc arg ...))
     (lambda (slot-name ...) ((begin proc) arg ...)))
    ((srfi-26-internal-cut (slot-name ...) (proc arg ...) <...>)
     (lambda (slot-name ... . rest-slot) (apply proc arg ... rest-slot)))

    ;; process one slot-or-expr
    ((srfi-26-internal-cut (slot-name ...)   (position ...)      <>  . se)
     (srfi-26-internal-cut (slot-name ... x) (position ... x)        . se))
    ((srfi-26-internal-cut (slot-name ...)   (position ...)      nse . se)
     (srfi-26-internal-cut (slot-name ...)   (position ... nse)      . se))))

; (srfi-26-internal-cute slot-names nse-bindings combination . se)
;   transformer used internally
;     slot-names     : the internal names of the slots
;     nse-bindings   : let-style bindings for the non-slot expressions.
;     combination    : procedure being specialized, followed by its arguments
;     se             : slots-or-exprs, the qualifiers of the macro

(define-syntax srfi-26-internal-cute
  (syntax-rules (<> <...>)

    ;; If there are no slot-or-exprs to process, then:
    ;; construct a fixed-arity procedure,
    ((srfi-26-internal-cute
      (slot-name ...) nse-bindings (proc arg ...))
     (let nse-bindings (lambda (slot-name ...) (proc arg ...))))
    ;; or a variable-arity procedure
    ((srfi-26-internal-cute
      (slot-name ...) nse-bindings (proc arg ...) <...>)
     (let nse-bindings (lambda (slot-name ... . x) (apply proc arg ... x))))

    ;; otherwise, process one slot:
    ((srfi-26-internal-cute
      (slot-name ...)         nse-bindings  (position ...)   <>  . se)
     (srfi-26-internal-cute
      (slot-name ... x)       nse-bindings  (position ... x)     . se))
    ;; or one non-slot expression
    ((srfi-26-internal-cute
      slot-names              nse-bindings  (position ...)   nse . se)
     (srfi-26-internal-cute
      slot-names ((x nse) . nse-bindings) (position ... x)       . se))))

; exported syntax

(define-syntax cut
  (syntax-rules ()
    ((cut . slots-or-exprs)
     (srfi-26-internal-cut () () . slots-or-exprs))))

(define-syntax cute
  (syntax-rules ()
    ((cute . slots-or-exprs)
     (srfi-26-internal-cute () () () . slots-or-exprs))))

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2004-03-01 21:10 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-15  2:17 srfi-26 Alex Shinn
2004-01-15  9:36 ` srfi-26 Daniel Skarda
2004-01-21  0:44   ` srfi-26 Marius Vollmer
2004-01-23  0:44     ` srfi-26 Kevin Ryde
2004-01-24 10:22       ` srfi-26 Daniel Skarda
2004-02-28 20:15   ` srfi-26 Kevin Ryde
2004-02-29 10:04     ` srfi-26 Daniel Skarda
2004-03-01 21:10       ` srfi-26 Kevin Ryde
2004-01-15 22:08 ` srfi-26 Kevin Ryde
2004-01-16  3:28   ` srfi-26 Alex Shinn
2004-01-16  4:13     ` srfi-26 Paul Jarc
2004-01-16 18:53       ` srfi-26 Greg Troxel
2004-01-19  8:22         ` srfi-26 Alex Shinn
2004-01-19 16:43           ` srfi-26 Stephen Compall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).