World: r3wp
[!REBOL3]
older newer | first last |
Maxim 21-Sep-2010 [4982x3] | >> a == make map! [ e 4 ] >> a/b: func [][print 3] >> a/b 3 shoudn't it return a function type? |
I mean... I though maps where for storage rather than evaluation... | |
though=thought | |
Sunanda 21-Sep-2010 [4985] | docs just say "not documented" http://www.rebol.com/r3/docs/datatypes/map.html Use select a 'b to return the function itself Use curecode to get the behaviour normalised :) |
Maxim 21-Sep-2010 [4986x2] | hehe |
ah didn't think of select... doh. but I will CC it, just to get Carl's feedback. | |
BrianH 21-Sep-2010 [4988x4] | Maxim: "shoudn't resolve have a refinement called /bind making it easier to rebind data to target context in a single pass?" There is a REBIND internal function that hasn't been exported yet. Ask Carl or request in CureCode for the function to be exported. |
Now for the other binding stuff: * SET is a low-level function that would be slowed down immensely by adding any refinements. * SET does handle the unbound scenario: It triggers an error. You can then handle the error. * R2 and R3 get their speed from the direct binding model. The core speedup of that model is that SET doesn't bind. * LOAD in R3 is a high-level mezzanine function. It is meant to be as fast as possible given its purpose, but being fast is not its main goal; user-level flexibility is. Most of the overhead of LOAD is in handling all of its various options, as refinements, file extensions and script header settings. If you know what you are doing, you can always optimize your code by doing it directly instead of having LOAD try to figure out that is what you want to do. LOAD is not meant for use in tight loops. * Henrik, ChristianE, the R3 standard answer to the question of how to make BIND TO-WORD "a" more efficient or friendly in R3 is this: You are encouraged to not program that way in R3. Converting strings to words is something you should do once, not all the time in tight loops. Your code will be much more efficient if you work in REBOL data rather than storing your code in strings and converting at runtime. Strings are for data, or script source, not for containing scripts at runtime. This is a good rule for all REBOL versions, but especially for R3 with its Unicode strings vs. shared UTF-8 words. * I have recently refactored LOAD so that it is broken into smaller, more efficient functions. You might find that those functions would work better for you in lower-level code. But this was done to let us make LOAD *more* powerful, not less, so the same advice I gave above about not using LOAD in tight loops still applies. I don't yet know if the new LOAD is faster or slower, but it is safer and easier to understand and modify, and you can make your own LOAD replacement that calls the same low-level functions if you like. Plus, you get compressed scripts :) | |
Maxim, maps are meant to be used like objects, but with different tradeoffs. The evaluation that you show is not a bug, it is by design, and it works for functions stored in blocks as well. >> a: reduce ['b func [] [3]] == [b make function! [[][3]]] >> a/b == 3 Use get-paths if you don't want evaluation: >> print mold :a/b make function! [[][3]] | |
So the evaluation has nothing to do with maps, it's a path evaluation thing. You can still store stuff in a map, but as with storing active values anywhere you have to be careful. | |
Maxim 21-Sep-2010 [4992] | yeah, ok, so its not a map thing... that is now obvious, since the select doesn't evaluate it.. |
BrianH 21-Sep-2010 [4993] | Welcome to the wonderful side effects of increased language consistency :) |
Maxim 21-Sep-2010 [4994x2] | I like the fact that you are modularizing LOAD... I did try to modify it before and well... I thought you where brave of even getting it to work at that point :-) |
I had forgotten about get paths... thanks... that is what I need. | |
BrianH 21-Sep-2010 [4996] | Carl requested the modularization. And I definitely wanted to do it because the whole module and script system didn't pass the hit-by-a-bus requirement. |
Maxim 21-Sep-2010 [4997] | hehe... I agree ;-) |
Andreas 21-Sep-2010 [4998] | I can't help but wonder if we'll ever get maps that are meant to be used like maps ... |
Maxim 21-Sep-2010 [4999x2] | actually the cultprit is the path walking here... but I agree that using them as objects within path notation is strange. |
brianH can you tell me *why* path notation evaluates map lookups? | |
Andreas 21-Sep-2010 [5001] | (I have no gripe with the path notation. It's the old strict-equal? issue the above was hinting at.) |
Maxim 21-Sep-2010 [5002x2] | brianH " increased language consistency" if this where true, then we couldn't store object in blocks without evaluating them by default either. IMHO maps are just hash tables, just like a block.... storage, not vector jump tables. but that might just me my skewed view of the world. |
oops... sorry my last statement was a bit messed up... ignore the first line... | |
Andreas 21-Sep-2010 [5004x3] | Well, it sure _is_ more consistent to always have paths which ultimately refer to a function! make the function an "active" value. |
Wether that consistency is desirable or worth anything is on another page. | |
But it generally simplifies things if you don't have to re-define the semantics of all path variations. | |
Maxim 21-Sep-2010 [5007] | anyways, we do have get paths now... so I guess I'll just shut up and stop stirring air ;-) |
Andreas 21-Sep-2010 [5008] | Yeah, and that illustrates the consistency argument: if paths with a map! as underlying would be redefined to behave like get-paths per default, what should get-paths on maps do :) ? |
Maxim 21-Sep-2010 [5009] | shave my neighbor's unclean dog? ;-P |
Andreas 21-Sep-2010 [5010] | I'm more for making coffee, but that's not too bad an idea either :) |
Ladislav 22-Sep-2010 [5011x2] | Hi, I corrected http://www.fm.tul.cz/~ladislav/rebol/evaluate.r(I omitted a USE-RULE call for the last rule in the script), and renamed the accumulator 'a in accordance with industry standards. Also, I added an efficiency note related to R3 protection disallowing us to use a simple binding method to create the USE-RULEs during function initialization (creation) instead of creating the USE-RULEs every time the respective function is called, which is inefficient. I wonder, whether we should consider a way how to allow the creator of the function to perform some additional initialization during function creation. |
As I demonstrated in the %use-rule.r script, such an initialization is possible using a method to circumvent the protection R3 uses, but it looks neither simple, nor very efficient. | |
Pekr 22-Sep-2010 [5013] | Some bugfixing for A108 - http://www.rebol.com/r3/changes.html |
Ladislav 22-Sep-2010 [5014x5] | This is probably the least "cryptic" way how to be able to initialize functions: func-with-init: func [ init [block!] {initialization code} spec [block!] { Help string (opt) followed by arg words (and opt type and string) } body [block!] "The body block of the function" ] [ spec: copy/deep spec body: copy/deep body insert body compose/only [ if init? (init) init?: false ] body: use [init?] reduce [ first [init?:] true body ] make function! copy/deep reduce [spec body] ] >> fr: func-with-init [initialized: now] [] [print ["this function was initialized:" initialized]] >> fr this function was initialized: 22-Sep-2010/9:36:22+2:00 |
The initialization has to occur in the function body, unfortunately, otherwise the R3 protection does not allow BIND to be used, which, on the other hand, means, that the IF call is done every time the function is called, which means additional overhead | |
But, anyway, this solution looks less "cryptic" than the one used in the %use-rule.r script, I guess | |
Another disadvantage is, that for this version to work, the 'init? variable must not be an argument (local variable) of the new function. | |
http://www.fm.tul.cz/~ladislav/rebol/func-with-init.r | |
Maxim 22-Sep-2010 [5019] | A108 now uses # to represent none... neat! |
Gregg 22-Sep-2010 [5020x2] | Thanks for doing the func-with-init research Ladislav. While I think we sometimes focus too much on optimization, I can see this as being important in the big picture for writing function generators that produce efficient results. |
This version is not as cryptic, even though it's longer. I can understand it. :-) | |
Henrik 22-Sep-2010 [5022] | http://www.rebol.com/article/0487.html Function splitting. |
Pekr 22-Sep-2010 [5023] | bleeeah :-) REBOL as a messaging language has networking protocols being an optional package = no standard functionality over the REBOL installations. Great, what's removed by default next? |
Andreas 22-Sep-2010 [5024x6] | Pekr, network protocols are still there and bundled within the binary. |
So they still are "standard functionality over the REBOL installations". | |
It's just that you'll hvae to explicitly import them, if you need them. | |
Let's use DECODE-CGI as a simple example: currently in R2, you fire up R2 and can use decode-cgi in your code straight away. | |
Currently in R3, it's not there at all. | |
In the future in R3, the code itself will be bundled with R3, but if you fire up R3 and type decode-cgi, it won't be available straight away. You'll have to explicitly import the CGI functions with import 'cgi first. | |
Pekr 22-Sep-2010 [5030] | do you use rebol without networking or db protocols? what for? |
Andreas 22-Sep-2010 [5031] | Yes. Many different scenarios. I have never used REBOL's ftp protocol, for example. |
older newer | first last |