unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* ANN: fectors v0.1
@ 2012-07-08  1:16 Ian Price
  2012-07-08  6:27 ` Marco Maggi
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Price @ 2012-07-08  1:16 UTC (permalink / raw)
  To: guile-user; +Cc: vicare-users


Hi folks,

Just a quick note to mention an implementation of persistent
(i.e. functional) vectors I wrote in celebration of the guile 2.0.6
release. It is written in portable R6RS, and tested on guile.

The code can be found at https://github.com/ijp/fectors

It's a pretty short and simple module, and I hope it proves useful.

I will note, however, that the library is not thread safe. It uses
internal mutation to provide efficient access to the most recently used
version of a fector. If this is a problem for you, or you are frequently
using branches other than the most frequent, I also have an
implementation of functional sequences based on fingertrees in my pfds
library, on the fingertrees branch. See
https://github.com/ijp/pfds/tree/fingertrees

Cheers,

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



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

* Re: ANN: fectors v0.1
  2012-07-08  1:16 ANN: fectors v0.1 Ian Price
@ 2012-07-08  6:27 ` Marco Maggi
  2012-07-08 10:26   ` Ian Price
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Maggi @ 2012-07-08  6:27 UTC (permalink / raw)
  To: Ian Price; +Cc: guile-user, vicare-users

Ian Price wrote:
> Just  a  quick  note   to  mention  an  implementation  of
> persistent   (i.e.   functional)   vectors  I   wrote   in
> celebration of the  guile 2.0.6 release. It  is written in
> portable R6RS, and tested on guile.

I  can  confirm  that  it works  with  Vicare  Scheme.   The
following  is a  test  file  for Vicare,  just  place it  in
fectors' source directory and do:

   $ vicare -L $PWD test-vicare.sps

;;; test-vicare.sps --- Functional Vectors: tests with Vicare Scheme

;; Copyright (C) 2012 Marco Maggi <marco.maggi-ipsu@poste.it>

;; Author: Marco Maggi <marco.maggi-ipsu@poste.it>

;; This program is free software, you can redistribute it and/or
;; modify it under the terms of the new-style BSD license.

;; You should have received a copy of the BSD license along with this
;; program. If not, see <http://www.debian.org/misc/bsd.license>.

#!r6rs
(import (rnrs)
  (fectors)
  (vicare checks))

(check-set-mode! 'report-failed)

\f
;;;; helpers

(define fector=?
  (case-lambda
   ((obj1 obj2)
    (fector=? obj1 obj2 eqv?))
   ((obj1 obj2 item=)
    (and (fector? obj1)
	 (fector? obj2)
	 (or (eq? obj1 obj2)
	     (let ((len1 (fector-length obj1)))
	       (and (= len1 (fector-length obj2))
		    (let loop ((i 0))
		      (or (= i len1)
			  (and (item= (fector-ref obj1 i)
				      (fector-ref obj2 i))
			       (loop (+ 1 i))))))))))))

\f
;;;; building fectors

(check
    (let ((F (make-fector 5)))
      (and (fector? F)
	   (fector->list F)))
  => '(0 0 0 0 0))

(check
    (let ((F (make-fector 5 #\a)))
      (and (fector? F)
	   (fector->list F)))
  => '(#\a #\a #\a #\a #\a))

(check
    (let ((F (fector 1 2 3)))
      (and (fector? F)
	   (fector->list F)))
  => '(1 2 3))

(check
    (let ((F (build-fector 5 (lambda (idx) (* 10 idx)))))
      (and (fector? F)
	   (fector->list F)))
  => '(0 10 20 30 40))

\f
;;;; inspecting

(check
    (let ((F (fector)))
      (fector-length F))
  => 0)

(check
    (let ((F (fector 1)))
      (fector-length F))
  => 1)

(check
    (let ((F (fector 1 2 3)))
      (fector-length F))
  => 3)

\f
;;;; accessing and mutating

(check
    (let ((F (fector 1 2 3)))
      (list (fector-ref F 0)
	    (fector-ref F 1)
	    (fector-ref F 2)))
  => '(1 2 3))

(check
    (let* ((F (fector 1 2 3))
	   (F (fector-set F 0 'a))
	   (F (fector-set F 1 'b))
	   (F (fector-set F 2 'c)))
      (list (fector-ref F 0)
	    (fector-ref F 1)
	    (fector-ref F 2)))
  => '(a b c))

\f
;;;; comparison

(check
    (let ((F (fector 1 2 3))
	  (G (fector 1 2 3)))
      (fector=? F G))
  => #t)

(check
    (let ((F (fector 1 2 3))
	  (G (fector 10 2 3)))
      (fector=? F G))
  => #f)

(check
    (let ((F (fector 1 2 3))
	  (G (fector 1 20 3)))
      (fector=? F G))
  => #f)

(check
    (let ((F (fector 1 2 3))
	  (G (fector 1 2 30)))
      (fector=? F G))
  => #f)

;;; --------------------------------------------------------------------

(check
    (let ((F (fector 1 2 3))
	  (G (fector 1 2 3 4)))
      (fector=? F G))
  => #f)

(check
    (let ((F (fector 1 2 3 4))
	  (G (fector 1 2 3)))
      (fector=? F G))
  => #f)

(check
    (let ((F (fector))
	  (G (fector 1 2 3)))
      (fector=? F G))
  => #f)

(check
    (let ((F (fector 1 2 3))
	  (G (fector)))
      (fector=? F G))
  => #f)

\f
;;;; conversion

(check
    (let ((F (fector 1 2 3)))
      (fector->list F))
  => '(1 2 3))

(check
    (list->fector '(1 2 3))
  (=> fector=?) (fector 1 2 3))

\f
;;;; done

(check-report)

;;; end of file

-- 
Marco Maggi



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

* Re: ANN: fectors v0.1
  2012-07-08  6:27 ` Marco Maggi
@ 2012-07-08 10:26   ` Ian Price
  0 siblings, 0 replies; 3+ messages in thread
From: Ian Price @ 2012-07-08 10:26 UTC (permalink / raw)
  To: Marco Maggi; +Cc: guile-user, vicare-users

Marco Maggi <marco.maggi-ipsu@poste.it> writes:

> I  can  confirm  that  it works  with  Vicare  Scheme.   The
> following  is a  test  file  for Vicare,  just  place it  in
> fectors' source directory and do:
>
<snip>

Thank you for this Marco, it is very handy, and I have added it to the
source tree. Usually I also try to write my test suits more portably,
and more thoroughly than I had done for the release. But once you've
written them once, it always feels like a drag to do it a second time :)

-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



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

end of thread, other threads:[~2012-07-08 10:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-08  1:16 ANN: fectors v0.1 Ian Price
2012-07-08  6:27 ` Marco Maggi
2012-07-08 10:26   ` Ian Price

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