BASIC Developer & Support Resources > Scripting Languages

Elk Scheme Extension Module.

(1/2) > >>

John:
In the process to trying to get a Fibonacci Scheme script running under TinyScheme it produced the wrong answer. The TinyScheme extension module was just a minimal API connection to Scheme. Basically a Scheme EVAL function.

I ran into Elk Scheme which has an extensive C API and BIGINT support. I would like to create an extension module for ScriptBasic with Elk. My hope is Mike will have a casual interest and mentor this project along.



Elk Project Site   Git Repository



--- Code: Text ---What is Elk?------------ Elk is an implementation of the Scheme programming language.In contrast to existing, stand-alone Scheme systems Elk has beendesigned specifically as an embeddable, reusable extension languagesubsystem for applications written in C or C++. Developers using Elk can deliver applications with different componentswritten in different languages, such as an efficient core written inC or C++ and an extensible user interface layer implemented in Scheme.To help building hybrid application architectures, Elk supports atightly-knit interworking of the C/C++ parts of applications withScheme code. Elk is also useful as a stand-alone Scheme implementation, in particularas a platform for rapid prototyping of X11-based Scheme programs. The Elk project was started in 1987 to support ISOTEXT, a multimediadocument editor that has been developed at the Technical University ofBerlin.  The first freely available version, Elk 1.0, was published inUSENET in September 1989.  Since then, Elk has been successfully used asthe extension language framework for numerous applications (commercialproducts as well as free software projects).  Getting Elk----------- You can obtain the Elk 3.99 distribution as well as additional informationabout Elk in the World Wide Web at    http://sam.zoy.org/elk/ The distribution is also available for anonymous FTP from a number ofservers including these:      ftp://ftp.x.org/contrib/devel_tools/elk-3.0.tar.gz   ftp://ftp.uni-bremen.de/pub/programming/languages/scheme/elk/elk-3.0.tar.gz  A non-trivial example application using Elk as its extension languageis available as source and pre-compiled binaries (`unroff' is a trofftranslator with back-ends for HTML and the -ms and -man macros):   http://www.informatik.uni-bremen.de/~net/unroff  Elk features------------   o  Full incremental, dynamic loading      This facility enables Scheme code to load compiled Scheme extensions     into the running interpreter (or into the application) on demand.     Complex Elk-based applications can be decomposed into dynamically     loadable components to avoid large, monolithic executables.     Furthermore, user-supplied extension need not be written entirely in     Scheme; they may include an efficient, low-level layer written in C     or C++.      Dynamic loading in Elk is supported on many platforms and is not     restricted to a dlopen() interface.  Elk provides automatic     initialization of dynamically loaded extensions and takes care of     C++ static constructors/destructors embedded in object files.   o  Freezing of fully customized applications into executable files      Elk provides a new Scheme primitive `dump' which freezes the dynamic     runtime image of the Scheme interpreter into an executable file     (including an enclosing application if present).  This facility     resembles unexec() in Emacs, but the new executable resumes execution     by returning from the call to `dump' by which that executable was     created (not unlike fork() in UNIX).  Dynamic loading and `dump'     increase the usability of Elk as the backbone of complex applications.   o  Powerful C/C++ interface for language interoperability      Elk provides for a tight integration of the C/C++ core of applications     (or extensions) with the extension language.  Applications can define     their own Scheme primitives (three calling disciplines are supported),     define application-specific first-class Scheme types with customized     print and read functions, convert objects between Scheme types and     C/C++ types in various ways, implement weak data structures, raise     Scheme errors, define Scheme variables and symbols, evaluate     S-expressions encoded as C strings, and utilize the garbage collector.   o  Full Scheme bindings for X11 and Motif      Several dynamically loadable extensions provide full Scheme access to     the X11/OpenWindows Xlib, to the application programmer interface of     the Xt intrinsics, and to the Athena and OSF/Motif widget sets.     Using these extensions, the graphical user-interfaces of Elk-based     applications can be built entirely in the extension language.   o  UNIX interface      Elk provides Scheme access to most UNIX system calls and common C     library functions.  The UNIX extension supports a wide range of     different UNIX platforms without restricting its functionality to the     lowest common denominator or to the POSIX 1003.1 functions.   o  Stop-and-copy and generational, incremental garbage collection      Elk employs two garbage collection strategies selectable at compile     time: a traditional stop-and-copy garbage collector and a generational     garbage collector which is more efficient and thus reduces the time the     application is disrupted by a garbage collection.  On platforms with     advanced memory management, `incremental' mode can be enabled for the     generational garbage collector to further reduce wait times.   o  Non-standard Scheme features      In addition to the standard Scheme core, Elk supports first-class     environments, error handling, provide/require and autoloading,     fluid bindings and dynamic-wind, simple `eval-twice'-style macros,     property lists, string ports and bidirectional ports, shell-style     `tilde expansion' in filenames, an interactive top-level written     in Scheme, a Scheme debugger and a pretty printer, arbitrary length     bitstrings, and Scheme records.   o  Comprehensive documentation      The distribution includes 230+ pages of fully indexed documentation.     All manuals exist as troff input files which can be translated to HTML     (with `unroff') for online browsing in addition to producing typeset-     quality printed versions.   o  Distributed in legally unencumbered form      The copyright/license agreement permits free redistribution and use     of Elk in commercial products.  Why is Elk using Scheme?------------------------ As extensions can get as large and complex as freestanding programs,extension language programmers (usually the users of the application)deserve the same language features that other programmers areaccustomed to.  By using a general-purpose programming language ratherthan a specialized scripting language, non-trivial extensions canbenefit from the structuring functionality inherent in real programminglanguages (such as Lisp). Members of the Lisp language family are particularly suitable as anextension language:  Lisp has a simple syntax but powerful semantics,it allows for small implementations, and its interactive naturesupports rapid prototyping and encourages users to explore and testsolutions to problems in an incremental way. Consequently, Lisp has become increasingly popular for this purpose, tothe point where the abundance of different dialects has grown into aproblem.  Of the standardized dialects of Lisp, only Scheme is suitablymodest, yet sufficiently general, to serve as a reusable extensionlanguage for a wide range of applications.  Scheme is orthogonal andwell-defined, and it is small enough to not dominate the application itserves and to be fully understood with acceptable effort.  The Elk distribution-------------------- Here is a brief roadmap for the subdirectories and files included inthe distribution.  elk-3.0 --+-- README      Explains the purpose and release status of Elk          |          +-- CHANGES     Lists the changes between this and earlier releases          |               of Elk          |          +-- MIGRATE     Explains how C/C++ code (applications or extensions)          |               written for older versions of Elk may have to be          |               modified to make it work with this version          |          +-- INSTALL     Instructions for configuring, compiling, and          |               installing Elk; a brief description of the files that          |               get installed in the process; and a description of          |               the structure of the Makefiles and the purpose of          |               Makefile.local and `build' in each source directory          |          +-- MACHINES    Additional, platform-specific advice for installing          |               and using Elk, such as compiler bugs, unsupported          |               features, problems with older OS versions and other          |               pitfalls          |          +-- BUGS        Information about known problems with this release          |          +-- TODO        Ideas, improvements and projects for future releases          |          +-- COPYING     The copyright status of the distribution          |          +-- AUTHORS     A list of people who have contributed significantly          |               to Elk; acknowledgments and credits          |          +-- include/    The include files to be #included by applications          |               that use Elk as their extension language, and by          |               extensions to Elk.  Including scheme.h from this          |               directory causes all the other .h files to be          |               included in the right order.  The include files may          |               or may not use ANSI/ISO-C prototypes, depending on          |               the config file you have chosen.          |          +-- src/        The C source files of the Scheme interpreter          |          +-- scm/        Scheme files that are loaded during runtime.  These          |               are copied to a destination directory specified in          |               config/site when Elk is installed.          |          +-- lib --,     This directory tree holds the C source for various          |         |     Elk extensions that can be loaded into the Scheme          |         |     interpreter or linked with an application          |         |          |         +-- xlib/  The C source files of the X11 Xlib extension          |         |          |         +-- xt/    The C source files of the Xt (X11 Toolkit          |         |          Intrinsics) extension          |         |          |         +-- xaw/   The Scheme interfaces to the X11 Athena widgets.          |         |          There is one .d file for each widget class.          |         |          Each of these is compiled into a C source file          |         |          when running `make' and then compiled into a          |         |          dynamically loadable object.          |         |          |         +-- xm/    The .d files for the Motif widgets          |         |          |         +-- unix/  The C source files of the UNIX extension          |         |          |         `-- misc/  The C source files of the record extension, the          |                    bitstring extension, the regular expression          |                    extension, and various other dynamically          |                    loadable Elk extensions          |          +-- doc/        The directory tree holding the documentation for          |               Elk as troff input files and pre-generated          |               PostScript files.  See doc/README for a roadmap          |               of the `doc' tree.          |          |          +-- examples --,   A collection of demonstration programs for Elk          |              |   and the various extensions (mostly in Scheme)          |              |          |              +-- scheme  Basic Scheme demos (collected from USENET          |              |           and other sources)          |              |          |              +-- xlib    Programs demonstrating the Xlib, Athena,          |              +-- xaw     and Motif extensions          |              +-- xm          |              |          |              +-- unix    Example programs for the UNIX extension          |              |          |              +-- regexp  A demonstration of the regexp extension          |              |          |              `-- c++     A few simple C++ programs demonstrating          |                          use of Elk with C++ applications (see          |                          README in this directory)          |          `-- util/       Various utilities, some of which may aid in preparing                          a config file for an as yet unsupported platform.  

