top of page
Workspaces

In ordinary marcel usage, you run commands, define and refer to environment variables, as with any other shell. You have access to a command history that survives from one session to another. But once you exit marcel, any variables that you have defined are lost. For example, I can define a variable storing a stream:

M 0.20.0 jao@loon ~$ gen 100 1 | red -i * >$ factorials

But once I exit marcel, this definition is lost.

A workspace organizes the command history, environment, and startup script, keeping those separate from other workspaces. The intended usage is that a workspace organizes what you need in a shell for working on a single project. Your startup script might import modules and define functions, or define databases and clusters or remote hosts, that you don't need in other projects. You might build up complex pipelines, and not want to lose them once you exit marcel. In general, variables store pipelines, functions, modules, and any other Python values, and whether you assigne values in your startup script, or interactively, they are scoped to and persistent for the workspace.

Without workspaces, marcel works as usual. There is a startup script, command recall survives sessions, but environment variables do not. Inside a workspace, command recall is limited to the commands issued in that workspace, and both command history and environment variables persist.

All operations on workspaces rely on the ws operator. E.g., to create a new workspace:

M 0.20.0 jao@loon ~$ ws --new myproject
Workspace(myproject)
M 0.20.0 (myproject) jao@loon ~$

The output from this command is a Workspace object. Note that the prompt now mentions the workspace. (This is optional behavior, and depends on how you have configured your prompt.)

Inside the workspace, I can use marcel in the usual way. For example, this code imports the math module, uses a function in that module to define a pipeline that computes entropy, and then exercises it by feeding it a stream of uniformly distributed random numbers between 0 and 1.

M 0.20.0 (myproject) jao@loon ~$ import math
M 0.20.0 (myproject) jao@loon ~$ entropy = (| map (x: -x * math.log2(x)) | red + |)

M 0.20.0 (myproject) jao@loon ~$ gen 10 | (_: random.uniform(0, 1)) | entropy
4.54540903583842

If I then exit marcel, restart it, and go back to the myproject workspace, math is still imported, and the entropy pipeline is still defined.

M 0.20.0 (myproject) jao@loon ~$ exit

jao@loon:~$ marcel

M 0.20.0 jao@loon ~$ ws myproject

M 0.20.0 (myproject) jao@loon ~$ gen 10 | (_: random.uniform(0, 1)) | entropy
4.54540903583842

I can list workspaces, (Workspace() is the default workspace):

M 0.21.0 (myproject) jao@loon ~$ ws --list
Workspace()
Workspace(myproject)
Workspace(myotherproject)

 

I can close a workspace, returning to the default workspace:

M 0.20.0 (myproject) jao@loon ~$ ws --close

Workspace()

bottom of page