Racket (programming language)

Racket (programming language)
Racket
Racket logo.png
Paradigm(s) Multi-paradigm: Functional, Procedural, Modular, Object-oriented, Reflective, Meta
Appeared in 1994
Developer PLT Inc.
Stable release 5.2[1] (November 9, 2011; 1 day ago (2011-11-09))
Typing discipline dynamic, strong, static
Dialects Typed Racket, Lazy Racket, Scribble, FrTime, and more.
Influenced by Scheme, Eiffel[2]
Influenced Scheme[3]
Platform x86, PPC, SPARC, MIPS, ARM
OS Cross-platform
License LGPL
Usual filename extensions .rkt, .rktl, .rktd, .scrbl, .plt, .ss, .scm
Website racket-lang.org

Racket (formerly called PLT Scheme) is a multi-paradigm programming language in the Lisp/Scheme family, that also serves as a platform for language creation, design, and implementation.[4][5] The Racket platform has four primary components:

  • the implementation of Racket (including a rich runtime system, various libraries, JIT compiler, and more);
  • DrRacket (formerly known as DrScheme), the Racket program development environment;
  • the ProgramByDesign outreach, an attempt to turn Computing and Programming into "an indispensable part of the liberal arts curriculum";[6] and
  • PLaneT,[7] Racket's web-based package distribution system for user-contributed packages.

The programming language itself is known for its powerful macro system which enables the creation of embedded and domain-specific languages, language constructs such as classes or modules, and separate dialects of Racket with different semantics.[8][9][10][11]

Contents

History

Development

Matthias Felleisen founded PLT in the mid 1990s, first as a research group, soon after as a project dedicated to the production of pedagogic materials for novice programmers (lectures, exercises/projects, software). In January 1995, the group decided to develop a pedagogic programming environment based on Scheme. Matthew Flatt cobbled together MrEd—the original virtual machine for Racket—from libscheme, wxWidgets, and a few other free systems.[12] In the years that followed, a team including Flatt, Robby Findler, Shriram Krishnamurthi, Cormac Flanagan, and many others produced DrScheme, a programming environment for novice Scheme programmers and a research environment for soft typing. The main development language that DrScheme supported was called PLT Scheme.

In parallel, the team started conducting workshops for high school teachers, training them in program design and functional programming. Field tests with these teachers and their students provided essential clues for the direction of the development.

Over the following years, PLT added teaching languages, an algebraic stepper,[13] a transparent read-eval-print loop, a constructor-based printer, and many other innovations to DrScheme, producing an application-quality pedagogic program development environment. By 2001, the core team (Felleisen, Findler, Flatt, Krishnamurthi) had also written and published their first textbook, How to Design Programs, based on their teaching philosophy.

Version history

The first generation of PLT Scheme revisions introduced features for programming in the large with both modules and classes. Version 42 introduced units–a first-class module system–to complement classes for large scale development. The class system gained features (e.g. Java-style interfaces) and also lost several features (e.g. multiple inheritance) throughout these versions.[9] The language evolved throughout a number of successive versions, and gaining milestone popularity in Version 53, leading to extensive work and the following Version 100, which would be equivalent to a "1.0" release in current popular version systems.

The next major revision was named Version 200, which introduced a new default module system that cooperates with macros. In particular, the module system ensures that run-time and compile-time computation are separated in order to support a "tower of languages."[14] Unlike units, these modules are not first-class objects.

Version 300 introduced Unicode support, foreign library support, and refinements to the class system. Later on, the 300 series improved the performance of the language runtime with an addition of a JIT compiler and a switch to a default generational garbage collection.

By the next major release, the project has switched to a more conventional sequence-based version numbering. Version 4.0 introduced the #lang short-hand to specify the language that a module is written in. In addition, the revision introduced immutable pairs and lists, support for fine-grained parallelism, and a statically-typed dialect.

Racket

On June 7, 2010, PLT Scheme was renamed Racket.[15] The renaming coincided with the release of Version 5.0. Subsequently, the GUI backend was rewritten in Racket from C++ in Version 5.1 using native UI toolkits on all platforms.

Features

Racket's core language includes macros, modules, lexical closures, tail calls, delimited continuations,[16] parameters (fluid variables), software contracts, green and OS threads, and more. Further extensions to the language are created with the powerful macro system. Unlike programming languages that lack macro systems, most language constructs in Racket are written on top of the base language using macros. These include a mixin class system,[9] a component (or module) system as expressive as ML's,[10] and pattern matching.

In addition, the language features the first contract system for a higher-order language.[17]

The most remarkable feature of these remains the macro system. It provides far more expressive power than Lisp's S-expression manipulation system,[18][19] Scheme 84's hygienic extend-syntax macros, or R5RS's syntax-rules. Indeed, it is fair to say that the macro system is a carefully tuned API for compiler extensions. Using this compiler API, programmers can add features and entire domain-specific languages in a manner that makes them completely indistinguishable from built-in language constructs.

