Ypsilon Scheme System
From LittleWingPinball
Ypsilon is the implementation of Scheme Programming Language, which conforms to the latest standard R6RS* established in September 2007. Ypsilon achieves a remarkably short GC pause time and the best performance in parallel execution as it implements "mostly concurrent garbage collection", which is optimized for the multi-core CPU system. Ypsilon is easy to use as well as good for applications of any kind that require quick, reliable, and interactive data processing.
- News: Ypsilon 0.9.6-update2 released (03-Sept-2008)
- Revised 6 Report on the Algorithmic Language Scheme (R6RS*): http://www.r6rs.org/
- Ypsilon Background Story: http://www.LittleWingPinball.com/contents/en/ypsilon.html
Contents |
License
Ypsilon Scheme System
Copyright (c) 2004-2008 Yoshikatsu Fujita. All rights reserved.
Copyright (c) 2004-2008 LittleWing Company Limited. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the authors nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Requirements
Version 0.9.6:
- Linux(x86), MacOS X 10.4(x86), MacOS X 10.5(x86), Windows Vista(x86).
- 32bit mode. (64bit mode is not supported)
- Compile/execute on Cygwin is not supported. Use binary for Windows(ypsilon.exe) in Cygwin.
- libpthread and libdl required for Linux and MacOS X.
Download
All source codes are available at:
Build and Install
Linux
Use gcc version 4.2.3.
Follow the procedure to install Ypsilon at the standard location(/usr/local). In this case, the path of the program will be /usr/local/bin/ypsilon. The library will be copied under /usr/local/share/ypsilon. And the man file will be copied at /usr/local/share/man/man1/ypsilon.1
$ make clean $ make $ make check $ make install
When the installation is completed, enter ypsilon at the shell prompt to launch the program. Now Ypsilon works as a Scheme interpreter which is able to use all R6RS standard library syntaxes and procedures.
$ ypsilon Ypsilon 0.9.6 Copyright (c) 2008 Y.Fujita, LittleWing Company Limited. >
If you want to install Ypsilon at other locations; for instance under /opt/local, follow the procedure as below. In this case, the program path will be /opt/local/bin/ypsilon. The library will be copied under /opt/local/share/ypsilon and the man file will be copied at /opt/local/share/man/man1/ypsilon.1
$ make clean $ make PREFIX=/opt/local $ make PREFIX=/opt/local install
MacOS X
Use gcc which is included in Xcode 3.0. The rest of the procedure is the same as Linux.
Windows
The installation of the prebuilt program
- Start an installation by double click on ypsilon_win32_096.msi in the project directory.
- The program will be installed at C:\Program Files\Ypsilon\ypsilon.exe. The library will be copied under C:\Program Files\Ypsilon.
- Select Ypsilon from the list shown in the list of "all programs" in the start menu; Or, enter "Ypsilon" in the search box in the start menu to launch the program.
- Execute test.bat in the project directory for the test for the Windows version.
The building from the source code
- Open ypsilon.sln in the project directory by Visual Studio 2008.
- Build, or re-build the solution.
- Start an installation by double click on ypsilon_win32_096.msi as the new ypsilon_win32_096.msi will be created in the project directory.
Configurations
Environment
- YPSILON_SITELIB
- It specifies a colon-separated(Linux and Mac OS X) or semicolon-separated(Windows) list of the sitelib directories. Ypsilon traverses the sitelib directories at loading the library before looking up the system default directory. See also '--sitelib' in the Options section.
- YPSILON_LOADPATH
- It specifies a colon-separated(Linux and Mac OS X) or semicolon-separated(Windows) list of the Scheme script file directories. Ypsilon traverses the sitelib directories at loading the Scheme script before looking up the system default directory. See also '--loadpath' in the Options section.
- YPSILON_ACC
- This is the auto-compile-cache directory. The directory must be created in advance of compiling as Ypsilon saves compiled codes in it. See also '--acc' in the Options section.
bash settings
Readline functions are not built in Ypsilon. Employ rlwrap by Mr. Hans Lub. Install rlwrap 0.30 and add the following definitions at .bashrc in the home directory.
function yps() {
rlwrap -q "\"'" ypsilon $@
}
Entering yps at the shell prompt launches Ypsion with rlwrap.
Emacs settings
Add the following lines in the .emacs file in the home directory.
(setq scheme-program-name "ypsilon")
Meadow settings
Copy ypsilon.bat in the project directory to the Meadow install directory(C:\Meadow in the default setting). Then add the following two lines in the .emacs file in the Meadow install directory.
(modify-coding-system-alist 'process "ypsilon" '(utf-8 . utf-8)) (setq scheme-program-name "c:/Meadow/ypsilon.bat")
Operations
Auto-compile-cache function
Ypsilon has auto-compile-cache function to shorten Scheme library loading. It caches compiled codes in the library automatically. This function saves the loading time dramatically especially for large libraries.
- Windows
- auto-compile-cashe is enabled as default. The cache file will be created in the <user's home directory>\AppData\Local\Temp\Ypsilon.
- Linux, MacOS X
- Auto-compile-cache function will be enabled and the cache file will be created in .ypsilon directory if there is a directory named .ypsilon.
- Auto-compile-cache funtion will not work if there is no directory named .ypsilon and no cache directory is specified neither in environmental variable nor as an option.
To confirm the auto-compile-cache setting after launching the program, enter (auto-compile-cache) at repl prompt. If auto-compile-cache is enabled, the program returns the directory name. If it is not enabled, it returns #f as a value.
> (auto-compile-cache) "/home/fujita/.ypsilon"
You can enable the auto-compile-cache by specifying the directory name which will store the cache file.
> (auto-compile-cache "directory name")
Also you can disable the function by entering
> (auto-compile-cache #f)
You can confirm the auto-compile-cache status by launching the program with --verbose option.
> ypsilon --verbose
Ypsilon 0.9.6 Copyright (c) 2008 Y.Fujita, LittleWing Company Limited.
;; YPSILON_ACC unspecified
;; YPSILON_SITELIB unspecified
;; YPSILON_LOADPATH unspecified
;; (auto-compile-cache) => "/home/fujita/.ypsilon"
;; (scheme-library-paths) => ("/usr/local/share/ypsilon/sitelib")
;; (scheme-load-paths) => ()
> (import (glut))
;; compile "/usr/local/share/ypsilon/sitelib/glut.scm"
;; compile "/usr/local/share/ypsilon/sitelib/ffi.scm"
> (import (streams))
;; loading "/home/fujita/.ypsilon/streams.cache"
>
Interactive mode
Ypsilon launches in the interactive mode if the Scheme script name is not entered as an argument at launching. It enters repl after importing (core) and (rnrs) libraries at top-level.
Script mode
Ypsilon launches in the script mode if a Scheme script name is entered as an argument at launching. This mode supports the top-level program execution in the form described in R6RS Chapter 8 Top-level programs.
If --interactive option is specified, it enters repl after executing the Scheme script.
Options
Write options before the Scheme script name as follows at launching the program.
ypsilon [ options ] [--] [ scheme-script ] [ arguments ]
Any of [ options ] [--] [ scheme-script ] [ arguments ] can be omitted. -- is the special option which must be written just before the Scheme script name.
--mute, -m
- Suppresses greeting.
--quiet, -q
- Suppresses greeting, repl prompt, and repl output.
--verbose, -v
- Prints load and compile activities.
--warning, -w
- Prints warnings on compile.
--interactive, -i
- Enters repl after running the script file.
--r6rs, -6
- Conforms R6RS Top-level program syntax
--compatible, -c
- Extends the lexical syntax for the compatibility of the existing scripts. For example, the reader reads '1+', '@1', '.n', and '|u v|' as identifiers. See also R6RS conformance section.
--sitelib=path
- Adds load search path. The path is a colon-separated list of directories. See also YPSILON_SITELIB in the Environment section.
--loadpath=path
- Adds load search path. The path is a colon-separated list of directories. See also YPSILON_LOADPATH in the Environment section.
--acc=dir
- Sets a auto-compile-cache directory. See also YPSILON_ACC in the Environment section.
--heap-limit=mbytes
- Sets a total heap limit in MBytes.
--dump-condition
- Force default exception handler prints conditions.
--disable-acc
- Disables the auto-compile-cache.
--clean-acc
- Cleans up the auto-compile-cache.
--version
- Prints the version and exits.
--help
- Prints help and exit.
--
- Indicates no more option to proceed.
Other utilities
You can use apropos function by (import (apropos)). For example, (apropos "^byte") displays the list of procedures which start with "byte". Apropos traverses the libraries which are already loaded.
>(import (apropos))
>(apropos "^byte")
;; bytevector->sint-list (core) (core bytevectors) (rnrs) (rnrs bytevectors)
;; bytevector->string (core) (core io) (rnrs) (rnrs io ports)
;; bytevector->u8-list (core) (core bytevectors) (core primitives) (rnrs) (rnrs bytevectors)
;; bytevector->uint-list (core) (core bytevectors) (rnrs) (rnrs bytevectors)
;; bytevector-copy (core) (core bytevectors) (core primitives) (rnrs) (rnrs bytevectors)
:
:
You can add the Scheme script search paths by (add-load-path "path"). Write (add-load-path "") displays the current path settings.
>(add-load-path "~/scm-scripts")
("/home/fujita/scm-scripts")
You can add the Scheme script search paths by (add-library-path "path"). Write (add-library-path "") displays the current path settings.
>(add-library-path "~/scm-libs")
("/home/fujita/scm-libs" "/usr/local/share/ypsilon/sitelib")
(import (trace)) enables the trace functions.
>(import (trace)) >(define fib ...) >(trace fib) (#<closure fib>) >(fib 5) C (fib 5) C : (fib 4) C : : (fib 3) C : : : (fib 2) R : : : 1 C : : : (fib 1) R : : : 1 R : : 2 C : : (fib 2) R : : 1 R : 3 C : (fib 3) C : : (fib 2) R : : 1 C : : (fib 1) R : : 1 R : 2 R 5 ; #<closure fib> call:9 level:4 5 >(untrace fib) () >(fib 5) 5
(import (pregexp)) enables Portable regular expressions for Scheme (pregexp)by Mr. Dorai Sitaram.
>(import (pregexp))
>(pregexp-match "([A-Za-z0-9._%+-]+)@([A-Za-z0-9.-]+)\\.([A-Za-z]{2,4})" "foo.bar@hoge.hoge.com")
("foo.bar@hoge.hoge.com" "foo.bar" "hoge.hoge" "com")
(import (match)) enables Pattern Matching Syntactic Extensions for Scheme(match or Andrew Wright match)by Mr. Andrew K. Wright.
>(import (match)) >(match '(1 2 (3)) ((x y (z)) (+ x y z))) 6
(import (streams)) enables srfi-41.
>(import (streams))
>(stream->list 10
(stream-map (lambda (x) (* x x))
(stream-from 0)))
(0 1 4 9 16 25 36 49 64 81)
(import (srfi srfi-N)) enables srfi-1, 6, 8, 26, 28, 39, 42.
>(import (srfi srfi-42) >(list-ec (:range n 3) (:range k (+ n 1)) (list n k)) ((0 0) (1 0) (1 1) (2 0) (2 1) (2 2))
R6RS Conformance
Ypsilon implements full and complete features of R6RS (Revised 6 Report on the Algorithmic Language Scheme).
- Revised 6 Report on the Algorithmic Language Scheme
- Revised 6 Report on the Algorithmic Language Scheme — Standard Libraries
Ypsilon implements Scheme's Numerical Tower which includes Arbitrary Precision Integers, Rational Numbers, and Exact and Inexact Complex Numbers. Ypsilon tries to return exact numbers if possible.
(sqrt -16) => 0+4i (sqrt -417889/47831056-15/3458i) => 3/133-5/52i
Ypsilon is conformity to all the specification (including Implementation responsibilities) which is specified by the keywords which are explained in R6RS Chapter 2 Requirement levels such as "must", "must not", "should", "should not". Therefore, scripts which depend on the behaviors which were unspecified in R5RS may generate syntax errors. For example, (letrec ((a (* (b) (c))) (b (lambda () 10)) (c (lambda () 20))) a) are allowed to evaluate as 200 in R5RS processing system, it cause an error in Ypsilon as follows:
error: binding construct attempt to reference uninitialized variable, use '--warning' to perform expansion time check
In R6RS, strict error detection is required. For example, it is obligated to make identifiers such as '1+' or those which quoted like ' |foo bar| lexical exception. Therefore, there would be some scripts which can not be read by R6RS. Ypsilon can read such identifiers by specifying --compatible in command lines options. In such cases, the reader would not conform R6RS. You can control the reader behavior by #!r6rs and #!compatible comments in the source codes.
- After #!r6rs comments, the reader enters R6RS conforming status until the port in reading gets EOF
- After #!compatible comments, it enters into the compatible mode in the same way
- #!r6rs and #!compatible comments can be entered at repl prompts.
#!r6rs >1+ error in read: invalid lexical syntax 1+ ..."/dev/stdin" line 1 #!compatible >1+ error: unbound variable |1+|
The implementation of the library system is called implicit-phased model. I adopted this model as it enables to develop interactive user library developments. Also this model is close to the specification which is now examined for ERR5RS.
In implicit-phased model, identifiers which has been exported from the library can be referred in every level. The "for" form for explicit-phased models will be syntax-checked but the contents will be ignored.
ERR5RS Conformance
Ypsilon is planned to conforme to ERR5RS as soon as the specification is fixed.
* Reference: http://scheme-punks.cyber-rush.org/wiki/index.php?title=Main_Page
Benchmarks
Ypsilon works on concurrent GC and multi-core CPU system bring its ability into full play.
Please note the bench-mark test was done with Intel Core2 Duo CPU.
The bench-mark code uses Gambit Benchmarks of Gambit Scheme system.
- Gambit Scheme system: http://dynamo.iro.umontreal.ca/~gambit/wiki
All the bench-mark codes used are included in the distribution package available for downloads.
