About Ravi
Premiers pas avec Ravi
Scheme Tutorial
Objets Scheme
Le shell ravi
Starting Ravi
Le module trace
Les ports d'E/S
The C Parser
load, require, modules
Système d'interruptions
Scheme compiler
C++ mode
Generating C++ Modules
La déclaration struct
Le type "C-object"
More information


C++ mode

C++ mode makes the Ravi shell act as a C++ interpreter. The interpreter reads a "command" which must be a single C/C++ instruction, executes it, and prints the result.

Let's look at a simple session of ravi in C++ mode: This example uses the modpoint module presented in module generation

 ravi -mod c++
 require( modpoint0);     // loading the module

:>help(Point); // getting help about class Point is C++class Module : modpoint0 parent class: #f methods are: 1 GetX 2 GetY 3 SetX 4 SetY 5 Set 6 (c-operator -=) 7 ObjectInfo 8 constructor

:>help( 6); Point::(c-operator -=) defined with 1 profile(s): Point * operator-=(Point &);

:>p1=new Point(3,4); // creating a point <Point : (3 4)> :>p1.GetX(); // calling a method 3 :>p2=new Point(p1); <Point : (3 4)> :>p2.SetX(12); // calling another method :>p2; <Point : (12 4)>

Short notice

Usefull ways to activate C++ mode

ravi [-v] -mod c++ -scheme-trace [filename ...]

Switching between C++ mode and Lisp mode

The command scheme switches from C== to Lisp/Scheme. The function (c++-toplevel) switches from Scheme to C++.

Simplification of C++ syntax

In order to simplify interactive use, c++ mode accepts a modified C++ syntax.

  • You may omit the semi-colon at the end of a command, it is added automatically. This implies your command is given on a single line. As with preprocessor commands, this line may be extended using the backslash character a the end.

  • You may omit the parentheses for 1-argument functions.

This is very practical - the follwing 3 lines are strictly equivalent:

help Point

Scheme compatibility

Under C++ mode you have access to all parts of the Ravi environment, which includes (actually, it initially IS) a complete Scheme system. This has an annoying consequence: in Scheme, the hyphen (minus sign) is traditionnally used to separate the syllables of a symbol, rather than the underscore character used in C. This means Scheme identifiers are not legal identifiers in C. For this reason, the minus sign in C++ mode has the special property of being considered a letter if it follows a letter or digit. This can be annoying inside arithmetic expressions.

You can give the - sign its "pure C" syntax ...

Using Scheme functions in C++ mode

:>v=make-vector 10 #(() () () () () () () () () ()) :>vector-length v 10 :>v[3]=19 19 :>v[3]*v[3] 361 :>string-length "imag" 4