Racket's compiler is a bytecode compiler that translates to an internal bytecode format that is run by the Racket virtual machine. On x86 and PPC platforms, the bytecode is further compiled using a JIT compiler at runtime.

Since 2004, the language has also shipped with PLaneT: a package manager that is integrated into the module system so that third-party libraries can be transparently imported and used. Additionally, PLaneT has a built-in versioning policy to prevent dependency hell.[20]

A practical language

Apart from having a solid theoretical basis, Racket was designed to be used in production systems from the very beginning. Thus, the Racket distribution features an extensive library that covers systems and network programming, web development, a uniform interface to the underlying operating system, a dynamic foreign function interface, several flavours of regular expressions, lexer/parser generators, logic programming, and a complete GUI framework, to name a few.

The design decision to make Racket a practical language has implications beyond the library, too. Those include Racket's ability to generate standalone executables under Windows, Mac OS X and Unix, a profiler and debugger included in the IDE and a unit testing framework.

Language development

The macro system in Racket has been used to construct entire language dialects. This includes Typed Racket—a statically typed dialect of Racket that eases the migration from untyped to typed code,[21] and Lazy Racket—a dialect with lazy evaluation.[22] Other dialects include FrTime (functional reactive programming), Scribble (documentation language),[23] Slideshow (presentation language),[24] and several languages for education.[25][26] Racket's core distribution provides libraries to aid the process of constructing new programming languages.

Such languages are not restricted to S-expression based syntax. In addition to conventional readtable-based syntax extensions, Racket's #lang makes it possible for a language programmer to define any arbitrary parser, for example, using the parser tools library.[27] See Racket logic programming for an example of such a language.

Programming environment

The language platform provides an IDE, a continuation-based web server, a graphical user interface, and other tools. Racket is also a viable scripting tool and can be used for scripting the Unix shell and includes libraries like all common scripting languages.

Code examples

Here's a trivial "hello world" program:

#lang racket
"Hello, World!"

Running this program produces the output:

"Hello, World!"

Here's a slightly less trivial program:

The result of this program, as shown in DrRacket
#lang racket
(require 2htdp/image)
(let sierpinski ([n 8])
  (if (zero? n)
    (triangle 2 'solid 'red)
    (let ([t (sierpinski (- n 1))])
      (freeze (above t (beside t t))))))

This program, taken from the Racket web page, draws a Sierpinski triangle, nested to depth 8.

Using the #lang directive, a source file can be written in different dialects of Racket. Here is an example of the factorial program in Typed Racket, a statically typed dialect of Racket:

#lang typed/racket
(: fact (Integer -> Integer))
(define (fact n)
  (cond [(zero? n) 1]
        [else (* n (fact (- n 1)))]))

