r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Ladislav
29-May-2011
[1554x3]
Due to specifics in REBOL arithmetic it was deemed desirable to remain 
compatible with some of them when defining more arithmetic functions
In essence, the MOD function is a "helper" for ROUND. It uses the 
Boute's definition, but assuming that the divisor is positive. If 
you do want to use a more comfortable variant, you can use the MODULO 
function, which does not make such an assumption.
Still, there are arithmetic specifics, regarding rounding.
PeterWood
30-May-2011
[1557]
A bug?

>> cur: what-dir

== %/Users/peter/

>> cd %Code/Rebol

== %/Users/peter/Code/Rebol/
>> cd cur

** Access Error: Cannot open /Users/peter/Code/Rebol/cur/

** Near: change-dir to-file path

>> change-dir cur

== %/Users/peter/
Though this works:

>> cd :cur
== %/Users/peter/
Geomol
30-May-2011
[1558x4]
>> ? cd 
USAGE:
    CD 'dir


Notice the non-evaluated Literal Argument. So when you use CD, the 
argument isn't looked up.

>> ? change-dir
USAGE:
    CHANGE-DIR dir


With CHANGE-DIR, it is looked up. It is expected behaviour, but maybe 
confusing, that CD and CHANGE-DIR are different.
If I remember correctly, CHANGE-DIR came first, and it's suited for 
being used in scripts. CD is suited for using at the prompt.
<tab> completion of directories and files works, if you give argument 
as a file! datatype, but not when giving word! argument for CD. I 
believe, this is hard to get by.
And then, maybe if CD were constructed like this:

	cd: func [
		'dir [file!]
	][
		...
	]
Henrik
2-Jun-2011
[1562]
What does the PATH function do?
Geomol
2-Jun-2011
[1563x2]
>> blk: [a b c]
== [a b c]
>> path blk 'a
>> blk
== [a]
>> blk: [a b c]
== [a b c]
>> path blk 'b 
>> blk         
== [a b]
>> blk: [a b c]
== [a b c]
>> path blk 'c 
** Script Error: Invalid path value: c

Maybe for some internal use?
From group Core-old:


A: the PATH action is what the interpreter uses to evaluate VALUE/selector 
expressions for each datatype. It is an internal action and has no 
external purpose in programs. These kinds of words often appear as 
a sort of 

side-effect" from how REBOL is structured.  Datatypes are implemented 
as a sort of object class, where the interpreter "sends messages" 
to the class to evaluate expressions. The PATH action is a message 
that tells the datatype to perform a pick-like or poke-like internal 
function."
Henrik
2-Jun-2011
[1565]
interesting, thanks
Geomol
2-Jun-2011
[1566]
It seems to original come from a post in group "RT Q&A" dated 11-Dec-05.
Gabriele
3-Jun-2011
[1567]
yep, that's supposed to be unset but it somehow has been leaking 
out for a while.
Henrik
4-Jun-2011
[1568x3]
is there any official way of using SORT/COMPARE on a block containing 
a mix of different datatypes?
or perhaps more correctly, a method to use LESSER? or GREATER? on 
a mix of different datatypes?
Looks like SORT uses this datatype map internally:


[unset! datatype! native! action! function! object! word! set-word! 
get-word! lit-word! refinement! none! logic! integer! decimal! money! 
time! date! char! pair! event! tuple! bitset! string! issue! binary! 
file! email! url! tag! image! block! paren! path! get-path! set-path! 
lit-path! hash! list!]
onetom
4-Jun-2011
[1571]
how do u know?
Henrik
4-Jun-2011
[1572x3]
I made a block of all datatypes and sorted it. That was the outcome.
Nevertheless, it seems the method is going to be complicated and 
slow for /COMPARE as I don't know how it handles periferal cases 
like:

sort reduce [true false]
== [false true]

which cannot be compared outside SORT using:

lesser? true false
** Script Error: Cannot use lesser? on logic! value


and I don't know and should not need to know how many periferal cases 
there are.
the solution to me would be that comparison functions use the same 
logic as SORT.
Geomol
4-Jun-2011
[1575x4]
Since you can sort a block of logic! values, then <, > etc. should 
work on them, so that's missing. Doing to-integer on logics first 
solve it. And you have to check all the other datatypes by hand first 
to find out, where possible problems are, I guess.
Sorting pairs. hmm...

>> sort [1x2 2x1]
== [2x1 1x2]

Doesn't make sense.
It shouldn't be possible to order pairs, like complex numbers. (Unless 
you define your own rules.) :)
But as pairs are used to make GUIs, it maybe makes sense to sort 
them in this case. Top of screen is before bottom.
Henrik
4-Jun-2011
[1579]
SORT seems to sort anything that you throw at it and I think that 
makes sense, when making GUI lists. Right now I have a problem in 
that I can't control the input datatype and must sort anyway. The 
structure of the data is currently so that SORT/COMPARE is best to 
use, but LESSER? and GREATER? prevent this from being simple.
Geomol
4-Jun-2011
[1580]
Today's Moment of REBOL Zen:

