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

World: r3wp

[Red] Red language group

Dockimbel
27-Feb-2011
[19]
In theory, you should be able to build some R3 extensions in Red/System 
(I would need to implement the DLL linker support and 3rd-party DLL 
exported functions mapping first).
BrianH
27-Feb-2011
[20]
It would also be possible to make the function argument type syntax 
more complex than that of R3, providing more detailed information. 
On the other hand, duck typing may be sufficient to determine what 
is necessary.
Dockimbel
27-Feb-2011
[21]
Brian: true, I'm not yet sure how far the inference engine could 
push the limit without becoming too complex to maintain, so I've 
put this early warning to show that there will be a limit (even I 
don't know yet where it will be precisely).
BrianH
27-Feb-2011
[22x2]
And that limit could be increased with time.
I like Go's type system, where there are interface types but you 
don't have to declare that your objects implement those interfaces. 
The type checker can figure out for itself whether the object matches 
any interface type. It's like formalized duck typing. Go's object 
model - no classes or inheritance - adapts really well to REBOL, 
so it's a good language to mine for ideas.
Dockimbel
27-Feb-2011
[24x2]
And that limit could be increased with time.

 Exactly. As Red's compiler will be coded in Red (once the bootstrapping 
 phase will be over), every new feature added to Red will benefit 
 to the compiler itself.
Go: It's in my scope of languages to study, like Scala, Lua, Factor 
and Rust.
Kaj
27-Feb-2011
[26]
Falcon :-)
Dockimbel
27-Feb-2011
[27]
Ah yes, I'll add that one too to my list. Thanks for the reminder 
:-)
Ladislav
28-Feb-2011
[28]
Andreas: "Except that if Red (not Red/System) is to be statically 
compiled as well, that'll make the language quite different to REBOL. 
In fact, I'd assume that except for some superficial syntactic similarities, 
it won't have much to do with REBOL at all." - nevertheless, if Red 
will be a sublanguage of what I call the Data Exchange Dialect, it 
will be a REBOL dialect in my opinion, no matter how limited/unlimited 
it is going to be.
Pekr
28-Feb-2011
[29]
Althought not precisely undestanding the topic, I might agree with 
Ladislav. Now if I am not wrong, then e.g. Cyphre's JIT code could 
be regarded being kind of REBOL dialect - it looks like REBOL, it 
might have syntax like REBOL, you just can't do all the tricks with 
it. Whereas we could not say the same about e.g. a RebCode? Does 
it make sense, or am I wrong?
Ladislav
28-Feb-2011
[30]
Whereas we could not say the same about e.g. a RebCode?
 - actually, we could say the same about RebCode as well
BrianH
28-Feb-2011
[31x2]
Doc, you might also consider making your type inferencer aware of 
the ASSERT function. ASSERT/type in particular would provide useful 
information, and can be evaluated statically as long as you don't 
let the function be overriden.
Quick questions about Red/System:

- Do you have DO of block expressions (getting from a word, returning 
from a function), rather than scripts or inline blocks?

- Are the conditional control and loop functions built into the language, 
or are they functions?

- Can the aforementioned functions take block expressions, or only 
inline blocks?
Dockimbel
28-Feb-2011
[33]
ASSERT: I'll look into that.

DO of block expressions

 nope, it's too high-level for Red/System. Remember that there's no 
 block! datatype in Red/System, we're talking about a C-level language. 
 In Red, you'll be able to use DO (as well as REDUCE and COMPOSE) 
 pretty much the same way as in REBOL (will require the JIT).


Control flow functions: built into the language for Red & Red/System. 
They'll be expecting inline blocks as argument, but when the JIT 
will be available, this could be extended to block expressions.
MikeL
28-Feb-2011
[34]
Doc: LuaJIT.org may have some good parallels as well just LUA
BrianH
28-Feb-2011
[35x4]
I figured as much, but thanks for the clarification.
ASSERT/type can do deep type checking of paths, and after the function 
returns the code can assume that the assertions are true. This can 
help with making code that would otherwise be too general for the 
inferencer to handle be really specific. To work best, ASSERT would 
also need to be built into the language, like the loop functions.
When ASSERT is compiled the statically determinable assertions can 
be dropped from the output code, leaving only the stuff that needs 
to be checked at runtime.
Building in the type test functions into the language would have 
the same effect. The type inferencer could determine some of them 
statically. If they are regular functions, that would require partial 
evaluation to get the same effect.
Dockimbel
28-Feb-2011
[39]
MikeL: LuaJIT is definitely the best model to follow for Red's JIT, 
at least performance-wise.


