From: Niels P. Mayer
Subject: Re: lisp / C code integration + Xwindows
Date: 
Message-ID: <NPM.94Aug4231326@collage.eitech.com>
From: ······@cssc-syd.tansu.com.au (Chris Bitmead)
> My main question is, if I continue to investigate using lisp, for my
> project, pretty soon I'm probably going to want to integrate some of my
> own C code into lisp. Is there any standard's for how to do this, or is
> every implementation going to be different?

While there might be similarities for very simple foreign function
interfaces, those similarities don't really matter much for the task of
interfacing arbitrary C code to full-blown Common Lisp systems. This is
especially true if your C code is non-trivial: for example, C-code that can
dive into your complicated Lisp data structures (or objects) and pull out
the appropriate C-data.  Or C-code that returns complicated Lisp data
structures (e.g. objects, closures, etc) back to Lisp.

Such interface tasks are often easier in other "hybrid" C/Lisp
imlementations.  I know that it is quite easy to do this kind of hybrid
programming from my experience in building WINTERP (the OSF/Motif Widget
INTERPreter) from David Betz's XLISP and XLISP-PLUS (David Betz, Tom Almy,
Luke Tierney, et al). Likewise, Elk, XSCHEME, SCM, etc. also make it easier
to do hybrid programming.

For an example of instructions on adding C-extensions to a Lisp
interpreter, see Jeff Prothero's Guide on XLISP internals, which available
on the Web: http://www.eit.com/software/winterp/doc/XlispImpl.doc

> On a related note, I'd like to try and do some X windows programing in
> lisp. Preferably Motif. I assume whatever packages that exist for this are
> written in C. Would they only work with one variety of lisp? Can anyone
> recommend what I should use to program in X?

You should check out WINTERP 2.0, if you are interested in an integrated,
object-oriented, high-level, Lisp-based UI development environment. WINTERP
directly integrates Motif, Object-Oriented Animation/Graphics (Xtango), and
Unix subprocess facilities with the XLISP interpreter. It is good for
developing and delivering hybrid Lisp/C applications, and for
rapid-prototyping applications. WINTERP is positioned to compete against
systems like Tcl/Tk, Python etc for building and delivering UI-based
applications. In other words, it is a relatively small system given that it
contains a Lisp providing a workable subset of Common Lisp -- larger than
Tcl/Tk, but similar in size to Python.  (more info on WINTERP given below,
or via WWW -- http://www.eit.com/software/winterp/winterp.html, or
via anonymous ftp -- ftp.x.org:/contrib/devel_tools/winterp-2.03.tar.gz)

If you want to do Motif GUIs based on a full-blown Common Lisp system, you
might want to check out CLM/Gina. This uses a separate UI server which
hooks onto your Common Lisp via sockets. This is a reasonable portability
compromise for hooking up X/Motif to Common Lisp -- Motif, X, and the
Xtoolkit wants to force an event-driven view of the world onto all programs
it subsumes; Common-Lisp, on the other hand, wants to remain in control as
well. So CLM/Gina enables both of those "control freaks" to interoperate
without seriously tearing into your Common Lisp implementation
specifics. On the other hand, CLM/Gina's configuration does tend to force
quite a few context switches, which can make response sluggish on
lightweight, low-memory, or loaded systems (X server context switches
against Motif UI server and context switches against the
application/Common-Lisp itself). On the other hand, if you've got multiple
machines, and/or multiple processors, this may be a good way to split up
the work-effort.

WINTERP can also be used to build a Motif front end for arbitrary programs
(including one or more Common Lisp programs) by running interactive Unix
subprocesses. WINTERP provides some high-level interfaces which allow a
subprocess to remain busy computing without blocking the WINTERP-generated
UI. The facility allows calling arbitrary code in WINTERP's interpreter
once-per-line of output, or once-per-s-expression of output from the
subprocess. You can send data to the subprocess by just writing to a
stream, for example, using FORMAT.

