World: r3wp
[!REBOL3-OLD1]
older newer | first last |
Maxim 3-Apr-2009 [12608] | I was going to ask what assert is about? |
BrianH 3-Apr-2009 [12609x2] | Well, this is one of those functions that *has* to be as bulletproof and efficient as possible. Even Carl defers to my judgement on LOAD. I try to make it easy to read, but there's no point about worrying about lost comments when the source is a CHAT 26 LF away. |
ASSERT: http://www.rebol.net/r3blogs/0178.html | |
Maxim 3-Apr-2009 [12611] | thx |
Anton 3-Apr-2009 [12612] | You appear to be doing a very good job of it, overall, don't get me wrong. I wish you'd see my point of view with respect to other (future) users who will view the code in the console, not in some source file locatable somewhere if you're lucky and the RebDev chat server is still running. |
BrianH 3-Apr-2009 [12613x2] | DevBase is where the source will be, with full history. It's one of the primary features of R3. It's not going away. |
I mean, we'll probably have source packages and we will have DocBase and the manual, but DevBase is where the source is. | |
Maxim 3-Apr-2009 [12615] | what does assert return when all is ok? true? |
BrianH 3-Apr-2009 [12616] | Yes. If it's not OK it throws an error. After an assert you can count on the conditions being true. |
Maxim 3-Apr-2009 [12617x2] | is there a none returning version of assert... a bit like first vs pick ? |
all intersting stuff btw. | |
BrianH 3-Apr-2009 [12619x2] | Yeah. ALL. |
And FIRST returns none in R3. We're trying to make the errors more useful and meaningful in R3. | |
Maxim 3-Apr-2009 [12621] | that would mean less errors? but better ones? |
BrianH 3-Apr-2009 [12622] | Yup :) |
Maxim 3-Apr-2009 [12623x3] | cool. |
does ALL also support the /type refinement in R3 ? | |
now you see... I'm all fired up on R3 and I've stoped working for the past hour.... ;-) glass is now an hour behind schedule ;-) | |
BrianH 3-Apr-2009 [12626x2] | Nope, but SWITCH TYPE?/word does (effectively). |
Or FIND typeset! value. | |
Maxim 3-Apr-2009 [12628x2] | my first R3 func .... valid?: func [spec][attempt [assert spec]] ; -) |
so I can assert within any/all blocks ;-) | |
BrianH 3-Apr-2009 [12630] | valid?: func [spec /type][attempt [apply :assert [:spec type]]] |
Maxim 3-Apr-2009 [12631] | yess apply that is a great addition to R3 8-D |
BrianH 3-Apr-2009 [12632] | Already backported to R2-Forward. |
Maxim 3-Apr-2009 [12633] | must be a bit slow though... is it? |
BrianH 3-Apr-2009 [12634x3] | R2-Forward is also in DevBase (and has *lots* of comments). |
The R2-Forward APPLY is not as fast as the native, but I've found it fast enough for wrapper functions in R2. | |
Plus it disables the special treatment of 'a and :a declared parameters. | |
Maxim 3-Apr-2009 [12637] | is that gone in R3? (set word arguments) |
BrianH 3-Apr-2009 [12638] | Nope, they just work better. |
Geomol 3-Apr-2009 [12639] | Don't forget to keep it simple! As simple as possible, but not simpler. |
PatrickP61 6-Apr-2009 [12640x2] | Is there a way in R3 to "capture" error messages when using ATTEMPT, or some other command. i.e. >> WRITE %missing/File.txt to-binary "test string" ** Access error: Cannot open: %missing/File.txt reason: -3 ** Where: WRITE ** Near: WRITE %missing/File.txt to-binary "test string" >> ATTEMPT [WRITE %missing/File.txt to-binary "test string"] == none Is there any way to get the error message from the ATTEMPT? |
Found it! >> probe disarm try [WRITE %missing/File.txt to-binary "test string" make object! [ code: 500 type: 'Access id: 'cannot-open arg1: %missing/File.txt arg2: -3 arg3: none near: [WRITE %missing/File.txt to-binary "test string"] where: [WRITE try] ] == make object! [ code: 500 type: 'Access id: 'cannot-open arg1: %missing/File.txt arg2: -3 arg3: none near: [WRITE %missing/File.txt to-binary "test string"] where: [WRITE try] ] | |
ICarii 6-Apr-2009 [12642] | in R3 is there a way to intercept the write event before the send occurs - and if not, is there a way to force a send before another write takes place in an Async queue? I'm getting an issue where multiple write events are being cached and sent all at once (about 10 write events per second). |
Graham 6-Apr-2009 [12643] | What I think most people do is this: if error? set/any 'err try [ ][ probe mold disarm err ] |
Izkata 6-Apr-2009 [12644] | Is there any advantage to using set/any over a set-word ? |
Gregg 6-Apr-2009 [12645] | I'm not sure what you mean. They're unrelated. |
Izkata 6-Apr-2009 [12646x2] | if error? err: try [ ][ print mold disarm err ] |
I've always used the second way, but almost everywhere else, I see others use set/any | |
Gregg 6-Apr-2009 [12648] | Ah, I see now *a* set-word!. :-\ Consider an unset! result: >> if error? err: try [()] [print mold disarm err] ** Script Error: err needs a value ** Near: if error? err: try [()] >> if error? set/any 'err try [()] [print mold disarm err] == none |
Izkata 6-Apr-2009 [12649] | Ohhkay, guess I've just never run across it. Thanks |
Anton 6-Apr-2009 [12650] | Is there any way in R3 to optimize code such as out: insert insert insert insert insert [] 'fill-pen color [text vectorial] 0x0 "hello" ? I think the appearance of n INSERTs is kind of ludicrous. People are doing this for performance reasons, so the usual way we would optimize the code (which produces an intermediate block), isn't an answer. I've forgotten if R3 has any way. (A quick look at APPLY and MAP doesn't seem to bear any fruit.) |
Steeve 6-Apr-2009 [12651x2] | it's not more fast than using a reduce or a compose. |
but it saves memory overheads, exspecially in big loops | |
Anton 6-Apr-2009 [12653x5] | ---> thus, does become a speed issue. |
It would be nice to be able to say: loop 5 [insert] [ ] v1 v2 v3 v4 v5 | |
so no intermediate block is generated. | |
Or have a method of reducing only the items in a block as they are being applied, without generating a new temporary block to hold them. | |
(This idea has been discussed before, somewhere...) | |
older newer | first last |