The cltcl Reference Manual

This is the cltcl Reference Manual, version 0.0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Mon Feb 26 16:03:06 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 cltcl

Embed Tcl/Tk scripts in Common Lisp

Author

Paul Griffioen

License

MIT, see file LICENSE

Version

0.0.1

Source

cltcl.asd.

Child Components

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


3.1 Lisp


3.1.1 cltcl/cltcl.asd

Source

cltcl.asd.

Parent Component

cltcl (system).

ASDF Systems

cltcl.


3.1.2 cltcl/package.lisp

Source

cltcl.asd.

Parent Component

cltcl (system).

Packages

cltcl.


3.1.3 cltcl/cltcl.lisp

Dependency

package.lisp (file).

Source

cltcl.asd.

Parent Component

cltcl (system).

Public Interface
Internals

3.1.4 cltcl/communication.lisp

Dependency

cltcl.lisp (file).

Source

cltcl.asd.

Parent Component

cltcl (system).

Public Interface

3.1.5 cltcl/protocol.lisp

Dependency

communication.lisp (file).

Source

cltcl.asd.

Parent Component

cltcl (system).

Public Interface
Internals

4 Packages

Packages are listed by definition order.


4.1 cltcl

Source

package.lisp.

Use List
  • common-lisp.
  • common-lisp-user.
Public Interface
Internals

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


5.1 Public Interface


5.1.1 Special variables

Special Variable: *debug*

If not nil the commands of a script are send one by one to the interpreter. This eases localization of errors. Default nil.

Package

cltcl.

Source

protocol.lisp.

Special Variable: *interpreter*

The default Tcl/Tk interpreter. Default value is /usr/bin/wish.

Package

cltcl.

Source

protocol.lisp.

Special Variable: *stream*

A two-way-stream connected to a Tcl/Tk interpreter or NIL if no such interpreter is running. This stream is used by functions CALL, POST and RUN.

Package

cltcl.

Source

protocol.lisp.

Special Variable: *trace-level*

An integer that determines which events are traced in clTcl’s communication protocol between Lisp and Tcl/Tk. Setting a larger number gives trace messages. Level -1 (the default) is complete silence, level 0 is errors only, level 1 is errors and events, level 2 is errors, events and event details.

Package

cltcl.

Source

protocol.lisp.


5.1.2 Macros

Macro: with-tcl/tk ((var &rest args) &body body)

Uses OPEN-TCL/TK-STREAM to start a Tcl/Tk interpreter and connect to it by a two-way stream. Arguments ARGS are used as keyword arguments to OPEN-TCL/TK-STREAM. The forms in BODY are evaluated as an implicit progn with VAR bound to the stream returned by OPEN-TCL/TK-STREAM. When control leaves the body, either normally or abnormally, the stream is closed with CLOSE-TCL/TK-STREAM.

Package

cltcl.

Source

communication.lisp.


5.1.3 Ordinary functions

Function: call (command &rest args)

Calls Tcl/Tk command COMMAND with arguments ARGS properly escaped. Arguments of type symbol are writting to a string and prefixed with a hyphen to support keyword for Tcl options. Other arguments are written to string if necessary and properly escaped. This function is typically used in a event that was invoked in a clTcl script run by EVENT-LOOP. Sends the command to *STREAM*.

Package

cltcl.

Source

protocol.lisp.

Function: close-tcl/tk-stream (stream)

Instructs the Tcl/Tk process associated with STREAM to exit and closes the stream. Arguments STREAM must be a stream created by OPEN-TCL/TK-STREAM. This function is implementation dependent.

Package

cltcl.

Source

communication.lisp.

Function: escape (x)

Escapes all characters that have a special meaning for Tcl (includes whitespace) with a backslash.

Package

cltcl.

Source

cltcl.lisp.

Function: event-loop (script &key interpreter options arguments)

Starts Tcl/Tk interpreter located at INTERPRETER, binds *STREAM* to the stream that connects to Tcl/Tk, binds *INTERPRETER* to INTERPRETER, runs SCRIPT on ARGUMENTS and starts listening on the stream. Use command ’exit’ to end the listener. Establishes a binding for restart KEEP-LISTENING to recover from errors in an event handler. The default value for INTERPRETER is *INTERPRETER. Keyword OPTIONS is passed to the interpreter.