>> forever [prin now/time // 7 wait 1 loop 20 [prin bs]] 
0:00:00.000000002
Gregg
4-Jun-2011
[1581]
Very cool John.
onetom
5-Jun-2011
[1582]
:)) i didn't know about bs until now...
Gabriele
5-Jun-2011
[1583]
forever [prin now/time // 7 wait 1 prin cr]

(remainder on time is funny)
Geomol
5-Jun-2011
[1584x3]
Yeah, looks like a bug.
onetom:

>> ? char!
Found these words: 
   backslash       char!     #"\" 
   backspace       char!     #"^H" 
   bs              char!     #"^H" 
   cr              char!     #"^M" 
   escape          char!     #"^[" 
   lf              char!     #"^/" 
   newline         char!     #"^/" 
   newpage         char!     #"^L" 
   null            char!     #"^@" 
   slash           char!     #"/" 
   tab             char!     #"^-"
And then there is one string related to those, crlf.
BrianH
5-Jun-2011
[1587]
The one that gets me is remembering that newline is a character and 
new-line is a function, rather than vice-versa.
Maxim
5-Jun-2011
[1588]
me too.  I always mix them up... isn't this something that could 
be changed in R3?
GrahamC
5-Jun-2011
[1589]
Wait for R3
Geomol
6-Jun-2011
[1590x2]
Exchanging newline and new-line, and I bet a lot of people will mix 
those up. :) Why do you feel, they should be the other way around?
newline could be called EOL?
http://en.wikipedia.org/wiki/Newline
BrianH
6-Jun-2011
[1592]
I don't feel that they should be the other way around. The problem 
is that there is no obvious reason why it should be one way or another, 
so when trying to remember it I get it wrong about half the time. 
Using 'eol would be good, but wouldn't help the problem because we 
can't undefine 'newline in R2 because of the backwards-compatibility 
rules.
Geomol
6-Jun-2011
[1593]
new-line could be called set-newline? :)
BrianH
6-Jun-2011
[1594]
You can't get rid of the old name in R2, you can just add new names. 
You have to get rid of the old name to solve the problem.
Geomol
6-Jun-2011
[1595x2]
Get rid of the bad old name and change the few scripts, that might 
use new-line. Problem solved!
If people don't want to change old scripts, then just make some script 
to be included (maybe by default using some option when calling REBOL), 
which define things like:

	new-line: :set-newline
BrianH
6-Jun-2011
[1597x2]
The backwards compatibility rules of R2 prohibit getting rid of the 
old name (backwards compatibility is the reason for R2's continuing 
existence). That definition would need to be included by default.
If people don't want to change old scripts they use R2 instead of 
R3.
Geomol
6-Jun-2011
[1599]
Maybe things like set-newline is for R3 then.
BrianH
6-Jun-2011
[1600]
As for SORT, that's an interesting problem. LESSER? and GREATER? 
are supposed to be constrained to datatypes that are comparable, 
and that have some form of magnitude or ordering. For datatypes that 
don't really have magnitude or ordering they don't really work. When 
it comes down to it, true is not greater than false inherently (considering 
it to be so is more of a moral stand). And none is not greater or 
less than 'a, they just aren't comparable concepts.


SORT doesn't have that luxury though, because it is designed to not 
fail (or rather, not trigger errors because a comparison fails). 
So it has to define some extra comparisons that don't really make 
any sense, as a fallback in the cases where there is no comparison 
that does make sense. The datatype ordering trick is one of those, 
where they are ordered by their inner datatype number, and different 
data that isn't otherwise comparable is ordered by its datatype number 
too (words are greater than unset but less than none, for instance). 
R3 has a list of those datatypes in order in system/catalog/datatypes, 
but if there's a similar list in R2 I don't know where it is - Henrik's 
above is a subset, just the datatypes with externally referenced 
values. R2's and R3's datatypes are in a different order.


SORT/compare is supposed to allow you to provide your own ordering 
function if the standard ordering doesn't make sense. However, if 
you want to support all of the comparisons that the built-in ordering 
supports, you have to make a really complex comparator function with 
a lot of special cases, and in the case of R2 replicate a lot of 
internal data; that function would be pretty slow too. This is why 
SORT/compare is more often used for more restricted cases, like reversing 
the order, or comparing based on object keys.
Sunanda
6-Jun-2011
[1601]
Good points about SORT, Brian.


One small observation. SORT has a /reverse refinement, so /compare 
is not needed for simply reversing the order of a sort.
BrianH
6-Jun-2011
[1602]
Agreed.
onetom
6-Jun-2011
[1603]
Geomol: crying from the gust (-; ? char! is beautiful