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

World: r3wp

[Red] Red language group

Dockimbel
29-Mar-2011
[696]
Right, that's something to consider too. But I've often found such 
notation a bit hard to read and remember. Also to consider: hex syntax 
opens a hole in the "no digit as first character in words" rule. 
I hoped that I wouldn't have to break that rule again for other literals.
BrianH
29-Mar-2011
[697]
Doc, by multibyte chars I wasn't talking about variable-size, I was 
talking about fixed-size with Unicode support. A char! would have 
a single size, but that size would either be 1, 2 or 4 bytes depending 
on whether the base plarform supports ASCII, Unicode2 or full Unicode.
Dockimbel
29-Mar-2011
[698x2]
I think that such rule played well its role of barrier against typos 
in code for REBOL, even if it closes the door to some syntax combinaisons. 
So, I'm quite reluctant to break it further. A solution would need 
to be found for different sized integer literals.
Brian: right, but I'm not sure that Red/System needs to be Unicode-aware, 
at least not to implement UTF-8 Red's sources parsing.
BrianH
29-Mar-2011
[700]
I think that readable trumps consise in this case, Maxim. And for 
a compiled language, to-long 33, to-short 33 and to-byte 33 can be 
resolved at compile time with no overhead.
Dockimbel
29-Mar-2011
[701]
Unicode: it's an open question that needs experimenting further with 
Red/System. I'm not against to make char! a unicode codepoint type, 
if it helps coding at Red/System level.
BrianH
29-Mar-2011
[702]
Doc, if Red/System doesn't need to be Unicode-aware, you should replace 
the string! type in it with a binary! type and just have compiler-resolved 
string-to-binary conversions of string literals in the source. Have 
real strings only exist at the Red level.
Dockimbel
29-Mar-2011
[703]
That's the solution I was considering so far, but your point about 
Unicode makes me wonder if there's is not a better solution than 
the old C way.
Andreas
29-Mar-2011
[704]
All better solutions include byte! + binary! types :)
BrianH
29-Mar-2011
[705]
The old C way was based on legacy byte-size chars. It is better to 
be Unicode-aware from the start than it is to retrofit it.
Andreas
29-Mar-2011
[706x2]
Btw, you should probably specify that "printable characters" are 
bytes in the range 20h-79h
US ASCII only defines 128 characters.
BrianH
29-Mar-2011
[708]
Andreas, 79h is the DEL char, not printable :)
Andreas
29-Mar-2011
[709x2]
should be 7Fh, and 7Fh is the DEL char of course
But I'm referring to section 3, which currently uses 20h-FFh
BrianH
29-Mar-2011
[711x2]
Oh, right :)
Then printables go to 7Eh.
Andreas
29-Mar-2011
[713]
So use 20h-7Eh
Dockimbel
29-Mar-2011
[714x2]
Well, by default, Red/System could be transparent to UTF-8 (that's 
what will be used in Red for strings I/O), as is string! in R2. Will 
add char! as unicode codepoint to possible evolutions anyway.
Characters range: yes I need to change that, PeterAWood posted a 
note about it too: http://groups.google.com/group/red-lang/browse_thread/thread/99e14e44fbf69abf?hl=en
BrianH
29-Mar-2011
[716x2]
Red/System could be able to make values of all of Red's types, while 
not itself using all of its types in its own code. Red/System source 
could contain literals of Red's string! type, but its compiler will 
convert those literals to Red/System's binary! type. Then Red/System 
can make string! values explicitly by doing the conversions itself, 
or calling functions to do so. Make the Red/System language types 
a strict subset of the Red types, and don't pretend that you really 
support strings and chars in your language unless you have Unicode 
support built in. Then Red's built-in Unicode support would be written 
in Red/System code operating on binary! data :)
And then no code that calls C with char* types would pass in values 
of the string! type unless they have been converted to binary! first, 
implicitly by the compiler or explicitly by the code.
Dockimbel
29-Mar-2011
[718x2]
Good point. That was the plan. You've put it more clearly than I 
would.
I've kept the string!/char! analogy too long, so it almost confused 
me too. :-)
BrianH
29-Mar-2011
[720x2]
You might want to make it more explicit in the system design and 
docs that this is your approach, and add binary! and byte! as explicit 
types a lot sooner. Then you can do a tiny amount of type inference 
to at least have the compiler be smart enough to do the conversions 
when it can, so runtime conversions can be minimized.
Same with the bit!, bitset!, logic! group. Bits and bitsels are storage 
types, but logic values are what conditional expressions work with. 
This also has the benefit of letting the compiler avoid putting in 
if 0 checks all over the place and just go by condition codes instead, 
especially for inlined control flow code.
Maxim
29-Mar-2011
[722]
brian "I think that readable trumps consise in this case, Maxim."

