Very nice. I think the ternary operator is a little non intuitive, but I come from a C background, so maybe it's based on something in Perl? I don't know how hard it would be, but something like:
if A && B || C then ... else ...
would mirror the DNA's structure and be more intuitive.
Also, I'm unfamiliar with Perl's && || operators. Others probably are too. Could you explain what they do?
I'm going to introduce
if later with the following syntax:
if ( ... ) {
...
}
else {
...
}
But there are some difficulties in implementation:
- Assigning to a variable in then and else which is used in the condition. This includes assigning to an expression, since expression may evaluate to an address of the variable used in the condition. Evaluation of the variable's address at compile time may be a complex task. Sometimes expression cannot be evaluated at the compile time at all (e. g. rnd(1000) ).
- Using rnd(...) in the condition.
Perhaps I'll just forbid
- using rnd() in condition expression
- using variables modified inside then and else clauses in condition expression
- assigning to expressions inside then and else
Naturally
if is already implemented, all I need to implement those checks, that is quite a bore.
Ternary conditional assignment operator is not met in Perl, though you can say in Perl:
$a = 1 if $b == 0;
Perhaps it is prettier, isn't it? I still can change to this syntax without much effort. What do you think?
&& and
|| work in Perl and Sanger as follows:
- a && b equals a if a is false (== 0 in Sanger's case), b otherwise (no matter if b is true or false)
- a || b equals a if a is true (!= 0 in Sanger's case), b otherwise (no matter if b is true or false)
Since it is so, you may do conditional assignment an extra way:
*.nrg > 20000 && .repro = 10;
which is basically the same as
.repro ?? *.nrg > 20000 = 10;
But ternary conditional operator has an additional possibility to use
this in condition. It refers to the value of the expression you assign. It is implemented with
dup assembly operator.
Well yes what do they, and will this be backward compatible. Dna->sanger
Though I don't understand what you mean by 'backward compatible', I can assure you it won't make trouble. Sanger tracks boolean and integer contexts and modifies integer values met in boolean context accordingly (with
sgn abs).