World: r3wp
[Red] Red language group
older newer | first last |
Dockimbel 19-May-2011 [1403] | Sorry, I meant: handle!: alias pointer! [integer!] or void-ptr!: alias pointer! [integer!] |
BrianH 19-May-2011 [1404] | You might want to avoid using handle! for these, as it is the best candidate for the opaque-pointer-sized-value type in Red proper, that all of Red/System's pointer! types would appear to be when they leak into Red code. |
Kaj 19-May-2011 [1405] | Well, isn't that exactly the reason to use it? |
BrianH 19-May-2011 [1406] | I mean, don't use the word 'handle! as an alias because it will likely be a built-in datatype in Red, and in all Red/System functions and datatypes exported to Red. |
Kaj 19-May-2011 [1407] | But it would be exactly what you want, wouldn't it? |
BrianH 19-May-2011 [1408x2] | handle!: alias integer! would override the built-in meaning of handle!. All code that uses that word would need to be changed when Red comes out. |
Keep in mind that there is no bounds-checking for Red/System's pointer type, and Red/System has typecasting (rather than conversion). Neither of those would be allowed in Red itself because of typesafety issues. Red/System will be like the unsafe code of C#. | |
Kaj 19-May-2011 [1410] | That would be just a little code, and it's obvious that you have to develop your programs to stay in sync with a language that's in alpha status |
BrianH 19-May-2011 [1411] | Yup. But it's also good to warn them of planned developments once they're definitely planned, and this one is pretty well established. |
Kaj 19-May-2011 [1412] | Exactly, so that's the reason to start using the handle! type now |
BrianH 19-May-2011 [1413] | No, that's a good reason to *add the handle! type to Red/System* now, as a preemptively reserved word. Not a reason to use the word handle! to refer to a completely different thing. |
Kaj 19-May-2011 [1414] | It still means that I start writing "handle!" in my code now |
BrianH 19-May-2011 [1415x2] | Perhaps it could be a name for a non-dereferenceable void pointer type, since that's the closest C equivalent. |
Basically, Red's handle! type would be the same as R3's handle! type. Opaque value that is pointer sized, but can't be used as a pointer without typecasting, and no arithmetic possible. No conversions to other datatypes either in typesafe code. | |
Kaj 19-May-2011 [1417] | That's in Red. Red/System is a different context |
BrianH 19-May-2011 [1418] | Yes, but Red/System's main purpose is to do things with Red data, so it needs to have access to Red's types, even if its own literal types are different. So Red/System needs to have a handle! type, even though Red/System code would need to typecast values of that type to something else in order to be able to do anything with them. |
Kaj 19-May-2011 [1419] | I don't see why it couldn't be the same type |
BrianH 19-May-2011 [1420] | Alias types are user-defined. The handle! type would be system-intrinsic. |
Kaj 19-May-2011 [1421] | Yes, a temporary difference in declaration, because as of now, there is no handle! type to declare |
BrianH 19-May-2011 [1422] | As long as the type is defined in the core runtime code, rather than in user code, there is no difference. |
Kaj 19-May-2011 [1423x2] | Exactly |
And since it isn't defined in the runtime now, I have to write it myself until that time | |
BrianH 19-May-2011 [1425] | The main thing is that it needs to be defined as *non-dereferenceable* and *no pointer arithmetic allowed*, so if Red/System's equivalent of the void pointer is so restricted, that will do. If dereferencing or pointer arithmetic is allowed on Red/System's void pointer type, that needs to be fixed asap. |
Kaj 19-May-2011 [1426x2] | Why? That would be the behaviour in Red. Red/System's task is to actually be able to do something with a pointer |
Unless you want to make Red a true capabllities language, but you are opposed to that concept | |
BrianH 19-May-2011 [1428x2] | In a strongly typed language, which even Red/System is, dereferencing a pointer means getting a value back that is of a known type; pointer arithmetic means adding in increments of the size of that type. A void pointer references nothing, and that nothing has no size. You must be required to typecast to another pointer type explicitly if you want to dereference the pointer, or to know how much to increment or decrement it. |
The difference between Red and Red/System is that such typecasts are possible in Red/System. | |
Kaj 19-May-2011 [1430] | If Red/System truely is to be strongly typed, there needs to be more than just pointer! [integer!]. The issue I'm currently having is exactly that there is no matching declaration for what I need |
BrianH 19-May-2011 [1431] | Right, there need to be pointers to other types. And support for more types, for that matter. |
Kaj 19-May-2011 [1432] | I'm not under a strong impression that this is planned. So currently, I need to treat Red/System as weakly typed |
BrianH 19-May-2011 [1433x2] | It is not currently planned *by Doc* to have Red/System be a complete language, since he only needs it to access a few system libraries and implement the Red runtime. He's said that others are welcome to contribute the necessary changes to make Red/System a more complete language. |
If you want to use Red/System as-is to do more advanced stuff than that, then go ahead and break the rules. Or better yet, add the features you're missing. | |
Kaj 19-May-2011 [1435x4] | I understand the burdens of future programs, but I've written a program right now that I have to keep working |
In other words, the rules you're talking about don't exist | |
Still, I would welcome Red/System becoming strictly strongly typed | |
If and when that happens, I'll update my programs to be compliant, as I'm doing now | |
BrianH 19-May-2011 [1439] | Well, it can't become strictly strongly typed, as a certain amount of type breakage is the whole point of its existence. You can't be strictly strongly typed if you have typecasting, pointer arithmetic, literal pointer values, or the ability to call C code. Red/System is supposed to be strongly typed with those rule breakers, in order to shield Red itself from those features. |
Kaj 19-May-2011 [1440x13] | Ehm, yes, that's what I've been saying all the time |
Doc, defining handle! with alias doesn't work: | |
*** Compilation Error: invalid struct syntax: [handle!] *** in: %/users/administrator/Red/Red-ZeroMQ-binding/examples/../ZeroMQ-binding.reds *** at: [struct [ content [handle!] | |
#define doesn't work, either: | |
** Script Error: Cannot use path on none! value ** Where: check-arguments-type ** Near: if all [ not empty? spec: entry/2/4 block? spec/1 ] [ spec: next spec ] foreach | |
You wanted to know if the appointed error locations are correct. That seems to be alright, and the error for a struct is nicely descriptive, but an error for a function definition is rather unspecific: | |
*** Compilation Error: invalid definition for function send: [ socket [pointer!] data [pointer!] size [integer!] flags [integer!] return: [logic!] ] *** in: %/users/administrator/Red/Red-ZeroMQ-binding/examples/../ZeroMQ-binding.reds *** at: [func [ socket [pointer!] | |
Oh wait. I have to use a block for #define, and then it works. But not ALIAS | |
And the error output for a function starts at the offending parameter, so that's actually pretty good, but it's not obvious | |
Here's a message that's not very clear: | |
*** Compilation Error: type mismatch *** expected: [pointer!] , found: [integer!] *** in: %/users/administrator/Red/Red-ZeroMQ-binding/examples/../ZeroMQ-binding.reds *** at: [0 as-message message data] | |
I can't compare pointers to zero any more. Presumably, these are the arguments to the zero? function, but that information is lost | |
As a nitpick, there's an excess space in the message, before the comma | |
older newer | first last |