r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Red] Red language group

Dockimbel
30-Dec-2011
[4169x2]
Same as for CASE: undefined value.
Suggestions for improving that are welcome (both for CASE and SWITCH), 
as long as they don't require a lot of additional coding.
BrianH
30-Dec-2011
[4171x2]
Do you have something like unset!, or is it really undefined? (I 
hate undefined behavior in a programming language, pet peeve)
For that matter, do you have something like the none! type? Nullable 
types are the subject of a big debate in PL design right now.
Dockimbel
30-Dec-2011
[4173]
It's just undefined (probably returning the SWITCH/CASE argument 
value, but that would be implementation-dependent, and could be changed 
in the future).
BrianH
30-Dec-2011
[4174]
Yuck (no offence). Triggering an error or returning none would be 
better. There are even some languages that trigger an error on compilation 
in that case, but that requires either an interesting type system 
or some dataflow analysis, so that is not likely a good idea to put 
in Red/System.
Dockimbel
30-Dec-2011
[4175x2]
None! type: no, Red/System has null and 0, but no first class datetype 
for that.
datatype
BrianH
30-Dec-2011
[4177]
Any runtime error triggering in Red/System? Not that I suggest it 
(I prefer the Go approach), but I'm curious.
Dockimbel
30-Dec-2011
[4178x3]
None! type might not be a so big burden to implement and support, 
but it is just not required for implementing Red, which is the main 
purpose of Red/System currently. If current Red/System users can 
come up with good semantics for such type, I could examine the case 
for implementing it, though.
No runtime error triggering yet. But the runtime error sub-system 
is implemented and used internally.
I mean no way for user to trigger specific errors yet.
BrianH
30-Dec-2011
[4181]
Variables are statically typed in Red/System? That would make the 
none debate more interesting.
Dockimbel
30-Dec-2011
[4182x3]
Also, TRY could be implemented too, but as Red/System will be used 
from Red, I am not sure, this is necessary to support.
Variables are statically typed, yes.
I know it's a bit frustrating currently, as we could add a lot of 
sophisticated features to Red/System, but that's not the plan. :-) 
Most users will never touch Red/System once Red gets available.
BrianH
30-Dec-2011
[4185x3]
That brings up the nullable types debate then.
Is the compiler capable of showing warnings? CASE and SWITCH without 
default cases might merit one. A caveat emptor approach might be 
bese for a C-like intermediate language, I guess :-/
bese -> best
Dockimbel
30-Dec-2011
[4188x5]
Warning: yes, currently only one is active for signaling useless 
type castings.
I am not a big fan of warnings "à la C", I debated myself several 
times to decide on keeping it or not (converting it to a compilation 
error).
It's not possible to statically analyse for default rule in CASE 
(no keywords, could be any expressions returning always TRUE).
Emptor: I'm not familiar with this concept, googling about it....
Oh, old Latin, shame on me! :)
BrianH
30-Dec-2011
[4193]
Can you analyze EITHER, CASE and SWITCH to determine whether the 
results the clauses return are the same type? I guess the same would 
go for ANY and ALL, if you have those.
Dockimbel
30-Dec-2011
[4194x2]
Yes, that is already done in the current implementation to allow 
the use in expressions.
ANY/ALL: yes, see http://static.red-lang.org/red-system-specs.html#section-9
BrianH
30-Dec-2011
[4196]
Do you have a value you can return when the value would be undefined, 
which would cause an error to be triggered if you try to use it in 
an expression? If so, CASE and SWITCH could have an implicit default 
case that returned such a value, and the compiler could optimize 
that out if the CASE or SWITCH return value is not used in an expression. 
That would solve the problem without resorting to nullable types.
Dockimbel
30-Dec-2011
[4197x2]
Do you have a value you can return when the value would be undefined

 Yes, zero. It could work for all current datatypes: 0 for numbers, 
 NULL for pointers and FALSE for logic! (all are implemented using 
 0 as value internally).


...which would cause an error to be triggered if you try to use it 
in an expression?
 No.
The first option could be easily implemented, probably just a line 
of code or two to add in the compiler.
BrianH
30-Dec-2011
[4199x2]
Well, since triggering the error was the point of all that, I guess 
not. We're back to caveat emptor.
It would need to be something distinct from 0, since that could be 
legitimate.
Dockimbel
30-Dec-2011
[4201x3]
Thinking about it, I believe that I could hardwire a runtime error 
in CASE/SWITCH in case of unmatched value and no default.
I will test that later tonight.
It would probably be the best option currently.
BrianH
30-Dec-2011
[4204]
There are languages that don't allow CASE or SWITCH to have an unhandled 
expression, to cut down on errors. Your suggestion would have that 
effect. It would improve the developer's code discipline, leading 
to fewer errors in the code.
Dockimbel
30-Dec-2011
[4205x3]
With current CASE in Red/System, it might be required to force the 
use of a 'default keyword, as in SWITCH, for the compiler to know 
if a default clause is used or not in a deterministic way.
Done a quick implementation test on SWITCH, it seems to be working 
fine.
(will be back in an hour)
PeterWood
30-Dec-2011
[4208]
I think that the addition of a default keyword in CASE would be an 
improvement.
Dockimbel
30-Dec-2011
[4209x2]
Ok, runtime errors added to both SWITCH and CASE, raised when no 
clause matches. No change were necessary for CASE.
Peter: I followed the same syntax as REBOL for CASE, but I am unsure 
that adding 'default keyword would be better. On one side, you have 
a better compatibility with REBOL, so easier for all REBOL old timers, 
on the other hand, we break compatibility (on syntax level only), 
but have a more consistent syntax inside Red/System.


Also the CASE semantics do not require a special keyword for making 
a default clause.

Need some time to think about it.
Henrik
31-Dec-2011
[4211]
Silly question: Does C-string mean that it's a C-compatible string 
type and whether there will be other string types in the future?
PeterWood
31-Dec-2011
[4212x4]
In short "yes". C-String in Red/System is simply a null terminated 
list of bytes. As I understand, strings in Red will support unicode 
but Nenad hasn't decided what form they will take yet.
If the compiler is only looking for 'default inside a switch statement, 
a good solution may be to #define defaiult as true in common.reds 
and then I can write

case [ a  = 1 [b: 1] default [b: 0]]

and old REBOLers can write 

case [ a  = 1 [b: 1] truet [b: 0]]
truet -> true
On the other hand, even if the syntax changed and default was a keyword, 
the old REBOLers could still write

case [ a  = 1 [b: 1] true [b: 0]]

and belt-and-braces types could write

case [ a  = 1 [b: 1] true [b: 0] default [b: 0]]  ;-)
Gabriele
31-Dec-2011
[4216x2]
Topaz SWITCH changed since then.
You have SWITCH and SWITCH-DEFAULT now.
Dockimbel
31-Dec-2011
[4218]
Other strings in the future: for Red/System, possible but very low 
priority for now. Red will have a R3-like string! datatype with Unicode 
support.