BrianH: thanks for the insightful explanation. This seems like a 
nice way to make the inferencer smarter. Is ASSERT used a lot in 
R3 mezz code so far?
BrianH
28-Feb-2011
[40x6]
Yes, for situations that the function type specs can't handle. It's 
mostly used for making code more bulletproof, but it can speed things 
up too. Even more so in Red since the runtime overhead could be eliminated 
when unnecessary.
My old version of LOAD used it a lot, but the new version uses the 
CASE/all style to get the same effect with less overhead.
See sys/make-module* for a good example of its use now.
ASSERT and ASSERT/type don't have a way to test the number and type 
compatibility of function arguments for first-class functions. It 
might be worth looking into a way to check that, perhaps as an extension 
of ASSERT, which could be ported to R3 as well. ASSERT is also high 
on the list of functions to backport to R2 as a native function.
Code like this in FIND-ALL:
    assert [series? orig: get series]

could be internally rewritten into this as part of the compilation 
process:
    orig: get series assert/type [orig series!]
You should definitely make sure that Red/System supports CASE and 
CASE/all, since the style that those functions allow leads to really 
efficient code.
Dockimbel
28-Feb-2011
[46x2]
I didn't need a CASE-like statement so far in Red/System, so it's 
there yet. Current implemented control flow statements: IF, EITHER, 
UNTIL, WHILE, ANY, ALL. So implementing CASE should be doable.
it's there
 => it's not there
BrianH
28-Feb-2011
[48]
Look at the source of LOAD and sys/load-header for some good examples 
of the CASE/all style. It's worth supporting.
Dockimbel
28-Feb-2011
[49]
I'm sure it would be nice to have it, but my short term goal with 
Red/System is to just code the minimal set of primitives required 
to build the upper layer (Red's runtime layer). I was hoping that 
other developers could keep expanding/improving Red/System while 
I would progress on the Red part.
BrianH
28-Feb-2011
[50]
Good point.
Andreas
28-Feb-2011
[51x2]
What makes CASE/all different from a long sequence of IFs?
(In respect to Red/System, where those will be equal, performance-wise.)
BrianH
28-Feb-2011
[53]
Maintainability of code. We found that the CASE/all style makes changes 
to code easy to make, and control flow easy to understand. This realization 
came out of the process of rewriting R3's module system into easier-to-maintain 
code.
Dockimbel
28-Feb-2011
[54]
It's sleep time here, but I can't resist to post a first Red/System 
source example:

#import [
	"kernel32.dll" [
		GetStdHandle: "GetStdHandle" [
		  	type		[integer!]
		  	return:		[integer!]
		]
		WriteConsole: "WriteConsoleA" [
		  	handle		[integer!]
		  	buffer		[string!]
		  	len		[integer!]
		  	written		[struct! [value [integer!]]]
		  	reserved	[integer!]
		  	return:		[integer!]
		]
	]
]

stdout: GetStdHandle -11
written: struct [value [integer!]]

prin: func [s [string!] return: [integer!]][
	WriteConsole stdout s length? s written 0
]

prin "Hello Red World!"
Andreas
28-Feb-2011
[55]
Ladislav, regarding Red being a REBOL dialect if Red's syntax is 
a subset of the data exchange dialect syntax: I fully agree.
Dockimbel
28-Feb-2011
[56]
Of course, this will be part of Red/System own small runtime, exposing 
among other functions, PRIN and PRINT.
BrianH
28-Feb-2011
[57]
How are the types of local variables declared in Red/System? The 
slideshow says no type inference...
Dockimbel
28-Feb-2011
[58]
As in REBOL: using /LOCAL followed by name and datatype.
BrianH
28-Feb-2011
[59]
And /local is special, not just another refinement?
Dockimbel
28-Feb-2011
[60]
Yes, it's a reserved keyword. I planned to add refinement support 
also, but I'm not sure I will need it to implement Red runtime, so 
it will be probably postponed.
Mchean
28-Feb-2011
[61]
how many attended the conference?
Dockimbel
28-Feb-2011
[62]
We were 5, but it felt like 10 ;-)
Mchean
28-Feb-2011
[63]
heh, well having actually had a conf i think you can use a 3x multiplier
Dockimbel
28-Feb-2011
[64]
Brian: here's an example of /LOCAL usage from my Red/System tests 
scripts (just a variation on the real PRINT function):


print: func [s [string!] return: [integer!] /local lf [string!] sz 
[integer!]][
	lf: "^/"
	prin s
	sz: 1
	WriteConsole stdout lf sz written 0
]
BrianH
28-Feb-2011
[65]
No tmp variables then :)
Dockimbel
28-Feb-2011
[66]
Nope.
Kaj
28-Feb-2011
[67]
Cool examples, Doc
Dockimbel
28-Feb-2011
[68]
The real PRINT is defined as: 

print: func [s [string!]][
	prin s
	prin "^/"
]