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

World: r3wp

[Red] Red language group

Kaj
21-Apr-2011
[1247]
Using 2147483648  ; #{80000000}
Oldes
21-Apr-2011
[1248]
What about using R3?
Kaj
21-Apr-2011
[1249x2]
For what?
64 bits?
Oldes
21-Apr-2011
[1251]
yes
Kaj
21-Apr-2011
[1252]
I'd be pleased with that, but structs do nothing in R3
Oldes
21-Apr-2011
[1253x2]
ah.. so that will be a problem I guess.
The struct is used in RED only for the syntax or something else as 
well? It would be quite easy to create an extension maybe.
Kaj
21-Apr-2011
[1255]
Anyway, 32 bits targets still require 32 bits arithmetic
Geomol
21-Apr-2011
[1256]
Continuing from !REBOL3:


When defining a minimum set of natives for a REBOL like language, 
at one point you have to consider ADD vs. +. If you have the + operator, 
you can create ADD as a function. On the other hand, if you can create 
your own operators (which isn't possible in REBOL), you could make 
+ from ADD. So which one is more basic? Are both justified?
Kaj
21-Apr-2011
[1257x2]
Depends on whether the point of view is grammar or semantics
In a functional language, infix operators are usually considered 
syntax sugar. On the other hand, in Red/System, + is elementary
Geomol
21-Apr-2011
[1259x4]
Ok, make sense. So the answer kinda depends on whether you consider 
the language strictly functional maybe?
Another function is the math EXP function. It just raises the number 
e to some power (the argument). A language like C (and probably most 
others languages) has this function (in the math library though). 
Probably to make code faster, but it can easily be defined as a REBOL 
function, right?
There are some rounding problems though, so it maybe can't be made 
easily, but probably using a trick.
>> exp 1
== 2.71828182845905
>> myexp: func [v] [2.71828182845905 ** v]
>> myexp 32
== 78962960182685.1
>> exp 32
== 78962960182680.6

So we might need more digits for e.
Maxim
21-Apr-2011
[1263]
you know, I was half joking when I suggested this group... :-)
Geomol
21-Apr-2011
[1264]
:) well, it's a good group for this, as Doc would consider these 
things at some point.
Maxim
21-Apr-2011
[1265]
I just woudn't want it to take over the topical discussions related 
to actual Red implementation and use.
Geomol
21-Apr-2011
[1266x2]
>> myexp: func [v] [2.7182818284590451 ** v]
>> myexp 32
== 78962960182680.6
>> exp 32
== 78962960182680.6

With 2 extra digits, it seems to work.
With e defined, the hyperbolic cos, sin, tan, etc. are easy (REBOL 
doesn't have these), and maybe also normal cos, sin, tan!? At least 
for complex numbers, but not so sure about reals. Maybe a better 
mathematician can tell us that? Ladislav?
BrianH
21-Apr-2011
[1268]
John, in a real REBOL-like language + is implemented using ADD; all 
operators redirect to their associated functions. You could do a 
similar trick with a compiled REBOL-like language like Red. This 
brings up another question though: Will Red implement operators in 
a fixed-predefined-set way like R2, or in a user-defineable way like 
R3? I hope the latter, though the former would make sense for Red/System, 
at least in the pre-Red stage of its development.
Geomol
21-Apr-2011
[1269x3]
Are complex numbers considered in Red?
User-defined operators are really nice, I think. Being able to write 
things like:

remove 42 from [1 2 3 42 177 280]

where FROM is just a simple FIND.
but as an operator.
Maxim
21-Apr-2011
[1272]
that is really nice geomol
BrianH
21-Apr-2011
[1273x2]
For now in R3 there are some restrictions about the kind of functions 
you can make an operator from - number of arguments and such. It 
is planned to eventually relax one of the restrictions, and allow 
function!, closure! and command! functions to be used. However, even 
in Red there will likely need to be a fixed format to the arguments 
of such a function: 2 args with no refinements, the first arg corresponding 
to the left side and the second arg corresponding to the right.
To make a FROM op you would need to make a FROM~ wrapper function 
around FIND; you wouldn't be able to make an op from FIND directly.
Maxim
21-Apr-2011
[1275]
there could be various forms to the ops.  there can be a way to tell 
the op building process to be unary binary or ternary.
Geomol
21-Apr-2011
[1276x3]
Yeah, operators with only 2 arguments sounds like a good idea. More 
and it fastly become too complex leading to confusion.
f
fastly
 :-D Think "quickly"
Maxim
21-Apr-2011
[1279x2]
brian, can we already build the FROM as an op in R3?  I've tried 
using the to-op and I can never get it to work.
(though we should go back to REBOL3! group)
Geomol
21-Apr-2011
[1281]
Maybe NOT can be defined as a function this way?


not: func [value][either none = :value or (false = :value) [true][false]]
Dockimbel
21-Apr-2011
[1282]
Will Red implement operators in a fixed-predefined-set way like R2, 
or in a user-defineable way like R3?

 Op! will be user-defined as they were in R-sharp interpreter. Here's 
 a short extract of R-sharp's boot script:

+:  make op! :add
-:  make op! :subtract
*:  make op! :multiply
/:  make op! :divide
=:  make op! :equal?
<>: make op! :not-equal?
BrianH
21-Apr-2011
[1283]
This would be safer to do in Red than it currently is in R3 because 
the compiler can perform all of the evaluation safety checks as part 
of its type checking, with no runtime overhead.
Dockimbel
21-Apr-2011
[1284]
Exactly, safer and cheaper to do with a compiler.
Andreas
21-Apr-2011
[1285x2]
If C doesn't allow struct parameters and return values, only struct 
references or pointers

C allows struct values as parameters and return value.
(They are often frowned upon in public API usage due to portability 
concerns, though.)
BrianH
21-Apr-2011
[1287]
Are there size limits to these parameters and return values?
Maxim
21-Apr-2011
[1288]
~size of the stack, I'd guess
Andreas
21-Apr-2011
[1289x2]
yep
no size limits, but it's obviously a lot easier to blow the stack 
if you pass around lots of large structs as values
BrianH
21-Apr-2011
[1291]
Even for return types? Are they just left on the top of the stack?
Andreas
21-Apr-2011
[1292x5]
that depends :)
as i said, it's a portability mess
small objects are sometimes passed in registers
i.e. if your struct fits in two machine words, some (x86) compilers 
use eax and edx to return it
other compilers rewrite the function to take an additional parameter 
with a pointer to storage used for returning the struct