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

* Re: srfi-26
  2004-01-15  2:17 srfi-26 Alex Shinn
@ 2004-01-15  9:36 ` Daniel Skarda
  2004-01-21  0:44   ` srfi-26 Marius Vollmer
  2004-02-28 20:15   ` srfi-26 Kevin Ryde
  2004-01-15 22:08 ` srfi-26 Kevin Ryde
  1 sibling, 2 replies; 14+ messages in thread
From: Daniel Skarda @ 2004-01-15  9:36 UTC (permalink / raw)
  Cc: guile-devel

Hello,

  srfi-26 and cut/cute are indeed cute macros. I sent my implementation to
guile-devel about fourteen months ago, but it seems nobody cared to commit
it to CVS (so I wish you good luck ;-)

0.

From: Daniel Skarda <0rfelyus@ucw.cz>
Subject: srfi-26 (cut, cute)
To: guile-devel@gnu.org, guile-user@gnu.org
Date: 03 Oct 2002 22:45:55 +0200

Hello,

  during summer I browsed through srfi specification and as an exercise I
implemented srfi-26 (curry-which-is-not-curry :-). I hope somebody with
write access to CVS will like it and commit it.

  I found cut and cute macros very handy (they usually safe you a lot of
boring typing and screen space :-) so maybe they should be also part of
ice-9/boot-9.scm.

Have a nice day,
0.

ps: The reference implementation uses define-syntax instead of define-macro.
I chose define-macro since I prefere this way of writing macros and
(use-modules (ice-9 syncase)) doubles guile startup time (at least on my comp).

;--- srfi/srfi-26.scm: ----------------------------------------------------------

(define-macro (cut slot . slots)
  (let loop ((slots	(cons slot slots))
	     (params	'())
	     (args	'()))
    (if (null? slots)
	`(lambda ,(reverse! params) ,(reverse! args))
      (let ((s	  (car slots))
	    (rest (cdr slots)))
	(case s
	  ((<>)
	   (let ((var (gensym)))
	     (loop rest (cons var params) (cons var args))))
	  ((<...>)
	   (if (pair? rest)
	       (error "<...> not on the end of cut expression"))
	   (let ((var (gensym)))
	     `(lambda ,(append! (reverse! params) var)
		(apply ,@(reverse! (cons var args))))))
	  (else
	   (loop rest params (cons s args))))))))

