How PLTCOLLECTS works in PLT Scheme

R6RS Scheme systems are composed of code artifacts that are either libraries or top-level-programs. Libraries simply map to directories. In PLT Scheme, you can configure the library search path by configuring the PLTCOLLECTS environmental variable.
Having configured it and not getting results that I had expected, I asked about what I was doing wrong and got a great explanation here. It is pasted below.

The path-list function does something that is common with environment variables that specify paths: you have a string of several paths, separated by a “:”, which are searched in order. In addition, an empty path means “splice the default here”. So you get:
“/foo:/bar” — look in /foo and then in /bar
“/foo:/bar:” — look in /foo, then in /bar, and then in the default
“:/foo:/bar” — look in the default, then /foo then /bar
“/foo::/bar” — look in /foo then the default, then /bar
The last example shows why it’s useful — it allows you to both override PLT collections, as well as specify collections that could be overriden by PLT collections. For example, the first is useful if you want to try patching libraries, and the second is useful if you want to add a library that is added to a later version of PLT and you want to use it now but not when you upgrade.
Finally, on windows, the path separator character is “;” instead of a colon. (And remember the possible pitfalls with backslashes, or just use forward slashes.)

Hopefully that detail gets added to the documentation; it wasn’t obvious from reading it.

Lisp as a crucible

