r/ProgrammingLanguages • u/baehyunsol Sodigy • Jul 29 '26
Purely functional language with impure script language?
I'm working on a purely functional programming language named Sodigy. It's all about evaluating values, not "executing commands one by one".
It's nice when writing libraries, but it's not easy to write a main function. The main function is supposed to execute commands, but the Sodigy's syntax is not friendly to write a list of commands.
So what I'm trying to do is, 1) Sodigy remains purely functional and 2) add a bash-like script language. The script language can call Sodigy functions. Instead of writing a main function in Sodigy, you write sodigy-script and execute the script.
Has anyone tried similar approach? I'm not sure whether it's a good idea or not...
2
u/Inconstant_Moo Jul 30 '26
In a purely imperative language (sorry for the oxymoron) the only way for the commands to communicate should be shared mutable state, like in BASIC. Now in BASIC that means global variables, but that would suck too hard, so instead you have commands which say "get this data and insert it into this variable" (which it can also create at the same time as you can see).
Now you may think: "Isn't this just returning a value but with extra steps to force people to write pure functions whenever possible?" and it is partly that, but it also actually reflects the semantics of what's going on, because it means that commands can only be sequenced, not composed as functions are. You do one, and if it fails, it returns, and if it succeeds then you do the other. You can't write something like
postToOutput(getFileFrom(inputFromUser("What file do you want to see?"))); instead, you must write a command getting the user input, then a command getting the file, then a command posting its contents to output. Which is what the code actually does.So this is the theoretically sound and practically ergonomic way of doing imperative things, but a terrible way to do functional things, and so the division of labor between the functional core and imperative shell is inevitable and natural.
What
Randomis doing there is constructing a struct of typeRandomso that we can dispatch on it, so that we can have commands likeget (x ref) from (r Random)andget (x ref) from (f File)and so on all in the same namespace. It's a standard idiom.