(define-macro (cute . slots)
  (let ((temp (map (lambda (s) (and (not (memq s '(<> <...>))) (gensym))) slots)))
    `(let ,(delq! #f (map (lambda (t s) (and t (list t s))) temp slots))
       (cut ,@(map (lambda (t s) (or t s)) temp slots)))))


_______________________________________________
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

* Re: srfi-26
  2004-01-15  2:17 srfi-26 Alex Shinn
  2004-01-15  9:36 ` srfi-26 Daniel Skarda
@ 2004-01-15 22:08 ` Kevin Ryde
  2004-01-16  3:28   ` srfi-26 Alex Shinn
  1 sibling, 1 reply; 14+ messages in thread
From: Kevin Ryde @ 2004-01-15 22:08 UTC (permalink / raw)
  Cc: guile-devel

Alex Shinn <foof@synthcode.com> writes:
>
> The reference implementation is public domain,

I think the gnu maintainer guide says you still need the author to
sign a disclaimer before incorporating it.


_______________________________________________
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

* Re: srfi-26
  2004-01-15 22:08 ` srfi-26 Kevin Ryde
@ 2004-01-16  3:28   ` Alex Shinn
  2004-01-16  4:13     ` srfi-26 Paul Jarc
  0 siblings, 1 reply; 14+ messages in thread
From: Alex Shinn @ 2004-01-16  3:28 UTC (permalink / raw)


At Fri, 16 Jan 2004 08:08:23 +1000, Kevin Ryde wrote:
> 
> Alex Shinn <foof@synthcode.com> writes:
> >
> > The reference implementation is public domain,
> 
> I think the gnu maintainer guide says you still need the author to
> sign a disclaimer before incorporating it.

For public domain work can't you just cut&paste it and then call
yourself the author?

Anyway, the guide says

  A change of just a few lines (less than 15 or so) is not legally
  significant for copyright.

and if you shorten the variable names and refactor cute in terms of cut
you can get it down to 14 lines:

(define-syntax %cut
  (syntax-rules (<> <...>)
    ((_ (slot ...) (f x ...)) (lambda (slot ...) ((begin f) x ...)))
    ((_ (slot ...) (f x ...) <...>) (lambda (slot ... . y) (apply f x ... y)))
    ((_ (slot ...) (pos ...) <> . se) (%cut (slot ... x) (pos ... x) . se))
    ((_ (slot ...) (pos ...) nse . se) (%cut (slot ...) (pos ... nse) . se))))
(define-syntax %cute
  (syntax-rules (<> <...>)
    ((_ (args ...)) (%cut () () args ...))
    ((_ (args ...) <...>) (%cut () () args ... <...>))
    ((_ (args ...) <> rest ...) (%cute (args ... <>) rest ...))
    ((_ (args ...) x rest ...) (let ((y x)) (%cute (args ... y) rest ...)))))
(define-syntax cut (syntax-rules () ((cut . x) (%cut () () . x))))
(define-syntax cute (syntax-rules () ((cute . x) (%cute () . x))))

-- 
Alex


_______________________________________________
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

* Re: srfi-26
  2004-01-16  3:28   ` srfi-26 Alex Shinn
@ 2004-01-16  4:13     ` Paul Jarc
  2004-01-16 18:53       ` srfi-26 Greg Troxel
  0 siblings, 1 reply; 14+ messages in thread
From: Paul Jarc @ 2004-01-16  4:13 UTC (permalink / raw)
  Cc: guile-devel

Alex Shinn <foof@synthcode.com> wrote:
> For public domain work can't you just cut&paste it and then call
> yourself the author?

The FSF wants legal documentation so they can prove that it is in the
public domain - just in case the author has second thoughts later, I
guess.


paul


_______________________________________________
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

* Re: srfi-26
  2004-01-16  4:13     ` srfi-26 Paul Jarc
@ 2004-01-16 18:53       ` Greg Troxel
  2004-01-19  8:22         ` srfi-26 Alex Shinn
  0 siblings, 1 reply; 14+ messages in thread
From: Greg Troxel @ 2004-01-16 18:53 UTC (permalink / raw)
  Cc: guile-devel

  From: prj@po.cwru.edu (Paul Jarc)

  The FSF wants legal documentation so they can prove that it is in the
  public domain - just in case the author has second thoughts later, I
  guess.

Or if the author's employer claims that something was a work for
hire.  That's the point of the employer-disclaimer, which is separate
conceptutally from the copyright assignment.  So for PD code this
still applies; it's arguably only really PD if the person who said so
was the copyright owner, so a signed statement from the author that
it's PD and from employer (anyone who might have a work-for-hire
claim) disclaiming copyright interest should do, at least
conceptually.

IANAL, TINLA, blah blah blah.



-- 
        Greg Troxel <gdt@ir.bbn.com>


_______________________________________________
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

* Re: srfi-26
  2004-01-16 18:53       ` srfi-26 Greg Troxel
@ 2004-01-19  8:22         ` Alex Shinn
  2004-01-19 16:43           ` srfi-26 Stephen Compall
  0 siblings, 1 reply; 14+ messages in thread
From: Alex Shinn @ 2004-01-19  8:22 UTC (permalink / raw)


At 16 Jan 2004 13:53:55 -0500, Greg Troxel wrote:
> 
> Or if the author's employer claims that something was a work for
> hire.  That's the point of the employer-disclaimer, which is separate
> conceptutally from the copyright assignment.  So for PD code this
> still applies; it's arguably only really PD if the person who said so
> was the copyright owner, so a signed statement from the author that
> it's PD and from employer (anyone who might have a work-for-hire
> claim) disclaiming copyright interest should do, at least
> conceptually.

I guess that makes sense, though it's really inconvenient for something
like the Scheme community which shares code so freely.

But how about the 14-line, not-significant-for-copyright version?  There
are only so many ways to implement cut without artificially using a
round-about technique... if you won't take that code, I'll write a
program to automatically generate every possible cut and post it to the
list, forever banning Guile from using SRFI-26! :P

-- 
Alex


_______________________________________________
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

* Re: srfi-26
  2004-01-19  8:22         ` srfi-26 Alex Shinn
@ 2004-01-19 16:43           ` Stephen Compall
  0 siblings, 0 replies; 14+ messages in thread
From: Stephen Compall @ 2004-01-19 16:43 UTC (permalink / raw)
  Cc: guile-devel

Alex Shinn <foof@synthcode.com> writes:

> But how about the 14-line, not-significant-for-copyright version?
> There are only so many ways to implement cut without artificially
> using a round-about technique... if you won't take that code, I'll
> write a program to automatically generate every possible cut and
> post it to the list, forever banning Guile from using SRFI-26! :P

I believe, however, that the output of a program may not be
copyrighted by the program's copyright holder, except for substantial
verbatim excerpts.  For example, the template used by flex is
copyrighted in the output, but the real generated bits are not
copyrighted.  Therefore, if you post this generating program, that
could be done.

Furthermore, copyright does not guarantee uniqueness.  From RMS's
speech, "Software Patents: Barriers to Innovation":

    Copyrights cover copying. If you write a novel that turns out to
    be word-for-word the same with Gone with the Wind and you can
    prove you never saw Gone with the Wind, that would be a defense to
    any accusation of copyright infringement.

:P

--
Stephen Compall or s11 or sirian

Charlie was a chemist,
But Charlie is no more.
For what he thought was H2O,
Was H2SO4.

asset supercomputer IDEA Medco BRLO Sundevil genetic Blowpipe EuroFed
JPL CID Ceridian Lon Horiuchi INS SDI


_______________________________________________
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

* Re: srfi-26
  2004-01-15  9:36 ` srfi-26 Daniel Skarda
@ 2004-01-21  0:44   ` Marius Vollmer
  2004-01-23  0:44     ` srfi-26 Kevin Ryde
  2004-02-28 20:15   ` srfi-26 Kevin Ryde
  1 sibling, 1 reply; 14+ messages in thread
From: Marius Vollmer @ 2004-01-21  0:44 UTC (permalink / raw)
  Cc: Alex Shinn, guile-devel

Daniel Skarda <0rfelyus@ucw.cz> writes:

>   srfi-26 and cut/cute are indeed cute macros. I sent my implementation to
> guile-devel about fourteen months ago, but it seems nobody cared to commit
> it to CVS (so I wish you good luck ;-)

Oops.  The archives say that we did accept it, but then obviously
nothing happened.

I prefer your implementation to the reference implementation,
actually.  It avoids, as you say, define-syntax which Guile still
isn't very good at; and we already have your papers!  So, if nobody
objects, I will include your version into CVS HEAD.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
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

* Re: srfi-26
  2004-01-21  0:44   ` srfi-26 Marius Vollmer
@ 2004-01-23  0:44     ` Kevin Ryde
  2004-01-24 10:22       ` srfi-26 Daniel Skarda
  0 siblings, 1 reply; 14+ messages in thread
From: Kevin Ryde @ 2004-01-23  0:44 UTC (permalink / raw)


Marius Vollmer <m.vollmer@ping.de> writes:
>
> I prefer your implementation to the reference implementation,
> actually.  It avoids, as you say, define-syntax which Guile still
> isn't very good at; and we already have your papers!  So, if nobody
> objects, I will include your version into CVS HEAD.

It'll be needing a copyright notice.  What years does it date from?


_______________________________________________
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

* Re: srfi-26
  2004-01-23  0:44     ` srfi-26 Kevin Ryde
@ 2004-01-24 10:22       ` Daniel Skarda
  0 siblings, 0 replies; 14+ messages in thread
From: Daniel Skarda @ 2004-01-24 10:22 UTC (permalink / raw)



Kevin Ryde <user42@zip.com.au> writes:
> It'll be needing a copyright notice.  What years does it date from?

  I wrote my cute cut implementation few days before I sent it to guile-devel.
September - October 2002, I guess.

0.


_______________________________________________
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

* Re: srfi-26
  2004-01-15  9:36 ` srfi-26 Daniel Skarda
  2004-01-21  0:44   ` srfi-26 Marius Vollmer
@ 2004-02-28 20:15   ` Kevin Ryde
  2004-02-29 10:04     ` srfi-26 Daniel Skarda
  1 sibling, 1 reply; 14+ messages in thread
From: Kevin Ryde @ 2004-02-28 20:15 UTC (permalink / raw)
  Cc: guile-devel

Daniel Skarda <0rfelyus@ucw.cz> writes:
>
> 	   (let ((var (gensym)))

Would make-symbol be a goer here, instead of gensym?


_______________________________________________
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

* Re: srfi-26
  2004-02-28 20:15   ` srfi-26 Kevin Ryde
@ 2004-02-29 10:04     ` Daniel Skarda
  2004-03-01 21:10       ` srfi-26 Kevin Ryde
  0 siblings, 1 reply; 14+ messages in thread
From: Daniel Skarda @ 2004-02-29 10:04 UTC (permalink / raw)



>> 	   (let ((var (gensym)))
>
> Would make-symbol be a goer here, instead of gensym?

  1) gensym is a standard (Common Lisp) for introducing new symbols in
     defmacros.
 
  2) I am not too familiar with Guile internals, I do not know too much
     about interned/uninterned symbols. I wrote cut/cute using Guile 1.6.
     AFAIR make-symbol was introduced in 1.7

  3) gensym is better for macro debugging (when you use macroexpand +
     pretty-print, #<uninterned symbol foo 807f810> is long and quite
     annoying to read) 

  4) Does make-symbol any significant performance improvement over plain
     gensyms?

0.



_______________________________________________
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

* Re: srfi-26
  2004-02-29 10:04     ` srfi-26 Daniel Skarda
@ 2004-03-01 21:10       ` Kevin Ryde
  0 siblings, 0 replies; 14+ messages in thread
From: Kevin Ryde @ 2004-03-01 21:10 UTC (permalink / raw)
  Cc: guile-devel

Daniel Skarda <0rfelyus@ucw.cz> writes:
>
>   4) Does make-symbol any significant performance improvement over plain
>      gensyms?

Guaranteed uniqueness, I believe, no matter what pathological nonsense
might surround it.


_______________________________________________
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).