Yes, there are concatenative programming languages with REPLs that offer mechanisms to save and restore sessions, including variables and functions. One such language is Forth, which is a stack-based, concatenative language known for its interactive environment.
Forth
Forth has been around for decades and has a rich ecosystem. It typically includes a REPL where you can define variables and functions (called "words" in Forth).
Saving and Restoring Sessions in Forth
To save your session in Forth, you can use the following approach:
-
Define Words and Variables:
variable my-var
: my-word ( n -- n+1 ) 1 + ;
-
Save the Session:
You can write these definitions to a file:
\ Open a file for writing
s" definitions.fs" 123 create write
\ Write definitions to the file
s" variable my-var" write
s" : my-word ( n -- n+1 ) 1 + ;" write
\ Close the file
drop drop
-
Restore the Session:
To restore the session, you read the file and execute its contents:
\ Open the file for reading
s" definitions.fs" 123 create read
\ Execute the contents of the file
execute
\ Close the file
drop drop
Other Languages
While Forth is a well-known example, other concatenative languages like Joy or Factor also have mechanisms to save and restore sessions, though the specifics can vary.
Factor
Factor is another concatenative language with a more modern feel. It has a robust REPL and supports saving the image of your session.
-
Define Words:
VARIABLE my-var
: my-word ( n -- n+1 ) 1 + ;
-
Save the Image:
You can save the entire state (including variables and words) to a file:
"session.save" save-image
-
Restore the Session:
To restore, you simply load the image:
"session.save" load-image
Conclusion
Both Forth and Factor provide ways to save and restore your programming session, including variables and functions. Forth is more low-level and stack-oriented, while Factor offers a more high-level, modern approach. Choose the one that best fits your needs and preferences.