Package

cltcl.

Source

protocol.lisp.

Function: format-script (script &rest args)

Applies function FORMAT to SCRIPT’s commands sequentially. Each element consumes its required formatter arguments from ARGS, leaving the rest of the arguments for the rest of the commands. For clTcl script written with #TCL[...] this gives the effect of a single format on the entire Tcl code.

Package

cltcl.

Source

cltcl.lisp.

Function: keep-listening ()

A restart applicable during errors in events. Transfers control back to Tcl and resumes listening.

Package

cltcl.

Source

protocol.lisp.

Function: open-tcl/tk-stream (&key interpreter options)

Starts a Tcl/Tk interpreter and creates and returns a two-way stream connected to this Tcl/Tk process. This function and the meaning of arguments INTERPRETER and OPTIONS are implementation dependent.

Package

cltcl.

Source

communication.lisp.

Function: post (command &rest args)

Posts Tcl/Tk command COMMAND with arguments ARGS properly escaped as an event and does not wait for a reply. Arguments of type symbol are writting to a string and prefixed with a hyphen to support keyword for Tcl options. Other arguments are written to string if necessary and properly escaped. Sends the command to *STREAM*.

Package

cltcl.

Source

protocol.lisp.

Function: read-list (&optional stream terminator)

Reads a Tcl list from STREAM. Reads Tcl words until an end of file occurs or READ-WORD finds TERMINATOR (when given), a semi-colon or a newline. The Tcl list is returned as a string. The default value for STREAM is *STANDARD-INPUT*. Returns NIL if end of file is found immediately.

Package

cltcl.

Source

cltcl.lisp.

Function: read-script (&optional stream terminator)

Reads a Tcl script from STREAM. Reads Tcl commands until READ-LIST finds TERMINATOR (when given) or an end of file occurs. Returns the commands as a list of strings. The default value for STREAM is *STANDARD-INPUT*.

Package

cltcl.

Source

cltcl.lisp.

Function: read-tcl-list-from-string1 (string)

Converts Tcl list STRING into a list of strings. Items are delimited by whitespace.

Package

cltcl.

Source

cltcl.lisp.

Function: read-word (stream &optional eof-error-p eof-value recursive-p terminator echo-p)

Reads a Tcl word from STREAM and returns it as a string. Reads characters untill the next one is a terminator. The terminator itself is not read. Terminators are TERMINATOR (when given), whitespace or Tcl list terminators. Throws an error if an end of file occurs, unless EOF-ERROR-P is nil, in which case it returns EOF-VALUE. If ECHO-P is non nil then escape characters are not handled and the word is literally copied.

Package

cltcl.

Source

cltcl.lisp.

Function: receive-line (stream)

Reads a Tcl list from STREAM including the terminating character. Returns nil if an end of file occurs.

Package

cltcl.

Source

communication.lisp.

Function: repl ()

A read-eval-print loop. Useful for development. Prompts for commands to send to the Tcl/Tk interpreter and prints the reply.

Package

cltcl.

Source

protocol.lisp.

Function: run (script &rest args)

Sends SCRIPT via *STREAM* to Tcl/Tk and waits for a reply. This function is typically used in a event that was invoked in a clTcl script run by EVENT-LOOP. Sets Tcl/Tk variable argv to ARGS, properly escaped.

Package

cltcl.

Source

protocol.lisp.

Function: send-script (stream script)

Sends clTcl script SCRIPT to a running Tcl/Tk interpreter via stream STREAM. The stream must be one that was opened with OPEN-TCL/TK-STREAM. The script must be a list of strings, each string being a valid Tcl command.

Package

cltcl.

Source

communication.lisp.

Function: write-list-to-tcl-string (list)

Converts list to a Tcl string. Nested lists are converted recursively. Strings are escaped. Other values are written to string and escaped.

Package

cltcl.

Source

cltcl.lisp.


5.2 Internals


5.2.1 Ordinary functions