Here is the 1 million digit fabonacci in Elk. It took an hour and 15 minutes in ScriptBasic native.


--- Code: Scheme ---; Fibonacci using fast doubling formulas, good for millions of digits!(define (fibo n)    (cond        ((= n 0) 0)        ((= n 1) 1)        (else             (let*                (                    (k (quotient n 2))                    (a (fibo k))                    (b (fibo (- k 1)))                )                 (if (even? n)                    (* a (+ (* 2 b) a))                    (let*                        (                            (2a (* 2 a))                            (c (* (+ 2a b) (- 2a b)))                        )                         (if (= (modulo n 4) 1)                            (+ c 2)                            (- c 2)                        )                    )                )            )        )    ))(Display (fibo 4784969)) 

jrs@jrs-laptop:~/sb/examples/test$ time elk -l elkfibo.scm > elkfibo.out

real   11m1.066s
user   11m0.855s
sys   0m0.016s
jrs@jrs-laptop:~/sb/examples/test$ ls -l elkfibo.out
-rw-r--r-- 1 jrs jrs 1000000 May 27 18:40 elkfibo.out
jrs@jrs-laptop:~/sb/examples/test$ tail -c64 elkfibo.out
6330930391815964864885353407167474856539211500699706378405156269
jrs@jrs-laptop:~/sb/examples/test$


Mike Lobanovsky:

--- Quote from: John on May 27, 2019, 06:33:01 pm ---... TinyScheme ... produced the wrong answer.
--- End quote ---

No wonder. TinyScheme has no BIGINT support, and it can only perform calc on, and print, numeric quantities it supports natively, of which double precision is the largest.

And thanks but no, I am not interested. Elk is a full scale ...NIX-oriented project with only minimal support for Windows. It can probably take one's lifetime to develop and maintain a Windows fork of it as a hobby, which isn't exactly my idea of bumming around in the declension of my years. ;)

John:
Actually TinyScheme wasn't at fault, it was the users Scheme code. Thanks for your feed back on Elk.

Mike Lobanovsky:
What does a corrected version of Scheme script look like, please?

John:
Here is a Fibonacci Scheme example that works great in TinyScheme.

Heater@RPi  posted the funky Scheme code that made me think TinyScheme was broken.

I think ScriptBasic and Scheme would make a very powerful language.

RPI Post

Navigation

[0] Message Index

[#] Next page

Go to full version