References

  1. ^ Racket blog, Racket v5.2
  2. ^ Strickland, T.S.; and Fellesisen, Matthias (2010). "DLS 2010: Contracts for First-Class Classes". http://www.ccs.neu.edu/racket/pubs/dls10-sf.pdf. 
  3. ^ Michael Sperber, R. Kent Dybvig, Matthew Flatt, Anton Van Straaten et al. (August 2007). "Revised6 Report on the Algorithmic Language Scheme (R6RS)". Scheme Steering Committee. http://www.r6rs.org/. Retrieved 2011-09-13. 
  4. ^ "Welcome to Racket". http://docs.racket-lang.org/guide/intro.html. Retrieved 2011-08-15. 
  5. ^ "Dialects of Racket and Scheme". http://docs.racket-lang.org/guide/dialects.html. Retrieved 2011-08-15. 
  6. ^ "Overview". Program by Design. http://programbydesign.org/overview. Retrieved 2011-08-17. 
  7. ^ PLaneT: Racket's centralized package distribution system
  8. ^ "Macros Matter". 2007-05-03. http://blog.racket-lang.org/2007/05/macros-matter.html. Retrieved 2011-08-08. 
  9. ^ a b c Flatt, M.; Findler, R. B.; Felleisen, M. (2006). "Scheme with Classes, Mixins, and Traits". Asian Symposium on Programming Languages and Systems. http://www.ccs.neu.edu/scheme/pubs/asplas06-fff.pdf. 
  10. ^ a b Flatt, M.; Felleisen, M. (1998). "Units: Cool Modules for HOT Languages". Programming Language Design and Implementation. http://www.ccs.neu.edu/scheme/pubs/pldi98-ff.ps.gz. 
  11. ^ Tobin-Hochstadt, S.; St-Amour, V.; Culpepper, R.; Flatt, M.; Felleisen, M. (2011). "Languages as Libraries". Programming Language Design and Implementation. http://www.ccs.neu.edu/scheme/pubs/pldi11-thacff.pdf. 
  12. ^ "Rebuilding Racket's Graphics Layer". 2010-12-08. http://blog.racket-lang.org/2010/12/racket-version-5.html. Retrieved 2011-08-23. 
  13. ^ Clements, J.; Flatt, M.; Felleisen, M. (2001). "Modeling an Algebraic Stepper". European Symposium on Programming Languages. http://www.ccs.neu.edu/scheme/pubs/esop2001-cff.pdf. 
  14. ^ Flatt, M. (2002). "Composable and Compilable Macros". International Conference on Functional Programming. 
  15. ^ "From PLT Scheme to Racket". Racket-lang.org. http://racket-lang.org/new-name.html. Retrieved 2011-08-17. 
  16. ^ Flatt, M.; Yu, G.; R. B.; Felleisen, M. (2007). "Adding Delimited and Composable Control to a Production Programming Environment". International Conference on Functional Programming. http://www.ccs.neu.edu/scheme/pubs/icfp07-fyff.pdf. 
  17. ^ Findler, R. B.; Felleisen, M. (2002). "Contracts for Higher-Order Functions". International Conference on Functional Programming. http://www.eecs.northwestern.edu/~robby/pubs/papers/ho-contracts-icfp2002.pdf. 
  18. ^ Flatt, Matthew (2002). "Composable and Compilable Macros, You Want it When?". International Conference on Functional Programming. http://www.cs.utah.edu/plt/publications/macromod.pdf. 
  19. ^ Flatt, Culpepper, Darais, Findler, Macros that Work Together; Compile-Time Bindings, Partial Expansion, and Definition Contexts
  20. ^ Matthews, J. (2006). "Component Deployment with PLaneT: You Want it Where?". Scheme and Functional Programming Workshop. 
  21. ^ Tobin-Hochstadt, S.; Felleisen, M. (2008). "The Design and Implementation of Typed Scheme". Principles of Programming Languages. 
  22. ^ Barzilay, E.; Clements, J. (2005). "Laziness Without All the Hard Work: Combining Lazy and Strict Languages for Teaching". Functional and Declarative Programming in Education. 
  23. ^ Flatt, M.; Barzilay, E.; Findler, R. B. (2009). "Scribble: Closing the Book on Ad Hoc Documentation Tools". International Conference on Functional Programming. 
  24. ^ Findler, R. B.; Flatt, M. (2004). "Slideshow: Functional Presentations". International Conference on Functional Programming. 
  25. ^ Felleisen, M.; Findler, R. B.; Flatt, M.; Krishnamurthi, S. (2009). "A Functional I/O System (or Fun for Freshman Kids)". International Conference on Functional Programming. http://www.ccs.neu.edu/scheme/pubs/icfp09-fffk.pdf. 
  26. ^ Felleisen, M.; Findler, R. B.; Flatt, M.; Krishnamurthi, S. (2004). "The Structure and Interpretation of the Computer Science Curriculum". Journal of Functional Programming. http://www.ccs.neu.edu/scheme/pubs/fdpe2002-fffk.pdf. 
  27. ^ "Parser Tools: lex and yacc-style Parsing". http://docs.racket-lang.org/parser-tools/. Retrieved 2011-08-16. 

Further reading

External links

Tutorials
Style Guide
Website and documentation

Wikimedia Foundation. 2010.

Игры ⚽ Поможем сделать НИР

Look at other dictionaries:

  • Comparison of programming languages (list comprehension) — Programming language comparisons General comparison Basic syntax Basic instructions Arrays Associative arrays String operations …   Wikipedia

  • List of programming languages by category — Programming language lists Alphabetical Categorical Chronological Generational This is a list of programming languages grouped by category. Some languages are listed in multiple categories. Contents …   Wikipedia

  • List of programming languages — Programming language lists Alphabetical Categorical Chronological Generational The aim of this list of programming languages is to include all notable programming languages in existence, both those in current use and historical ones, in… …   Wikipedia

  • Monad (functional programming) — In functional programming, a monad is a programming structure that represents computations. Monads are a kind of abstract data type constructor that encapsulate program logic instead of data in the domain model. A defined monad allows the… …   Wikipedia

  • DrRacket — Developer(s) PLT Inc. Stable release 5.2 [1] / November 9, 2011; 1 day ago ( …   Wikipedia

  • Datalog — is a query and rule language for deductive databases that syntactically is a subset of Prolog. Its origins date back to the beginning of logic programming, but it became prominent as a separate area around 1977 when Hervé Gallaire and Jack Minker …   Wikipedia

  • Scheme — Семантика: функциональный Тип исполнения: интерп …   Википедия

  • List comprehension — A list comprehension is a syntactic construct available in some programming languages for creating a list based on existing lists. It follows the form of the mathematical set builder notation (set comprehension) as distinct from the use of map… …   Wikipedia

  • One-liner program — A one liner is textual input to the command line of an operating system shell that performs some function in just one line of input. The one liner can be An expression written in the language of the shell. The invocation of an interpreter… …   Wikipedia

  • Continuation — For other uses, see Continuation (disambiguation). In computer science and programming, a continuation is an abstract representation of the control state of a computer program. A continuation reifies the program control state, i.e. the… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”