Function: clean-script (script)

Removes all empty strings and comments from command list SCRIPT.

Package

cltcl.

Source

cltcl.lisp.

Function: funa ()

Helper for TEST

Package

cltcl.

Source

protocol.lisp.

Function: func ()

Helper for TEST

Package

cltcl.

Source

protocol.lisp.

Function: handle-event (event)

Handles EVENT that was read from a Tcl/Tk stream. Calls the requested Lisp function and returns the results. Restart KEEP-LISTENING is available during the event.

Package

cltcl.

Source

protocol.lisp.

Function: handshake (stream)

Sends a message to Tcl/Tk stream to test if it responds. Throws an error when no appropriate message comes back.

Package

cltcl.

Source

protocol.lisp.

Function: listen-for-reply (stream)

Receives messages from STREAM until a reply is received. Incoming events and errors are handled. Returns the data from the reply.

Package

cltcl.

Source

protocol.lisp.

Function: log-status (level control-string &rest arguments)

Writes formatted text to *TRACE-OUTPUT* if LEVEL is at least as high as *TRACE-LEVEL*. Level 0 is for errors, level 1 is for events, level 2 is for event details.

Package

cltcl.

Source

protocol.lisp.

Function: message-data (message)

The data of the message obtained with RECEIVE-MESSAGE. The contents depends on the type of message.

Package

cltcl.

Source

protocol.lisp.

Function: message-tag (message)

The tag of the message obtained with RECEIVE-MESSAGE. One of the symbols :reply, :event or :error.

Package

cltcl.

Source

protocol.lisp.

Function: read-braced (stream &optional echo-p)

Reads a Tcl braced expression from STREAM.

Package

cltcl.

Source

cltcl.lisp.

Function: read-comment (stream)

Reads a line of Tcl comment from STREAM but leaves the newline.

Package

cltcl.

Source

cltcl.lisp.

Function: read-double-quoted (stream &optional echo-p)

Reads a Tcl double quoted expression from STREAM.

Package

cltcl.

Source

cltcl.lisp.

Function: read-white-space (stream)

Reads white space from STREAM, except newlines.

Package

cltcl.

Source

cltcl.lisp.

Function: read-word-aux (stream eof-error-p terminator echo-p)

Helper for READ-WORD.

Package

cltcl.

Source

cltcl.lisp.

Function: receive-message (stream)

Attempts to read a message from stream. Functions MESSAGE-TAG yields the tag of the message. Function MESSAGE-DATA yields the data. Counterpart of Tcl proc sendMessage

Package

cltcl.

Source

protocol.lisp.

Function: run-repl (&rest args &key trace-level &allow-other-keys)

Stub to test function REPL. Demonstrates how the repl might be added to an application via an event-handler.

Package

cltcl.

Source

protocol.lisp.

Function: run-script (script &optional stream)

Sends a script directly to the Tcl/Tk interpreter and waits for a reply.

Package

cltcl.

Source

protocol.lisp.

Function: run-sub-script (script &optional stream)

Sends a script to the listener that triggered the event that triggered this call and waits for a reply. The script is picked up and evaluated by a listener at the Tcl/Tk side.

Package

cltcl.

Source

protocol.lisp.

Function: script-for-command (command arguments)

Script that performs command with all arguments safely escaped.

Package

cltcl.

Source

protocol.lisp.

Function: send-message (stream tag message)

Counterpart is Tcl proc receiveMessage

Package

cltcl.

Source

protocol.lisp.

Function: tcl/tk-setup-script ()

Script that creates Tcl procedures in Tcl/Tk to communicate to Lisp.

Package

cltcl.

Source

protocol.lisp.

Function: test (&rest args &key trace-level &allow-other-keys)

Tests the connection with Tcl/Tk and displays systems
information. Sets *TRACE-LEVEL* to TRACE-LEVEL. The other keywords are passed to the event handler. See OPEN-TCL/TK-STREAM for allowed keywords.

Package

cltcl.

Source

protocol.lisp.

Function: write-escaped (x stream)

Escapes all characters that have a special meaning for Tcl (includes whitespace) with a backslash.

Package

cltcl.

