tamgulispe is a powerful Lisp interpreter integrated into the Tamgu programming language. It provides a seamless way to incorporate Lisp functionality into Tamgu programs, offering a unique blend of Tamgu's features with Lisp's expressive power.
tamgulispe allows you to execute Lisp code within Tamgu, providing a bridge between the two languages. When you use tamgulispe, it replaces the current Lisp implementation in Tamgu. This means that all Lisp operations within your Tamgu program will use this new implementation, ensuring consistency and providing access to the full range of LispE features.
- Lisp Execution: Execute Lisp code directly within Tamgu programs.
- Seamless Integration: Easily pass Tamgu variables and data structures to Lisp code and vice versa.
- Full Lisp Power: Access to a wide range of Lisp functions and capabilities.
- Tamgu Interoperability: Combine Tamgu's unique features with Lisp's functional programming paradigm.
- Regular Function Calls: Call regular Tamgu functions from within LispE code, further enhancing the integration between the two languages.
Understanding how arguments are passed to eval
and execute
is crucial for effectively integrating Tamgu variables with LispE code. Both methods handle Tamgu variables by recreating them in the LispE space, allowing for seamless interaction between the two languages.
The key point to understand is that when Tamgu variables are passed to either eval
or execute
, they are not directly used. Instead:
- Variable Recreation: The Tamgu variables are recreated as new variables within the LispE environment.
- Type Conversion: The Tamgu variable types are converted to their closest LispE equivalents.
- Scope: These recreated variables exist only within the scope of the LispE evaluation and do not affect the original Tamgu variables.
This approach ensures a clean separation between the Tamgu and LispE environments while still allowing for data exchange.
The eval
method in tamgulispe is versatile in how it handles arguments:
-
Multiple Arguments:
eval
can take multiple arguments, which are processed sequentially.int a = 10; int b = 20; l.eval("(+ ", a, " ", b, ")"); // Evaluates to 30 in LispE
-
String Concatenation: When passing multiple arguments, they are effectively concatenated into a single LispE expression before evaluation.
-
Complex Data Structures: Tamgu containers (like vectors, maps) are recreated as corresponding LispE structures.
vector v = [1, 2, 3]; l.eval("(map (lambda (x) (* x 2)) ", v, ")"); // Returns (2 4 6) in LispE
-
Note the result of an
eval
is automatically converted into the corresponding Tamgu type.vector v = [1, 2, 3]; v = l.eval("(map (lambda (x) (* x 2)) ", v, ")"); // Returns (2 4 6) in LispE
The execute
method is typically used for evaluating expressions without any cleaning afterward. For instance, if you want to record a function, you can use execute
to do so. The argument passing is the same as eval
.
//Records a tst function in LispE.
l.execute("defun tst(a) (+ a 10))");
- Variable Isolation: Changes to recreated variables in LispE do not affect the original Tamgu variables.
- Type Matching: LispE attempts to match Tamgu types with the closest LispE equivalent.
- Scope Limitation: Variables recreated in LispE exist only for the duration of the
eval
orexecute
call.
// Tamgu code
int x = 5;
string s = "hello";
vector v = [1, 2, 3];
// Using eval
l.eval("(println ", x, " ", s, " ", v, ")");
// In LispE, this recreates x as a number, s as a string, and v as a list
// Using execute
l.execute("(defun double (x) (* x 2))");
l.execute("(double " + x + ")"); // Returns 10, but Tamgu's x is still 5
By understanding this recreation process, you can effectively design your code to leverage both Tamgu and LispE capabilities while maintaining clear boundaries between the two environments.
To use tamgulispe in your Tamgu programs:
-
Import the tamgulispe module:
use('tamgulispe');
-
Create a lispe object:
lispe l;
-
Execute Lisp code using the
execute
oreval
methods:l.execute("(defun xx (u) (+ u 3))"); println(l.execute("(xx 10)"));
Note: The main difference between
execute
andeval
is thateval
cleans up structures after use, whileexecute
does not. This means thateval
is more memory-efficient for one-time evaluations, whileexecute
may be more performant for repeated calls to the same Lisp code. -
Use the backslash (
\
) to directly embed Lisp expressions in Tamgu code:println(\(xx a)); println(\(+ (xx a) 3));
-
Pass Tamgu variables to Lisp code:
int a = 100; int b = 1000; println(l.eval("(+", a, b, "(xx", a, "))"));
-
Work with Tamgu data structures in Lisp:
treemap m; m["test"] = 10; m["truc"] = 20; l.eval(m, a, b); println(l.eval("(type m)"));
-
Call regular Tamgu functions from LispE:
// Assuming 'my_tamgu_function' is a defined Tamgu function l.eval("(my_tamgu_function 10 20)");
tamgulispe allows for complex interactions between Tamgu and Lisp, including:
- Defining and calling Lisp functions from Tamgu
- Using Tamgu data structures in Lisp code
- Evaluating Lisp expressions with Tamgu variables
- Seamless type conversion between Tamgu and Lisp
- Calling regular Tamgu functions from within LispE code
tamgulispe is based on LispE, a powerful and flexible Lisp implementation. When you use tamgulispe, it completely replaces the current Lisp implementation in Tamgu with LispE. This ensures that you have access to all LispE features and functionalities throughout your Tamgu program.
For a comprehensive understanding of LispE's capabilities and syntax, please refer to the official LispE documentation:
The LispE documentation provides in-depth information about:
- LispE syntax and semantics
- Available functions and macros
- Advanced features and optimizations
- Examples and use cases
By leveraging tamgulispe, you can harness the full power of LispE within your Tamgu programs, creating a uniquely powerful programming environment that combines the strengths of both languages. The ability to call regular Tamgu functions from LispE code further enhances this integration, allowing for seamless interoperability between the two languages.