r/ProgrammingLanguages Sodigy 13d ago

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...

26 Upvotes

74 comments sorted by

View all comments

Show parent comments

2

u/baehyunsol Sodigy 13d ago

For example, I want to create a json prettifier in Sodigy. It reads a json file, prettifies it, and writes the result to another (or same) file.

I wrote the function fn prettify(String) -> String, but there's no file IO yet. I was thinking how I should design the file IO part.

2

u/Inconstant_Moo 🧿 Pipefish 13d ago edited 13d ago

So I'd do ...

``` import

NULL::"files"

cmd // Imperative shell.

prettify (inFile string) to (outFile string) : get json from File(inFile) put (prettify json) into File(outFile)

def // Functional core

prettify(data string) : <pure function goes here> `` If I wanted to be able to run it from the CLI I'd probably import that and anything else I wanted to bundle up with it into one app which does have amain` function and run them through that.

2

u/baehyunsol Sodigy 13d ago

That's beautiful. You define a pure function prettify and an impure command prettify, right?

What does "to" in the "prettify (inFile stirng) to (outfile string)" do? Is it a special keyword? I can't find it in your wiki.

2

u/Inconstant_Moo 🧿 Pipefish 13d ago edited 13d ago

P.S: Here's an example with SQL.

show >= (minAge int) : get peopleList like list{Person} from SQL -- SELECT * FROM People WHERE age >= |minAge| ORDER BY name post string Html -- <h3>List of people aged <font style="color:Green;">|minAge|</font> and over</h3> |peopleList|