Vix.cpp v2.6.0 is here Read the blog
Skip to content

Vix Reply

Interactive REPL engine for Vix.

Vix Reply powers the vix and vix repl interactive experience. It provides a fast shell for testing expressions, variables, JSON values, runtime helpers, and real C++ snippets powered by the Vix run pipeline.

Start the REPL

Running vix without a command starts the REPL by default:

bash
vix
1

You can also start it explicitly:

bash
vix repl
1

To pass arguments into the REPL session, use --:

bash
vix repl -- --port 8080 --mode dev
1

Inside the REPL, those arguments are available with:

text
Vix.args()
1

Example startup

text
Vix Reply v2.5.6  REPL
gcc 13.3  linux
exit: Ctrl+D | clear: Ctrl+L | help

>>>
1
2
3
4
5

What the REPL is for

Use Vix Reply when you want to:

  • test small expressions
  • evaluate math quickly
  • create and inspect variables
  • validate JSON values
  • inspect environment values
  • call simple Vix runtime helpers
  • run real C++ snippets from an interactive session
  • prototype small ideas before moving them into a C++ file

Vix Reply is inspired by interactive shells from tools like Python, Node.js, and Deno, but adapted to the Vix.cpp workflow.

Basic commands

text
help
version
pwd
cd <dir>
clear
history
history clear
exit
1
2
3
4
5
6
7
8

You can also clear the screen with:

text
Ctrl+L
1

To exit, use:

text
exit
1

or:

text
Ctrl+D
1

Expressions

You can type expressions directly:

text
>>> 1 + 2
3

>>> 10 * (3 + 4)
70

>>> 100 / 5
20
1
2
3
4
5
6
7
8

You can also use calc explicitly:

text
>>> calc 10 * (2 + 3)
50
1
2

Variables

Assign a value:

text
>>> x = 42
42
1
2

Read it back:

text
>>> x
42
1
2

Use it in another expression:

text
>>> x + 1
43

>>> x * 10
420
1
2
3
4
5

String values are supported:

text
>>> name = "Gaspard"
name = "Gaspard"

>>> name
Gaspard
1
2
3
4
5

Other simple values are supported too:

text
>>> age = 25
age = 25

>>> price = 19.99
price = 19.99

>>> active = true
active = true
1
2
3
4
5
6
7
8

JSON values

Vix Reply supports strict JSON values.

Objects

text
>>> user = {"name":"Gaspard","age":25}
user = {"age":25,"name":"Gaspard"}

>>> user
{"age":25,"name":"Gaspard"}
1
2
3
4
5

Arrays

text
>>> nums = [10,20,30]
nums = [10,20,30]

>>> nums
[10,20,30]
1
2
3
4
5

Nested JSON

text
>>> profile = {"name":"Gaspard","meta":{"country":"UG","verified":true},"tags":["cpp","vix","reply"]}
profile = {"meta":{"country":"UG","verified":true},"name":"Gaspard","tags":["cpp","vix","reply"]}
1
2

Access object properties:

text
>>> user.name
Gaspard

>>> user["name"]
Gaspard
1
2
3
4
5

Access arrays:

text
>>> nums[0]
10

>>> profile.tags[1]
vix
1
2
3
4
5

JSON must be valid.

Wrong:

json
{"name","Gaspard"}
1

Correct:

json
{ "name": "Gaspard" }
1

Printing output

Use print():

text
>>> print("Hello")
Hello
1
2

Use println():

text
>>> println("Hello world")
Hello world
1
2

You can mix strings and values:

text
>>> x = 3
x = 3

>>> println("x =", x)
x = 3

>>> println("x + 1 =", x + 1)
x + 1 = 4
1
2
3
4
5
6
7
8

Supported examples:

text
print("hello")
println("hello", "world")
println(42)
println(-42)
println(3.14)
println(true)
println(null)
1
2
3
4
5
6
7

Built-in helpers

Vix Reply exposes simple helpers directly and through the built-in Vix object.

Current working directory

text
>>> cwd()
/home/user/project
1
2

or:

text
>>> Vix.cwd()
/home/user/project
1
2

Change directory

text
>>> Vix.cd("..")
1

Process id

text
>>> pid()
12345
1
2

or:

text
>>> Vix.pid()
12345
1
2

Environment variables

text
>>> Vix.env("HOME")
/home/user

>>> Vix.env("PATH")
/usr/local/bin:/usr/bin:/bin
1
2
3
4
5

REPL arguments

text
>>> Vix.args()
["--port","8080","--mode","dev"]
1
2

Create directories

text
>>> Vix.mkdir("tmp")
1

Create nested directories:

text
>>> Vix.mkdir("tmp/logs", true)
1

Exit with a code

text
>>> Vix.exit(0)
1

Value helpers

Length

text
>>> name = "Gaspard"
name = "Gaspard"