well, right now, red is much less readable than C when types are 
involved. 


when I look at something like this (which is proposed as an extension 
to current type syntax): 
p: &[array! [20 integer!] 0]

I get nervous cause this is the anti-thesis of REBOL
why can't it be expressed like:

p[20]:  0  ; infered type


p[13 string!]: "hello"  ; explicit type, though usually superfluous
BrianH
29-Mar-2011
[723x2]
You don't want to overdo it of course, but the more info the compiler 
knows, the better code it can generate.
Maxim, I agree that the literal pointer syntax is bad. Do you have 
a better suggestion for the syntax of declaring explicit pointer 
variables, especially since you usually can't just write out the 
value of those variables as a literal number?
Dockimbel
29-Mar-2011
[725x2]
avoid putting in if 0 checks all over the place
: That's what I was concerned about on the implementation side.


just go by condition codes instead, especially for inlined control 
flow code.
 That's already the case.
Array! and pointer! literals: I'm not satisfied myself with that, 
but that's the best I could come up with, so far. If you have better 
propositions, I'll be glad to adopt them.
BrianH
29-Mar-2011
[727x2]
Out of curiosity, why did you use &[ ] for those typed serialized 
values instead of #[ ] as in REBOL?
Aside from the & character, those are basically the same thing as 
the serialized syntax of REBOL.
Dockimbel
29-Mar-2011
[729x2]
For a simple reason: you can't use LOAD on not-REBOL datatypes names: 
#[pointer! 0] triggers a LOAD error.
I've played with ALIAS to try to workaround that, but it wasn't a 
good idea.
BrianH
29-Mar-2011
[731]
So it's basically & [ ], not a single syntactic structure. Ok.
Dockimbel
29-Mar-2011
[732x2]
So, I finally chose to use the & character (already used in C and 
other languages to mean "address of") with a datatype description 
for pointer! literal form.
Right, & word and a block!.
BrianH
29-Mar-2011
[734]
Since we use AND and OR instead of & and |, there's no conflict with 
making & be a prefix builtin operator. Cool.
Dockimbel
29-Mar-2011
[735x2]
Exactly.
What do you think about dropping pointer! in favor of struct!, as 
struct! could do the same job? (See my last blog post)
BrianH
29-Mar-2011
[737]
I have mixed feelings about it. Pointer arithmetic is considered 
appropriate in a systems programming language if you want to make 
sure from the beginning that it is unverifiable. If you want a safer 
language, C++-style references are better. But the main problem with 
this is the same problem with R2's struct! type: It's too C-centric. 
Many languages other than C support actually passing structures into 
functions and returning structures, not just passing and returning 
pointers (or references) to them. Because of this I found the R2 
FFI model to be unusable to interface with the code that I really 
needed to call, which was as a matter of course never written in 
C.
Dockimbel
29-Mar-2011
[738]
Max: p[20]:  0 and  p[13 string!]: "hello"


These are not valid syntax in REBOL nor will be in Red. You're stretching 
the syntax a bit too far with putting a colon at the end of a block!.
BrianH
29-Mar-2011
[739]
I want to have a real structure type, not having a structure be equivalent 
to a reference to a structure.
Dockimbel
29-Mar-2011
[740]
This is something that could be added at Red level (in the core set 
of datatypes or as a user-defined type). Red/System will have to 
interface with C libraries mainly, that's why I took the C-like way 
to manage structs as references instead of values.
BrianH
29-Mar-2011
[741]
I noticed that in one of your structure examples one of the fields 
had a type of pointer! without a qualifying type. Are you supporting 
this?
Dockimbel
29-Mar-2011
[742]
It's a typo I guess.
Maxim
29-Mar-2011
[743]
the thing is that red/system isn't actually a semantic equivalent 
to REBOL its hard to keep an exact REBOL syntax equivalent.
Dockimbel
29-Mar-2011
[744x2]
Typo fixed.
Max: that's the hard part of Red/System design.