Finally, WINTERP includes a socket-based Lisp listener (unix domain, or
optionally, internet domain), which allows other programs or scripts to
send s-expressions to WINTERP for evaluation by the 'wl' executable. 'wl'
returns the result of evaluation on it's stdout.

> Oh, and I'd like to try out CLOS programing. Preferably in conjunction
> with X.

WINTERP directly represents the Motif widget hierarchy as a class hierarchy
in XLISP. It provides a smalltalk-inspired object system to allow you to
easily create new widget classes, subclass existing functionality,
etc. Additionally, the Xtango graphics/animation image classes (e.g.
circle, line, spline, polyline, text, bitmap, etc) allow you to create,
manipulate, compose, and animate geometric entities as objects.

WINTERP 2.0 includes a class-library which simplifies the contruction of
Motif GUI applications. For example, a class that encapsulates the
boilerplate aspects of creating your typical XmMainWindow-based application
window, a class to simplify the contruction of menubars, and pulldown or
popup menu items. Also included are classes that simplify the contruction
of list-browser interfaces, message-windows, etc.

WINTERP ain't CLOS, but that's ok. It's hard enough to get your average
stoopid TCL-head to understand that Lexical scoping and closures might be a
good idea, so I wouldn't want to give people anything as complex as CLOS,
despite its cool features. 

==============================================================================

Some information on WINTERP, taken from
http://www.eit.com/software/winterp/winterpIS.html...

                  WINTERP -- The OSF/Motif *W*idget *INTERP*reter
   