Source

cltcl.lisp.

Function: write-escaped-char (char stream)

Writes character CHAR to stream. Special Tcl escape characters \b, \f, \r,\n and \t are converted.

Package

cltcl.

Source

cltcl.lisp.

Function: write-tcl-string (object &optional stream recursivep)

Converts list to a Tcl string. Nested lists are converted recursively. Strings are escaped. Other values are written to string and escaped.

Package

cltcl.

Source

cltcl.lisp.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   C   E   F   H   K   L   M   O   P   R   S   T   W  
Index Entry  Section

C
call: Public ordinary functions
clean-script: Private ordinary functions
close-tcl/tk-stream: Public ordinary functions

E
escape: Public ordinary functions
event-loop: Public ordinary functions

F
format-script: Public ordinary functions
funa: Private ordinary functions
func: Private ordinary functions
Function, call: Public ordinary functions
Function, clean-script: Private ordinary functions
Function, close-tcl/tk-stream: Public ordinary functions
Function, escape: Public ordinary functions
Function, event-loop: Public ordinary functions
Function, format-script: Public ordinary functions
Function, funa: Private ordinary functions
Function, func: Private ordinary functions
Function, handle-event: Private ordinary functions
Function, handshake: Private ordinary functions
Function, keep-listening: Public ordinary functions
Function, listen-for-reply: Private ordinary functions
Function, log-status: Private ordinary functions
Function, message-data: Private ordinary functions
Function, message-tag: Private ordinary functions
Function, open-tcl/tk-stream: Public ordinary functions
Function, post: Public ordinary functions
Function, read-braced: Private ordinary functions
Function, read-comment: Private ordinary functions
Function, read-double-quoted: Private ordinary functions
Function, read-list: Public ordinary functions
Function, read-script: Public ordinary functions
Function, read-tcl-list-from-string1: Public ordinary functions
Function, read-white-space: Private ordinary functions
Function, read-word: Public ordinary functions
Function, read-word-aux: Private ordinary functions
Function, receive-line: Public ordinary functions
Function, receive-message: Private ordinary functions
Function, repl: Public ordinary functions
Function, run: Public ordinary functions
Function, run-repl: Private ordinary functions
Function, run-script: Private ordinary functions
Function, run-sub-script: Private ordinary functions
Function, script-for-command: Private ordinary functions
Function, send-message: Private ordinary functions
Function, send-script: Public ordinary functions
Function, tcl/tk-setup-script: Private ordinary functions
Function, test: Private ordinary functions
Function, write-escaped: Private ordinary functions
Function, write-escaped-char: Private ordinary functions
Function, write-list-to-tcl-string: Public ordinary functions
Function, write-tcl-string: Private ordinary functions

H
handle-event: Private ordinary functions
handshake: Private ordinary functions

K
keep-listening: Public ordinary functions

L
listen-for-reply: Private ordinary functions
log-status: Private ordinary functions

M
Macro, with-tcl/tk: Public macros
message-data: Private ordinary functions
message-tag: Private ordinary functions

O
open-tcl/tk-stream: Public ordinary functions

P
post: Public ordinary functions

R
read-braced: Private ordinary functions
read-comment: Private ordinary functions
read-double-quoted: Private ordinary functions
read-list: Public ordinary functions
read-script: Public ordinary functions
read-tcl-list-from-string1: Public ordinary functions
read-white-space: Private ordinary functions
read-word: Public ordinary functions
read-word-aux: Private ordinary functions
receive-line: Public ordinary functions
receive-message: Private ordinary functions
repl: Public ordinary functions
run: Public ordinary functions
run-repl: Private ordinary functions
run-script: Private ordinary functions
run-sub-script: Private ordinary functions

S
script-for-command: Private ordinary functions
send-message: Private ordinary functions
send-script: Public ordinary functions

T
tcl/tk-setup-script: Private ordinary functions
test: Private ordinary functions

W
with-tcl/tk: Public macros
write-escaped: Private ordinary functions
write-escaped-char: Private ordinary functions
write-list-to-tcl-string: Public ordinary functions
write-tcl-string: Private ordinary functions