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

World: r3wp

[Rebol School] Rebol School

PatrickP61
23-Sep-2010
[3301]
Oh God, the Rebolers understand me -- I must be starting to talk 
Rebol now!!! ha
Sunanda
23-Sep-2010
[3302]
I understand :)
  ANY is really a short-cut for OR, so:
  if any [a = 1 b = 2] 
means
   if (a = 1) or (b = 2)
BrianH
23-Sep-2010
[3303]
But the trick is that with ANY it will only evaluate the expressions 
until it finds the first TRUE? one, not the rest. With OR both the 
expressions are evaluated. ANY and ALL are used as control structures 
too.
Maxim
23-Sep-2010
[3304]
they're even more usefull in R3 now that more functions are none 
transparent  :-)
PatrickP61
23-Sep-2010
[3305]
Yes, so if I said something like DATA: ANY [ val1 val2] then the 
first non empty value would be set to DATA right?
Maxim
23-Sep-2010
[3306]
first true? value (not none not fase)
BrianH
23-Sep-2010
[3307]
Or less useful, depending on whether the none was an error. Learn 
to love ASSERT in R3.
PatrickP61
23-Sep-2010
[3308]
ASSERT?  Looking it up now
Maxim
23-Sep-2010
[3309x2]
for example:  0, "", []  would end up into data.
brian, is assert faster than its equivalent  [any all] combination 
?
PatrickP61
23-Sep-2010
[3311]
Thank you Maxim and Brian.  I enjoy your help!
BrianH
23-Sep-2010
[3312]
ASSERT is as fast as ANY, but faster once you add the error generation 
code to the ANY statement. ASSERT/type is *much* faster than ANY.
Maxim
23-Sep-2010
[3313]
cool
BrianH
23-Sep-2010
[3314x2]
ASSERT is a great way to integrate your tests right into your code, 
making TDD irrelevant. The module system uses ASSERT a lot to catch 
attempts to hack the security.
For now, at least. We may switch to explicit error generation in 
some cases, for more informative errors.
PatrickP61
6-Oct-2010
[3316]
In R2 I'm trying to define a function that will return back 120% 
of some values similar to this:

scale: func [ val ][ val * 1.2 ]  <-- this works but returns a decimal 
-- I'd like it to return integer, so I tried

scale: func [ val ][ to-integer reduce [ val * 1.2 ]]  <-- doesn't 
work  -- what am I doing wrong
GrahamC
6-Oct-2010
[3317x2]
remove the [ ]
and the reduce
Maxim
6-Oct-2010
[3319]
it needs parens

to-integer (val * 1.2)
GrahamC
6-Oct-2010
[3320]
you sure?  '* should take precedence
PatrickP61
6-Oct-2010
[3321]
scale: func [ val ] [ to-integer val * 1.2 ]

AS I read it, it looks like, take the integer of val, then multipy 
by 1.2, which in my mind would return a decimal, but that is not 
happening that way right?
Maxim
6-Oct-2010
[3322]
Graham, yes your right..
GrahamC
6-Oct-2010
[3323]
mine?
PatrickP61
6-Oct-2010
[3324]
yes
GrahamC
6-Oct-2010
[3325]
* has higher precedence than 'to-integer so it gets used first
PatrickP61
6-Oct-2010
[3326]
Thank you for that clarification!
Maxim
6-Oct-2010
[3327]
Pat, there is only one precedence rule in rebol expressions:

 ops resolve left to right, THEN functions are interpreted in argument 
 grabing order.
PatrickP61
6-Oct-2010
[3328]
So any ops (i guessing that is any math expression) is evaled first 
left to right, then however the arguments are evaluated -- right?
Maxim
6-Oct-2010
[3329]
which is annoying when using comparison ops with functions... ex:
if length? val = 3  ; wrong... 

val=3 ; true
length? true ; error
GrahamC
6-Oct-2010
[3330]
to-integer multiply 10 1.125 => 11
Maxim
6-Oct-2010
[3331]
so you always have to put the ops BEFORE comparing to a function...

if 3 = length? val
GrahamC
6-Oct-2010
[3332]
length? equal? 3 val
PatrickP61
6-Oct-2010
[3333]
so THAT is why I sometimes see some IF statements like that!!!
Maxim
6-Oct-2010
[3334]
yes
GrahamC
6-Oct-2010
[3335]
easier to use the function equivalents
PatrickP61
6-Oct-2010
[3336]
What do you mean GrahamC?
GrahamC
6-Oct-2010
[3337x2]
equal? instead of =
add instead of +
multiply instead of *
PatrickP61
6-Oct-2010
[3339]
ahhh I see
Maxim
6-Oct-2010
[3340x2]
if you want to use ops the way your head probably thinks about logic, 
you'll need to use parens which add a (minuscule) slowdown... really 
its a very small hit.

IF (length? val) > 3 

but this can be recoded as:

IF 3 < length? val
the problem with using funcs is that they extremely confusing to 
read.  so they are very rarely used.
PatrickP61
6-Oct-2010
[3342]
Very good to know!
Maxim
6-Oct-2010
[3343]
and for the record... this was wrong...

length? equal? 3 val

it should be

equal? length? val 3
GrahamC
6-Oct-2010
[3344]
that reads better :)
Maxim
6-Oct-2010
[3345]
the problem is that 3 and equal? go together... obviously I chose 
to order them this way to prove the point... but on any expression 
with more than 2 or 3 ops... function use becomes so complex to decipher 
that its worth it, just adding parens.


I did tests a while back and enclosing things in parens was usually 
practically invisible in loops... just a single path evaluation (like 
pair/x) takes up much more time IIRC.
PatrickP61
24-Oct-2010
[3346]
Got a simple question:


I defined a function called pref.  Its purpose is to simply print 
a precise time and value (which could be one of several values), 
but it is not doing what I expect:

pref:	func [value][print [now/time/precise "-->" value]]

pref	["Your current directory is" what-dir]    ; <-- wanted hh:mm:ss:xxx 
--> Your current directory is ...


but instead I got this:   15:04:43.968 --> Your current directory 
is what-dir


the function did evaluate the now/time/precise correctly, but did 
not evaluate the what-dir.  What can I do to get it to resolve all 
passed variables?
sqlab
24-Oct-2010
[3347]
pref	reduce  ["Your current directory is" what-dir]
PatrickP61
24-Oct-2010
[3348]
oh yes,  reduce!!!  Thank you
PatrickP61
15-Dec-2010
[3349x2]
I don't understand this situation:
>> help same?
USAGE:
        SAME? value1 value2

DESCRIPTION:
        Returns TRUE if the values are identical.
        SAME? is a native value.

ARGUMENTS:
        value1 (any-type!)
        value2 (any-type!)

s1: "series"
s2: copy s1
same? s1 s2
== false


The two values are two separate yet identical values.  Does identical 
mean the same reference ie the same memory location in rebol or am 
I not understanding what identical means?
Should the description read like this:

DESCRIPTION:
        Returns TRUE if the values are identical references.