Scheme Programming/Why Scheme rather than Java, Python or another high-level language?

From Wikibooks, open books for an open world
Jump to navigation Jump to search
Scheme Programming
 ← Why Learn Scheme? Why Scheme rather than Java, Python or another high-level language? What defines Scheme? → 

Java and Python are very powerful real world languages, but they often struggle as languages for learning. The extra syntax they have for enabling the programmer to easily access the more advanced features quickly complicate the whole matter, thus defeating the point of being easy to learn.

Scheme supports many features often only found in interpreted languages such as closures, first class functions and advanced meta-programming, even though Scheme can be compiled easily. In fact, many of these features which are today almost exclusively associated with interpreted languages started with Scheme and unlike Python, JavaScript and Ruby which inherited many features from Scheme, Scheme is a minimalistic language.

The main difference between most interpreted languages and Scheme is that in Scheme, more advanced operations are typically expressed in terms of simpler operations, this reduces the task of implementing Scheme and also gives the programmer the ability to further extend the language with similar extra features. For instance, a lexical block with top bindings as in C:

{
	int a = 1, b = 2;
	/*
	 * Block code here
	 */
}

would be expressed in Scheme as:

(let ((a 1) (b 2))
  ; Block code here
)

Where the semantics of let are itself defined in Scheme as:

(define-syntax let
  (syntax-rules ()
    ((let ((symbol value) ...) content ...)
     ((lambda (symbol ...) content ...) value ...))))

The majority of Scheme syntax is thus defined in Scheme code, thus, while most languages only provide the definition of subroutines, Scheme also allows the definition of new syntax while still being a compiled language. Indeed, Scheme can even decide at runtime what new syntax to include.

The obvious downside of this is that there is a lot of parentheses in Scheme source code, so much that this may be confusing at first. This is a characteristic of most LISP-derived languages, and has led to the nickname "Lost In Stupid Parentheses" for various LISP implementations. However, the brackets do have merit. The fact that there were a lot of functional attempts to express the full power of Scheme in a more conventional syntax that never became popular show that these brackets do work better than they seem at first glance, and most Scheme programmers support the fact that once you understand it, it makes things a lot clearer.