>>> len(name)
7
1
2
3
4
5
text
>>> nums = [10,20,30]
nums = [10,20,30]

>>> len(nums)
3
1
2
3
4
5
text
>>> user = {"name":"Gaspard","age":25}
user = {"age":25,"name":"Gaspard"}

>>> len(user)
2
1
2
3
4
5

Convert values

text
>>> int("42")
42

>>> int(42.0)
42

>>> float("3.14")
3.140000

>>> float(10)
10.000000

>>> str(25)
25
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Inspect types

text
>>> type(user)
object

>>> type(nums)
array

>>> type(user.name)
string

>>> type(nums[0])
int
1
2
3
4
5
6
7
8
9
10
11

C++ snippet mode

Vix Reply can run real C++ snippets through the normal Vix run pipeline.

Enter C++ mode:

text
>>> :cpp
C++ mode. Type :run to execute or :cancel to exit.
cpp>
1
2
3

Example:

text
>>> :cpp
C++ mode. Type :run to execute or :cancel to exit.
cpp> #include <vector>
...   #include <vix/print.hpp>
...   int main() {
...     vix::print("Hello, world", 2, true, std::vector<int>{1,2,3});
...   }
Hello, world 2 true [1, 2, 3]
1
2
3
4
5
6
7
8

Run a Vix HTTP server from the REPL

You can also start a small Vix HTTP server from C++ snippet mode:

text
>>> :cpp
C++ mode. Type :run to execute or :cancel to exit.
cpp> #include <vix.hpp>
...   using namespace vix;
...
...   int main() {
...     App app;
...
...     app.get("/", [](Request&, Response& res) {
...       res.send("Hello, world");
...     });
...
...     app.run(8080);
...   }
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Then test it from another terminal:

bash
curl http://localhost:8080
1

Expected output:

text
Hello, world
1

C++ mode commands

text
:cpp       Enter C++ snippet mode
:run       Run the current C++ snippet
:cancel    Cancel C++ snippet mode
1
2
3

Important note about C++ mode

Vix Reply is not a full C++ interpreter.

C++ snippet mode writes the snippet to a temporary .cpp file and runs it through vix run. This means the code is validated by the real C++ compiler and uses the normal Vix build, diagnostics, and runtime behavior.

The snippet must be valid C++ code.

For example, callbacks must use valid C++ lambda syntax:

cpp
app.get("/", [](Request&, Response& res) {
  res.send("Hello, world");
});
1
2
3

Common mistakes

Invalid JSON syntax

JSON objects require key: value pairs.

Wrong:

json
{"name","Gaspard"}
1

Correct:

json
{ "name": "Gaspard" }
1

Forgetting quotes around strings

Wrong:

text
>>> name = Gaspard
1

Correct:

text
>>> name = "Gaspard"
1

Passing REPL arguments without --

Wrong:

bash
vix repl --port 8080
1

Correct:

bash
vix repl -- --port 8080
1

Everything after -- is passed to the REPL session and becomes available through Vix.args().

Forgetting to close a C++ function call

Wrong:

cpp
app.get("/", [](Request&, Response& res) {
  res.send("Hello, world");
}
1
2
3

Correct:

cpp
app.get("/", [](Request&, Response& res) {
  res.send("Hello, world");
});
1
2
3

Common workflow

Start the REPL:

bash
vix
1

Try simple values:

text
>>> x = 10
10

>>> x * 2
20
1
2
3
4
5

Inspect the environment:

text
>>> Vix.cwd()
/home/user/project

>>> Vix.env("HOME")
/home/user
1
2
3
4
5

Check JSON:

text
>>> user = {"name":"Ada","role":"developer"}
user = {"name":"Ada","role":"developer"}

>>> user.role
developer
1
2
3
4
5

Run C++:

text
>>> :cpp
cpp> #include <vix/print.hpp>
...   int main() {
...     vix::print("Hello from C++");
...   }
Hello from C++
1
2
3
4
5
6

Exit:

text
>>> exit
1

Best practices

  • Use the REPL as a scratchpad.
  • Use it to validate small expressions.
  • Use it to inspect environment values.
  • Use it to test JSON values before using them in config files or APIs.
  • Use C++ snippet mode to quickly test real C++ code through the Vix pipeline.
  • Move larger code into a real .cpp file or project once the idea is validated.

Module layout

text
include/vix/reply/
  api/
  console/
  core/

src/
  api/
  console/
  core/
1
2
3
4
5
6
7
8
9

Public entry point

The main entry point is:

cpp
#include <vix/reply/core/ReplFlow.hpp>

int repl_flow_run(const std::vector<std::string>& replArgs);
1
2
3

The Vix CLI uses this entry point to implement:

bash
vix repl
1

Next step

Continue with project creation.

Open the vix new guide

Released under the MIT License.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.