I talked with Koz about this and looked at that last approach. The 'If ... Set' approach is the road to madness since 'Result' just comes out of nowhere.
But he did propose something like:
Set Day If Christmas Then BeginText Christmas EndText Else BeginText Not Christmas EndText EndSetIf
This reads a little strange as if the set is conditional, but the value is conditional.
Mikoto suggested this:
Set Day To BeginText Christmas EndText If Christmas Else BeginTest Not Christmas EndText EndSet
This would unroll as:
Set Day To BeginText Christmas EndText If Christmas Else BeginTest Not Christmas EndText EndSet
I must say I'm a bit confused by this, what it would do or and why. Can you explain better ?
So right now when you do an if statement, it runs an action for success or failure. But what if you want the result of that action? Right now the result gets discarded like a command directive, there's no way to give it a name like a set directive.
Here's a quick example: Let's say we want to add a number to someone's name if it's already taken.
We'd write it like this currently:
If NameDatabase Contains Name Then Name Append BeginText 1234 EndText Else Name EndIf
But this doesn't actually do anything, because Append just creates a new value.
So in this case we'd want something like:
Set NewName If NameDatabase Contains Name Then Name Append BeginText 1234 EndText Else Name EndSet
Where the value of NewName is set to either the result of Append or just Name again.
It might make more sense if you mentally replace Append with Join
Here's a quick question to myself: How does this interact with setting variables and returning?
Set X If .... EndSet is obviously the way to do set and is equivalent to ternary operations
But what about conditional returns? Where based on a result you either return or set a variable? A bit like
if(!(name = read_valid_name())) return;
I guess in NewLang that would be represented as:
Set Name To Read_Valid_Name EndSet
If Not Name Then Return EndIf
Note that these are NOT just nested if statements, as they don't support returning/jumping. Only values/function calls.
Just a quick note, If directives probably need prefixes like 'Not'
Currently If directives discard their value unconditionally. This isn't very useful for actually getting work done in a language that will aim to be mostly functional.
I'm not too sure exactly how this would nest or even if this is the right thing to do, so I'm just going to throw out some ideas:
This approach seems to be the easiest to define- just let if directives happen in set directives. But to break it up over lines it looks a lot stranger as you can no longer tell what's happening just by reading the start of the line.
Alternatively you could put the sets in the if directives like this:
This reads a bit better as:
This would effectively make if directives a control structure, which makes sense to me.
However it's less safe: What if one branch doesn't set Day but we use it later?
We could try and use levels of nesting to make it easier for people to skim past:
Perhaps we could introduce some kind of indentation or nesting syntax?
Another approach altogether is to bind the result to a variable automatically, like this:
or written nicely:
Where 'Result' would be the result of the if statement. I like this approach the most because it avoids nesting, which is a goal of the language. Maybe we could explain it by being a stack value or something?