Implementing vector-for-each in PLT

François asked how one might implement vector-for-each. Here are two solutions that were provided:
Matthias

#lang scheme
(define-syntax for-each-vector
  (syntax-rules ()
    ((for-each-vector proc vec ...)
     (let ((len (min (vector-length vec) ...)))
       (do ((index 0 (+ index 1)))
         ((= index len))
         (proc (vector-ref vec index) ...))))))
(for-each-vector
 (lambda (a b) (display (+ a b)))
 #( 1 2 3)  #( 1 2 3))
(newline)
;; functional, preferred
;; for-each-vector2
;; (All (A C ...) ((C ... -> A) (Vectorof C) ... -> A))
(define (for-each-vector2 p . vec)
  (for ((i (in-range (apply min (map vector-length vec)))))
    (apply p (map (lambda (v) (vector-ref v i)) vec))))
(for-each-vector2
 (lambda (a b) (display (+ a b)))
 #( 1 2 3)  #( 1 2 3))
(newline)

Sam TH

#lang scheme
(require srfi/43)
(for ([a #(1 2 3)] [b #(1 2 3)])
  (display (+ a b)))
(newline)
(vector-for-each
 (lambda (i a b) (display (+ a b)))
 #(1 2 3) #(1 2 3))

Why there is not restart exception handling in PLT Scheme

YC asked here[1]:

Is it possible to handle exceptions like Common Lisp, specifically restarts?
Scenario: undefined variables – handling by defining the variable, and continue past the exception.

Matthew explained what is and is not possible in the following threads here, here, and here.
[1]: PLT Scheme Mailing list, “restart exception handling?”, Thu Jul 10 17:35:57 EDT 2008

Hacking PLT to add a range syntax

Here is a post demonstrating how to add an infix range syntax to PLT Scheme.

[a .. b]  => (interval a b)
(... expr1 [expr2] ...) => (... (vector-ref expr1 expr2) ...)

Addendum: 04/20/09
Here is the final version of the code, with additional interesting syntax:

That includes:
[1 .. 4] short interval (1 to 3)
[1 … 4] long interval (1 to 4)
Curry with {}:
{+ _ 3} => (lambda (x) (+ x 3)
{+ _ (* 2 _)} => (lambda (x y) (+ x (* 2 y)))
This is convenient with map and filter:
(map {+ _ 3} [1 … 3]) => ‘(4 5 6)
Iota from SRFI 1:
[5] => (iota 5) => (0 1 2 3 4)
[5 3] => (iota 5 3) => (3 4 5 6 7)
[5 3 2] => (iota 5 3 2) => (3 5 7 9 11)
Lambdas:
{n -> (+ n 1)} is (lambda (n) (+ n 1)
And a very simple comprehension:
> [(+ n 3) : n is (< n 10) (even? n)] (3 5 7 9 11) > [(+ n 3) : n is (< n 10)] (3 4 5 6 7 8 9 10 11 12) > [(* n n) : n is (< n 10) (odd? n)] (1 9 25 49 81)

The PLT email list archive URLs have changed

The PLT Scheme email list archive URLs have changed. You can read all about it in this thread.
The result is that any links posted before this change was made are now broken.
Basically it is no one’s fault: not the PLT folks nor the sysadmins. The mailing list software reindexes messages in this breaking manner.
Nonetheless, now there are around 200 broken links on this site alone. I’m neither sure how to fix them automatically nor manually. Clearly the latter would be too time consuming.

What file is a name defined in?

 

#lang scheme
; What file is a name defined in?
;; definition-source : identifier -> (U symbol path)
;; Returns a symbol or path for the module that contains
;; the definition for a given name.
(define (definition-source id)
  (let ([binding (identifier-binding id)])
    (and (list? binding)
         (resolved-module-path-name
          (module-path-index-resolve (car binding))))))
(definition-source #'map)
 ; => #
(definition-source #'+)
; => #%kernel
; "The + procedure is defined in the built-in kernel module
; (it has no Scheme source file)."

(via PLT)

Moby Scheme

We are delighted to announce the first release of Moby Scheme, a compiler from Beginner Student Language (BSL) + World programs to smartphones. The current prototype compiles to the Android platform, and supports almost all BSL programs as well as libraries to accelerometer, GPS, and SMS functionality.
We are concurrently working on a Web service interface for end-users. If your only goal is to *use* Moby, you can certainly try it out, but the current release assumes you have some developer chops to install and manage packages. We’re hoping, however, that you’ll also want to *contribute*, for which this is your avenue.

(via PLT)

Literate Programming in Scheme

The release notes here for PLT Scheme 4.1.5 mention support for literate programming. Not being familiar with the term; I read more about it on Wikipedia here.
I have wanted in-code documentation generation tools to serve this purpose; but I have never succeeded with them. It had always felt like I was battling the intent of the tool. Even Eiffel’s notion of different views on code-as-documentation never quite fit for me. This approach is fascinating; it allows for you to tell a story about the code as you write the code. Having posted to the PLT list asking about it here; two folks replied with details on this style and Scheme.
PLT Scheme recently added literate programming support; documented here. One example of its application is in Chat Noir here; and the source code for it may be viewed here (Thanks Robby).
A tool for literate programming in Scheme called is schemeweb located here (Thanks Phil).