World: r3wp
[Core] Discuss core issues
older newer | first last |
Geomol 30-Oct-2011 [2544x3] | Oh, those border areas. That really really special cases not seen in real applications. |
But, yeah, you're right in those special cases. | |
Many languages return inf in cases with math overflow. I would prefer load mold 1.7976931348623157e308 to return [inf] instead of the now: ** Math error: math or number overflow And that inf in the block should of course be of type decimal!. | |
Ladislav 30-Oct-2011 [2547x3] | That is a low-level aproach in REBOL interpreter, hidden by the error triggering code |
And, I am content with the high level code taking care of exceptions | |
My FLATTEN function implementation is available at: http://www.rebol.org/view-script.r?script=flatten.r | |
james_nak 30-Oct-2011 [2550] | Guys, thanks for all the input. I didn't mean to cause this much excitement. :-) I just wanted to get my crazy DB program to work. And by the way, it does, at least so far. |
Geomol 30-Oct-2011 [2551] | James, it's usually interesting to explore the many corners of the language. Good you program work! That's important. |
james_nak 30-Oct-2011 [2552] | Thanks Geomol. |
Henrik 30-Oct-2011 [2553] | I sometimes wonder about having a NEXT that does not move to the tail, but only to the last element in cases where you always do a FIRST on the block afterwards to get the first element. Then you don't need the trivial unless tail? next blah [blah: next blah] idiom. |
Ladislav 30-Oct-2011 [2554] | In my opinion, the unless tail? next blah [blah: next blah] should not be used at all. (I suppose, that it is in a cycle?) |
Henrik 30-Oct-2011 [2555] | more like list navigation, where one may move back and forth one item at a time, but never past the last item. |
Ladislav 30-Oct-2011 [2556] | you can define it as a function, if you need it, but it probably never becomes a native |
Henrik 30-Oct-2011 [2557] | I would not think it would. |
Geomol 30-Oct-2011 [2558] | What if the block is empty? It should be possible to avoid the UNLESS ... idiom, maybe by some careful coding. |
Geomol 31-Oct-2011 [2559x2] | In R2: >> type? :sine == native! >> type? :sine/radians ** Script Error: sine expected value argument of type: number In R3: >> type? :sine == native! >> type? :sine/radians == native! >> do :sine 30 == 0.5 >> do :sine/radians 30 == 0.5 ; Wrong result!? Shouldn't things like :sine/radians just be invalid get-paths? |
Think about passing :sine/radians as an argument to a function. So when using that argument in the function, the user would expect sine/radians to be calculated, but it doesn't, and it will be very difficult to implement that feature, if at all possible. | |
Ladislav 31-Oct-2011 [2561x5] | In R2: >> type? first [:sine/radians] == path! in R3: >> type? first [:sine/radians] == get-path! |
(R2 does not have get-paths) | |
Think about passing :sine/radians as an argument to a function. - you mean like this? type? first [:sine/radians] ? As far as I am concerned, I did not expect any additional evaluation | |
Aha, you probably meant that you did not like same? :sine :sine/radians ; == true | |
You can put that into CureCode as a wish, stating, that you prefer an error to be triggered instead | |
Geomol 31-Oct-2011 [2566] | Today's Moment of REBOL Zen: >> f: func [a op b] [a op b b] >> f 1 quote / 2 == 1 >> f: func [a op b] [op a b] >> f 1 quote / 2 == 0.5 |
BrianH 31-Oct-2011 [2567x5] | Note: That is in R2, where QUOTE word! doesn't work (known limitation). On R3, the / is not dereferenced. |
Also, in R2 operators are evaluated by DO itself, which has a set of keywords that it transforms from operator to prefix function syntax. R3 does this swap by value, not by name, so operator renaming is possible. However, this leads to behavior like this: >> f: func [a op b] [a op b b] >> f 1 get quote / 2 == 2 >> f: func [a op b] [op a b] >> f 1 get quote / 2 ** Script error: op operator is missing an argument ** Where: f ** Near: f 1 get quote / 2 This is why, when you are accepting and calling function values, it's best to either limit yourself to the types of functions you are expecting, or use APPLY. >> f: func [a op b] [apply :op [a b]] >> f 1 get quote / 2 == 0.5 >> f 1 :divide 2 == 0.5 | |
R2 has an APPLY too, in mezzanine but it works the same way. It was added for security and function wrappers. | |
Ladislav, Geomol, that same? :sine :sine/radians bug is already in CureCode here: http://issue.cc/r3/1559- please add your comments there. | |
That issue is a really good reason to use ASSERT/type to validate your paths. | |
Ladislav 31-Oct-2011 [2572] | I see it as a minor issue. I would not be disappointed even if it stays as is. |
james_nak 31-Oct-2011 [2573] | Brian, aha, "Assert": another one of the newer, non-dictionary functions. Thanks for pointing those out to me the other day. I now have a list. |
BrianH 31-Oct-2011 [2574x2] | It is a potential security hole, but not more of one than assigning a function to an object field. It requires the same ASSERT/type call to screen for it. Still, it would be nice if it triggered an error on evaluation, especially since newbies would benefit from that error when they naively try to do a get-path for a function call instead of using APPLY or a direct call. |
James, ASSERT in R2 is not yet as good as ASSERT in R3. There are some limitations, most notably that you can't use ASSERT/type to validate a path. A proper native ASSERT is on the top of the list to add to R2 in the next version, whenever that comes. | |
james_nak 31-Oct-2011 [2576] | To be frank, it is most likely down the road before I ever use the new functions. I can tell just by perusing it that I would need to spend some time trying to understand what they do. But thanks for the input. |
BrianH 31-Oct-2011 [2577] | APPLY is a lot more useful in R2 than ASSERT; be sure to take a look at that one. |
james_nak 31-Oct-2011 [2578] | I will. Thanks. |
Henrik 2-Nov-2011 [2579x2] | Regarding my UNLESS TAIL? NEXT 'blah thing, perhaps this is more elegant: blah: min next blah back tail blah |
hmm... that does a comparison on the first value in the block instead of the index. is that useful? | |
Ladislav 2-Nov-2011 [2581] | That compares strings, (more general, since you can compare any strings, not just parts of the same head string starting at different positions) |
Henrik 2-Nov-2011 [2582] | yes, you are right. |
Geomol 9-Nov-2011 [2583] | Today's Moment of REBOL Zen: >> length? charset "" == 256 >> length? to binary! charset "" == 32 |
Oldes 9-Nov-2011 [2584] | 1 byte = 8 bits so 32 * 8 = 256bits:) |
Geomol 9-Nov-2011 [2585x3] | Bingo! But why? Does it make sense, that the length of a bitset! is reported as being 256? I guess, it does, as we can insert values from 0 to 255 into a bitset. |
Why isn't the length of a char one? >> length? #"a" ** Script Error: length? expected series argument Kinda related: it's funny, that a bitset! isn't a series, even if we can ask the length of it: >> series? charset "" == false | |
Or the length of a char could be 8, if we count in bits. But I feel, it would make more sense to give the length of a char as being 1. (I was working on a mezzanine version of string parsing, where skipping is much easier, if LENGTH? worked with chars too.) | |
Andreas 9-Nov-2011 [2588] | >> length? make bitset! 1024 == 1024 |
Geomol 9-Nov-2011 [2589] | Wow, didn't see that coming! Now, what does that mean? (Always more to learn.) |
Andreas 9-Nov-2011 [2590x2] | A bitset is just a collection of N bits which are either set or cleared. |
A charset is a 256-element bitset, as R2 recognises 256 distinct characters. | |
Geomol 9-Nov-2011 [2592] | I know the benefit of bitsets in parsing. For what use are other kinds of bitsets? |
Andreas 9-Nov-2011 [2593] | Why isn't the length of a char one? Because characters are no series datatype and therefore it does not make much sense to speak or their length. That's about the same as asking "Why isn't the lenght of an integer one?" or "Why isn't the length of a logic! one?" |
older newer | first last |