World: r3wp
[Core] Discuss core issues
older newer | first last |
BrianH 23-Feb-2010 [15841] | It's modifying though, unlike EXCLUDE. |
Henrik 23-Feb-2010 [15842] | well, it makes kind of sense, I guess to return something else. returning a block from a modifying function seems a little bit like a "round circle" to me. |
BrianH 23-Feb-2010 [15843] | I suppose it's the cheapest thing to return and he thinks it's valuable information, so fine. I previously used REMOVE-EACH as a filter though, so it means more code for me in some (admittedly rare) circumstances. Overall, R3 code tends to be cleaner for most standard code patterns, though in some cases the best features are slightly undocumented (except in mezzanine code that depends on them). |
Henrik 23-Feb-2010 [15844x2] | it's probably a recurring code pattern for him |
and now I made a round circle comment :-) (I talk way too much today) | |
BrianH 23-Feb-2010 [15846] | For instance, in R3 (can't check R2 right now on this computer) comparison is allowed to unset! and error! values can be done with operators if the unset/error value is on the left side of the operator, but not on the right. This is because operators redirect to actions, and action functions are different depending on their first argument (single-dispatch). The comparison actions for unset! and error! can compare to other values, but the comparson actions of other types don't support comparing to error/unset. The action! function that calls the action has a typespec for its first argument that doesn't allow error/unset, but the op! redirects to the internal action, not the action! function, and it works because it uses a DO trick instead of a standard function call. |
Steeve 23-Feb-2010 [15847] | Arghhhh !!!! My Brain.... |
BrianH 23-Feb-2010 [15848] | Sorry, that was awkwardly phrased. If there was a better way of explaining that to newbies that didn't require a full article, it would be in the docs. |
Steeve 23-Feb-2010 [15849] | it's just that your explanation dig out more interesting questions. But i'm too tired tonight |
BrianH 23-Feb-2010 [15850] | Basically, the functions that you see in REBOL aren't necessarily the functions that are actually called. For each function type DO calls them a little differently, and this eventually gets to the actual function code. For most functions the argument spec type checking is done by DO, not the function itself. For natives (or mezzanines with explicit type checking) there can sometimes be some extra checking. Apparently all actions have to do some extra internal type checking because the argument compatibility rules are too weird to be expressable using the REBOL function spec syntax, so that syntax doesn't tell the whole story sometimes - the source of many dismissed documentation bug tickets, I'm afraid. |
Steeve 23-Feb-2010 [15851x2] | I should start to register some quotes of you an Carl, to be able to think about, afterward. |
like that one i saw some day ago, about EMPTY? calling TAIL? IIRC | |
BrianH 23-Feb-2010 [15853] | EMPTY? doesn't call TAIL?, they are the same function assigned to two different words :) |
Steeve 23-Feb-2010 [15854x5] | Are you sure ? |
yep tested | |
But I remember an odd bu | |
... bug when trying to use EMPTY? as an actor in a scheme | |
It throwed an error about TAIL? | |
BrianH 23-Feb-2010 [15859x3] | Port actions are mostly redirected to the scheme, but not (directly) the ones that implement the port model itself, afaict. |
As for EMPTY? and TAIL?, a function has no way of knowing what it is called. That error message generated from within the TAIL? port! action guessed wrong. | |
Oh, it gets trickier (in theory - I've had to do a lot of scientific method on the internals, not decompiling). I think that DO does some of the function call work, and the function type itself does the rest through an internal action. DO handles the evaluation rules and builds the stack frame, then passes along that stack frame to the function dispatch action of the function type for it to redirect to the real code in a type-specific way. Now it definitely works that way, the only question is whether the type-specific dispatch code is built into DO itself, accessed through the action dispatch mechanism, or action code called directly without going through the action dispatch mechanism. Only Carl or a decompiler could say for sure. But really, it doesn't matter because the behavior is the same in any case. | |
Steeve 23-Feb-2010 [15862] | Working with schemes, i saw another one thing really disturbing. Seems that LAST and FIRST use PICK. But LAST and FIRST are natives and PICK is an action. I always thought that ACTIONS may use NATIVES but not the reverse. |
BrianH 23-Feb-2010 [15863x4] | Nope, at least not in R3. Natives can call actions, and even call function! functions too. |
And apparently the type-checking of the left argument of an op! is done differently that the type checking of other arguments. Since this type checking is apparently done by DO, the type spec of the op! or action! function specs is apparently there for documentation, not actually used. Instead, DO checks whether the corresponding action is supported by the type and goes by that, rather than duplicating effort. | |
Mezzanine functions called by native functions are generally called "intrinsics", and there are several of them. DO, MAKE module! or port!, and the startup code call intrinsics. | |
This is how LOAD can be a mezzanine, btw, and still be called by DO. And it's how the module system can be mostly mezzanine too. | |
Steeve 23-Feb-2010 [15867x2] | yep, i begin to know them really well. Btw, i think make-port should be corrected in some ways |
when i construct ports with a spec block, i would rather prefer to use dialect (using delect) instead of passing a prototype of the spec object | |
BrianH 23-Feb-2010 [15869] | Yeah, I've cleaned up begin and make-module a bit, and rewritten DO completely many times, but make-port is still on my list. |
Steeve 23-Feb-2010 [15870] | i.e. open [ 10.45.12.12 2450] instead of open [scheme: 'tcp host: 10.45.12.12 port-id: 2450] |
BrianH 23-Feb-2010 [15871] | It actually does use a dialect already, that just resembles an object spec. |
Steeve 23-Feb-2010 [15872x2] | not really a dialect, just a bunch of case/if |
using DELECT would allow a more versatile syntax. | |
BrianH 23-Feb-2010 [15874x2] | MAKE-SCHEME is earlier on my list though. |
I'm not doing anything with DELECT until after it's settled. A complete rewrite of DELECT with a new dialect model is scheduled for the next host kit release. | |
Steeve 23-Feb-2010 [15876x2] | i take the risk (using delect), I onl |
I only hope the rewrite will just add more capabilities | |
Graham 23-Feb-2010 [15878] | Maybe we should also have a set! datatype ( need to use a different name though ) to indicate a unique unordered collection |
BrianH 23-Feb-2010 [15879] | And that dialect you mention is ambiguous - you need the keywords. |
Steeve 23-Feb-2010 [15880x2] | it was an just example. We can have default behaviour for several data-type, and use keywords only to allow disambiguation |
a tuple is an IP by default, an integer is a port-id by default. etc... | |
BrianH 23-Feb-2010 [15882] | And a scheme is nothing by default. |
Graham 23-Feb-2010 [15883] | userid and password and domains are ...the same |
Steeve 23-Feb-2010 [15884] | a word is scheme by default :) open [http 12.34.45.56 80] |
BrianH 23-Feb-2010 [15885] | Graham, we have set functions that work with the block! type, we don't need a set! type. There is a budget for built-in types - we can only have a limited number of them. There has to be a major need that can't be handled easily enough otherwise for a new built-in datatype to be added. A set! type might merit a user-defined datatype, or a spoofed datatype like the ones I added to 2.7.7+, but it's not an extreme enough difference from the behavior of block! with set functions to merit a full datatype. |
Graham 23-Feb-2010 [15886] | Seems a bit of overhead if you're trying to maintain a set if you have to check each time you add something if it already exists or not. |
BrianH 23-Feb-2010 [15887] | Which is why I want an INCLUDE function, the opposite of EXCLUDE. |
Steeve 23-Feb-2010 [15888] | bitsets are exactly what you need graham (only working with sets of integers or chars, though) |
BrianH 23-Feb-2010 [15889] | Maps work well for that too, using #[true] as the value or #[none] for not there. Works great, works with FOREACH. |
Steeve 23-Feb-2010 [15890] | but heavy :) |
older newer | first last |