by Niels Mayer [http://www.eit.com/people/mayer.html]
            Enterprise Integration Technologies
            800 El Camino Real, Fourth Floor
            Menlo Park, CA 94025
            e-mail: ·····@eit.com

               WINTERP home page
               [http://www.eit.com/software/winterp/winterp.html]
   
   WINTERP is the OSF/Motif Widget INTERPreter, an application development
   environment enabling rapid prototyping of graphical user-interfaces (GUI)
   through the interactive programmatic manipulation of user interface objects
   and their attached actions. WINTERP is also an excellent platform for
   delivering extensible or customizable applications. By embedding a small,
   efficient Lisp interpreter with UI primitives within the delivered
   application, users and system integrators can tailor the static and dynamic
   layout of the UI, UI/application dialogue, and application functionality.
   
               WINTERP is a good tool for learning and experimenting with the
   capabilities of the OSF/Motif UI toolkit, allowing UI designers to more
   easily play "what if" games with different interface styles. WINTERP's
   implementation provides a compromise between the prototyping and
   extensibility advantages of Lisp environments, and the inefficiency and
   expenses of delivering Unix applications under environments such as Common
   Lisp. Typically, prototyping and customization are done entirely in
   interpreted Lisp; for delivery, efficiency-critical low-level code may be
   written in C and is easily exported to the interpreter as a new primitive.
   
               WINTERP was first made publicly available on the X11r4 "contrib"
   distribution and new releases have appeared on the X11r5 and X11r6
   distribution. The recent X11r6 release of WINTERP 2.0 significantly improves
   on previous releases by providing a variety of developer tools and libraries
   for increased productivity. Improved functionality is delivered via
   object-oriented graphics and 2.5D animation, asynchronous subprocesses, the
   XmGraph widget (for creating directed acyclic graphs, trees, and
   direct-manipulation displays), the Table widget (GUI layout using
   tbl(1)-style specifications), GIF support, etc.
   
               WINTERP's interpreter is based on David Betz, Tom Almy, Luke
   Tierney et al's XLISP-PLUS. The interpreter's Smalltalk-inspired object
   system enables a truly object oriented interface to the X11 toolkit
   Intrinsics (Xt) and the OSF/Motif widget set.  WINTERP's use of a real
   programming language for customization/prototyping allows WINTERP based
   applications to be much more flexible than applications using lower-level
   and less-general languages provided by the X resource database,
   Brunecky&Smythe's Widget Creation Library (WCL), OSF/Motif's UIL (user
   interface language), and Ousterhout's TCL/Tk. Furthermore, the use of
   object-orientation at a fundamental level within the application UI code
   allows WINTERP-based applications to scale more effectively than other
   languages.
   
               WINTERP 2.0 features an object-oriented 2.5D graphics and
   animation "widget" based on John Stasko's Xtango path transition paradigm.
   Both for static and dynamic graphics, this high-level interface simplifies
   and abstracts away much of the low-level drudgery required to create 2.5 D
   graphics interfaces -- smooth, flicker free display updates occur as complex
   nonrectangular graphical objects move around and obscure and uncover each
   other. Animation composition operations allow multiple individual shapes to
   all move "simultaneously" through sequences of animation frames. The
   graphics are pixel-independent and easily resizeable, scalable and zoomable.
   Each primitive graphics image class supports its own set of class specific
   animation and movement methods, while some operations (e.g. movement, fill,
   etc) are polymorphic. The following primitive objects are supported:
   
       Line (w/ color, forward-arrow, backward-arrow, bidirectional-arrow,
        thickness, and style options);
      
       Rectangle (w/ color, fill options);
      
       Circle (w/ color, fill options);
      
       Ellipse (w/ color, fill options);
      
       Polygon (w/ color, fill options);
      
       Polyline (w/ color, forward-arrow, backward-arrow, bidirectional-
        arrow, line style, line-thickness options);
      
       Spline (w/ color, line-style and line-thickness options)
      
        Text (w/ font, color, and centering options)
      
       Bitmaps and Bitmap movies
      
       GIF images.
      
   The primitive graphics classes may also be contained in a composite image
   class, which provides a grouping and layering principle for new classes
   presenting multiple images. Composite images allow the construction of
   independent layers of animation objects which may be operated on in groups.
   
               WINTERP's graphics capabilities enable simple game-style
   animation, employing multiple layers of arbitrarily shaped objects.
   Furthermore, application-specific interactive-graphics capabilities may be
   encapsulated into a new Widget-Class. This significantly simplifies the
   creation and integration of new graphics widgets into the system -- these
   special widgets look like normal Motif widgets to the rest of the system.
   
               To enable GUI-applications based on existing Unix facilities,
   WINTERPprovides primitives for collecting data from Unix processes, and
   facilities for interacting with other Unix processes. These facilities make
   it possible to glue together existing Unix functionality into a GUI based
   application with a relatively small amount of WINTERP-Lisp "glue".
   WINTERP2.0 features the ability to run multiple interactive, asynchronous
   Unix subprocesses without blocking GUI interactivity. This feature is useful
   for creating GUI interfaces to existing terminal-based programs, and can
   also be used for connecting to interactive network services and databases.
   
               An environment similar to WINTERP's already exists in the
   Gnu-Emacs text editor -- WINTERP was strongly influenced by Gnu-Emacs's
   successful design. In Gnu-Emacs, a mini-Lisp interpreter is used to extend
   the editor to provide text-browser style interfaces to a number of Unix
   applications (e.g. e-mail user agents, directory browsers, debuggers, etc.).
   Whereas Emacs-Lisp enables the creation of new applications by tying
   together C Implemented primitives operating on text-buffer UI objects,
   WINTERP-Lisp ties together operations on graphical UI objects implemented by
   the Motif widgets. Both achieve a high degree of customizability that is
   common for systems implemented in Lisp, while still attaining the speed of
   execution and (relatively) small size associated with C-implemented
   applications.
        
   
WINTERP features:

       Free with non-restrictive copyright -- available via anonymous
          ftp from ftp.x.org, directory contrib/devel_tools, file
          winterp-2.XX.tar.gz.
      
       Portable -- entirely implemented via machine independent C
          source and X11/Xt/Motif libraries.
    
       OSF/Motif widgets are real XLISP objects widgets can be specialized
          via subclassing, methods added or altered, etc.
      
       Automatic storage management (via garbage collection) of Motif/Xt/X
          data, animation and graphics data, and application resources.
      
       Contains facilities for simple "direct manipulation" of UI
          components.
      
       Interface to Gnu Emacs's lisp-mode allows code to be developed and
          tested without leaving the editor.
      
       Interactive programing also available in the "WINTERP Control Panel",
          with editing taking place in a Motif text widget controlled by
          WINTERP.
      
       Built-in RPC mechanism for inter-application communications,
          implemented via serverized, event-driven Lisp interpreter.
      
       XmGraph widget for creating directed acyclic graphs, trees, and
         direct-manipulation displays.
      
       Table widget allows constraint-based GUI static layout             using
      tbl(1)-style specifications.
      
  REFERENCES ON WINTERP, AND ITS COMPONENTS:
  
        David Michael Betz.  "XLISP: An Object-oriented Lisp (version 2.1)"
   Unpublished documentation accompanying the public release of Xlisp
   software.  David Michael Betz, P.O. Box 144, Peterborough, NH 03458,
   April, 1989.
   
                Olaf Heimburger. "Elche Im Winter -- Interaktive
   X-Applicationbuilder         unter Lisp -- Elk und WINTERP." iX, July 1991,
   pp 64-68.
   
                Niels P. Mayer, Allan W. Shepherd and Allan J. Kuchinsky.
   "Winterp:    An object-oriented, rapid prototyping, development and delivery
        environment for building extensible applications with the OSF/Motif
   UI Toolkit."  In Proceedings Xhibition '90, X Window System and Open
   Systems Technical Conference, San Jose, CA, May 1990, pp 49-64.
   
                Niels P. Mayer, Allan W. Shepherd and Allan J. Kuchinsky.  The
   WINTERP Widget INTERPreter -- An Application Prototyping and
   Extension Environment for OSF/Motif.  In Proceedings X Into The Future,
   The European X Users Group Autumn Conference 1990, Surrey, UK,
   September 1990, pp. 33-55.
   
                Niels P. Mayer.  The WINTERP Widget INTERPreter -- A Lisp
   Prototyping  and Extension Environment for OSF/Motif-based Applications and
   User-Interfaces. Lisp Pointers, ACM SIGPLAN, Volume IV, Number 1,    pp
   45-60.
   
           Niels P. Mayer.  The WINTERP OSF/Motif Widget INTERPreter -- A
     graphical user-interface language for rapid prototyping and
   delivering extensible applications.  In Proceedings Motif '91,         First
   Annual International Motif Users Meeting, Washington DC,         December
   1991, pp.  248-269.
   
        John T. Stasko. The Path-Transition Paradigm: A Practical Methodology
   for Adding Animation to Program Interfaces.  Journal of Visual
   Languages and Computing. (date, volume, page, publisher info unknown).
   
        Don Libes.  Expect: Curing Those Uncontrollable Fits of Interaction,
   Proceedings of the Summer 1990 USENIX Conference, Anaheim, CA, June
   11-15, 1990.
   
  PAPERS DESCRIBING APPLICATIONS WRITTEN USING WINTERP:
  
        Allan Shepherd, Niels Mayer, and Allan Kuchinsky.  STRUDEL: An
   Extensible Electronic Conversation Toolkit. In David Marca and
   Geoffrey Bock, editors, GROUPWARE: Software for Computer-Supported
   Cooperative Work, IEEE Computer Society Press, 1992, pp. 505-518.
   (originally, in proceedings Conference on Computer-Supported
   Cooperative Work, Los Angeles, October 1990, pp. 93-104.)
   
                Jay Glicksman, Glenn Kramer, and Niels Mayer. "Internet
   Publishing via       the World Wide Web". In proceedings Groupware '94,
   August 1994. San     Jose, CA.
   ___________________________________
   
                                                                  ·····@eit.com
                                                                               
   
                                                                               
   
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
= Niels Mayer ..... ·····@eit.com .... http://www.eit.com/people/mayer.html =
=  Multimedia Engineering Collaboration Environment (MM authoring for WWW)  =
=  Enterprise Integration Technologies, 800 El Camino Real, Menlo Park, CA  =
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=