Scheme and Lisp force you *think* from the get-go. Most engineers and programmers hate to do that and it makes them uncomfortable. Starting a program in Java or C is easy. There’s a pile of boilerplate you can type without thinking about it, and it `feels’ like you’re programming. Then you have to haul out the bag of tools like the compiler and the linker and makefiles or ant. There’s a lot of busy work needed just to get going, and you feel like you’ve accomplished something.
In Scheme or Lisp, you start it up and there you are at the REPL. You have to decide what your program is going to do. You can’t waste time writing boilerplate (it’s unnecessary), designing data structures (just cons one and specialize it later), figuring out how to build complex inheritance hierarchies (do that once you know what you are doing), you have to dive into the problem right away. If you are willing to make mistakes and learn from them, then the REPL is a great place to play. If you prefer to plan ahead so you don’t make mistakes, a REPL is a very uncomfortable place to be.

— jrm
Having experienced the “discomfort” myself, I recognize now that this development approach acts as a mirror to your strengths and weaknesses. It reveals, very very quickly, whether or not you really have got a grasp both on the problem and how you plan to solve it. There is no where to hide! It is great.
(via R6RS)

Why should programmers care about currying in practice in Scheme?

I wanted to know what currying means in practice for programmers who are not themselves theoretical computer scientists so I asked about it here. There were a lot of informative replies; and the most direct answers to the question seem to be:
Anthony Cowley:

There are many cases where Curried functions can be convenient, but I’ll just pick one class of examples. In FP, one is often passing around bundles of state in the form of parameters to a function.

Joe Marshall:

Your best bet would be to look at existing Scheme code. I found this example in the MIT Scheme loader: [click link for code]

Richard Cleis:

Currying permits repeated use of intermediate functions as an alternative to overtly managing arguments to a core function.

David Van Horn [on how to use the state monad in Scheme]:

You might have a look at these:
http://groups.google.com/group/comp.lang.functional/msg/2fde5545c6657c81
http://okmij.org/ftp/Scheme/monad-in-Scheme.html

Unhygienic macros inside of unhygienic macros are difficult

In this post; Ryan explains why unhygienic macros inside of unhygienic macros are often difficult.

;; the working if-it & when-it
(define-syntax (if-it stx)
  (syntax-case stx ()
    ((if-it test? then else)
     (with-syntax ((it (datum->syntax #'if-it 'it)))
       #'(let ((it test?))
           (if it then else))))))
(define-syntax (when-it stx)
  (syntax-case stx ()
    ((~ test? exp exp2 ...)
     (with-syntax ((it (datum->syntax #'~ 'it)))
       #'(let ((it test?)) (when it exp exp2 ...))))))
;; the non-working cond-it
(define-syntax (cond-it stx)
  (syntax-case stx (else)
    ((cond-it (else exp exp2 ...))
     #'(begin exp exp2 ...))
    ((cond-it (test? exp exp2 ...))
     #'(when-it test? exp exp2 ...))
    ((cond-it (test? exp exp2 ...) cond1 cond2 ...)
     #'(if-it test? (begin exp exp2 ...)
              (cond-it cond1 cond2 ...)))))

When ‘cond-it’ expands and produces an ‘if-it’ expression, the ‘if-it’ is marked by the macro expander as coming from a macro. That means its lexical context is different from the ‘it’ variables in the branches. That means that the ‘it’ variable binding produced by ‘if-it’ does not capture the ‘it’ references in the branches.

— Ryan

Functional Java

Functional Java is an open source library that aims to prepare the Java programming language for the inclusion of closures. It also serves as a platform for learning functional programming concepts by introducing these concepts using a familiar language. The library is intended for use in production applications and is thoroughly tested using the technique of automated specification-based testing with ScalaCheck.

(via PLT)

Adding a gutter to DrScheme

I had asked about how to add a gutter with line numbers to DrScheme, and Robby explained one approach here.

#lang scheme/gui
(require (lib "framework.ss" "framework")
         (lib "etc.ss"))
(define f (new frame:basic% [label ""] [width 500] [height 600]))
(define hp (new horizontal-panel% [parent (send f get-area-container)]))
(define gutter-text (new scheme:text%))
(define gutter-ec (new editor-canvas%
                       [parent hp]
                       [style '(hide-vscroll)]
                       [editor gutter-text]
                       [stretchable-width #f]
                       [min-width 60]))
(define text (new scheme:text%))
(define ec (new editor-canvas% [parent hp] [editor text]))
(send text load-file (build-path (collection-path "drscheme")
                                 "private" "rep.ss"))
(for-each
 (λ (n) (send gutter-text insert (format "~a\n" n)))
 (build-list (send text last-paragraph) add1))
(send gutter-ec scroll-to 0 0 0 0 #t)
(send f show #t)

Putting Java’s Null in its Place

Richard Cobbe’s thesis looks interesting:

Mainstream object-oriented languages include a null value that inhabits every object type and that pervades programs. It exists both because the language semantics requires it in certain places and because it is the most convenient representation for common patterns, such as for sentinel values indicating failure. Safety requires implementations of these languages to insert run-time checks throughout programs to determine whether object references are null at each field lookup and method call.
The ubiquity of null in object-oriented programs leads to severe engineering problems for programmers. First, the error messages issued by the run-time checks are typically not sufficiently informative to help the programmer find the source of the error. Second, the type systems in OO languages generally do not distinguish null from other values of (object) type, preventing the programmer from stating important invariants about the flow of null in the type system. Third, programmers’ standard use of null as a sentinel does not unambiguously represent failures. To resolve or avoid these ambiguities, component authors must incorporate additional complexity into their interfaces, and this complexity can lead to subtle bugs.
In this dissertation, we propose two changes to Java that allow us to completely remove the null value. Doing so addresses the problems above and provides significant engineering benefits to the programmer. Further, we demonstrate the practical feasibility of our proposal with a migration path that allows programmers to shift large codebases from Java to our new language, one class at a time.

(via LtU)

One reason for hygiene

You need hygiene because:

Only superstars on their highest alert level [while writing macros] get things right all the time.

–Matthias
That said, hygiene alone isn’t a cure-all for writing predictable macros. If you don’t understand what you are doing, thoroughly; you will screw up eventually. “Thar be dragons here” as someone once warned on the PLT list.
(via PLT)

Programming gerbils: Distributed programming with PLT-Scheme

Next Boston Lisp Meeting: Monday February 23th 2009 at 1800 at MIT 34-401B
Dimitris Vyzovitis will give a talk about Programming gerbils: Distributed programming with PLT-Scheme.
vyzo will talk about gerbil, a little language for distributed programming using PLT-Scheme. Gerbil is a macro language that provides facilities for actor-based distributed programs and transparent network simulation.
vyzo is a PhD student at the MIT Media Lab who suffers from a severe scheme addiction.
His website is at http://web.media.mit.edu/~vyzo/

(via PLT)