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

World: r3wp

[Core] Discuss core issues

BrianH
25-Jan-2008
[9017x2]
You don't rebind the function, you rebind its code block - not quite 
the same thing. Bind/copy wouldn't work because it creates a copy 
rather than rebinding the original block. You can alter the contents 
of the code block of a (R2) function, but you can't change the function's 
reference to that block to point to another block.
If you can create a new function, you can use bind/copy. It is occasionally 
possible to arrange your algorithm so that it is possible to replace 
a function without worrying about aliased references, but usually 
not.
[unknown: 5]
25-Jan-2008
[9019]
yeah I understand that but why would bind/copy ever fail where bind 
itself worked?
Anton
25-Jan-2008
[9020]
bind/copy goes deep.
[unknown: 5]
25-Jan-2008
[9021x2]
yeah
shouldn't it still work regardless
Anton
25-Jan-2008
[9023]
I think I remember, bind/copy is just a short equivalent to bind 
copy/deep.
[unknown: 5]
25-Jan-2008
[9024]
but if bind works and then you try the same code with bind/copy should 
it cause an error?
Anton
25-Jan-2008
[9025]
Just used when you don't want to modify the bindings of the original.
[unknown: 5]
25-Jan-2008
[9026]
yeah that is the way I understand it also which is why it suprised 
me in my code that bind works but when I simply add bind/copy in 
then it breaks the code.
Anton
25-Jan-2008
[9027x2]
Well, probably no error straight after binding, but if some other 
code rebinds it perhaps causes error later.
It depends on the situation. What is the situation you are in ?
[unknown: 5]
25-Jan-2008
[9029]
yeah that might be it
btiffin
30-Jan-2008
[9030]
What is the deal with mod and modulo?   What should   mod 10 3   
 mod 10 -3    mod -10 3   mod -10 -3   return?  Not what REBOL returns 
... what's the math of it supposed to be.


I accept  1 and 2, but -4 (mod -10 -3) freaks me out.  I don't use 
mod very often (and never with negative divisors or dividends), but 
it came up in a conversation with some student programmers (and I'm 
trying to convince them to give REBOL a try).
Anton
31-Jan-2008
[9031x2]
http://en.wikipedia.org/wiki/Modulo_operation
There is no single definition.
Tomc
31-Jan-2008
[9033]
I do not have a mental model of what a modulo < 2 could be never 
mind less than zero.  until is has an accepted definition in mathematics 
programming languages ought steer clear
btiffin
31-Jan-2008
[9034]
Thanks.  I just needed to source mod to see where it was coming from. 
 REBOL's mod does make mathematical sense, just needed to get my 
head round it.    Things like  mod -10 -11 being -21.


And Tom, yep.  :)  But I think I've grown to like REBOL's definition. 
  And I would expect anyone that needs negative divisors for a modulo 
calculation will understand the implications.
Oldes
31-Jan-2008
[9035x3]
>> ?? mod
mod: func [
    "Compute a nonnegative remainder of A divided by B."
    [catch]
    a [number! money! time!]
    b [number! money! time!] "Must be nonzero."
    /local r
][
    all [negative? r: a // b r: r + b]
    a: abs a
    either all [a + r = (a + b) positive? r + r - b] [r - b] [r]
]
>> ?? modulo
modulo: func [

    {Wrapper for MOD that handles errors like REMAINDER. Negligible
^-^-values (compared to A and B) are rounded to zero.}
    [catch]
    a [number! money! time!]
    b [number! money! time!] "Absolute value will be used"
    /local r
][
    throw-on-error [
        any [number? a b: make a b]
        r: mod a abs b
        either any [a - r = a r + b = b] [make r 0] [r]
    ]
]
? //
USAGE:
    value1 // value2

DESCRIPTION:
     Returns the remainder of first value divided by second.
     // is an op value.

ARGUMENTS:
     value1 -- (Type: number pair char money time tuple)
     value2 -- (Type: number pair char money time tuple)

so:
-10 // -3 == -1
the // is same like the mod(a, n) = a - n * floor(a / n) (from the 
Wiki page above)
Gregg
31-Jan-2008
[9038]
Ladislav spent a lot of time, and much discussion was had, on those 
functions.
btiffin
31-Jan-2008
[9039]
Yeah, I've grown to like the REBOL definitions since yesterday.  
:)
Pavel
8-Feb-2008
[9040x3]
To Oldes, any way to create general event (not gui) port? And create 
on demand events (fire and receive). Can such a port be global accesible 
to independent rebol processes? Can some scheme solve this?
Must this be a TCP port?
Or can it be memory to memory somehow?
Oldes
8-Feb-2008
[9043x2]
I don't think it can be memory to memory between independent processes.
Maybe the system port could be used, but I'm not sure.
Henrik
8-Feb-2008
[9045]
the easiest way is via TCP or a file, I think
Pavel
8-Feb-2008
[9046x2]
TCP should be functional, but for the curious guy How to put valid 
event into system port (not to mesh with other system events) and 
how to wait for it?
Is it possible to build own class of events in system port? To easy 
ignore other plenty of events.
Oldes
8-Feb-2008
[9048]
I never used system port so I don't know
btiffin
8-Feb-2008
[9049x3]
insert-event-func  ??
But, R2 doesn't allow event insertion though, only monitoring.
afaik
Pavel
8-Feb-2008
[9052]
Does anybody built an event marshaller (in Amiga words broker) for 
interprocess comuncation? Any coments welcome.
Robert
9-Feb-2008
[9053]
IIRC I posted this topic once but there was no real good solution 
to it. I often face the following problem:


My app performs a bunch of calculations based on user input. Now, 
if a user hacks in extremly big numbers, the app crashes because 
of "math overflow".


The hard part is that it's mostly impossible to predict at which 
calculation step this will happen. Making code "division by zero" 
proof is not problem, but how do I make my code "math overflow" proof?
Graham
9-Feb-2008
[9054]
Trapping the error is not good enough?
Gregg
9-Feb-2008
[9055x2]
Pavel, I've done various things for IPC. There is no standard REBOL 
solution I know of though. How best to do it depends on the rest 
of your app, it's design, and what you mean by "event marshaller". 
Simple TCP has worked well for me in the past.
I'm still hoping for ARexx type support built in to REBOL.
Robert
10-Feb-2008
[9057x2]
Graham, well how do you trap the error if you have hundreds of calculations? 
Just on the global level? That's what I do. But overall the app than 
fails.
To be really save, one has to check for overflow for every single 
operation.
Gregg
10-Feb-2008
[9059]
What about having a central calculation engine in the app, and passing 
everything through that?
Robert
11-Feb-2008
[9060x2]
How does this help? You still have to check for an overflow either 
while doing every single operation or upfront.
Example: We have this simple formular:

result: (a * b) + (c * d)

There are three points of failure:
1. a * b overflows
2. c * d overflows
3. (a * b) + (c * d) overflows


And if you need to give feedback to the user you have to check every 
single operation.
Sunanda
11-Feb-2008
[9062]
I'd suggest something like this:

-- calculations are done in a special function that is passed a string, 
eg
   ans: calc "(a * b) + (c + d)"
-- the 'calc DOes the string, protected by an 'attempt
-- if it succeeds, it passes back the result

-- if not, it throws an error report. If necessary, you can parse 
the original string and try each part of the calculation to find 
the first failure....Recursively via 'calc to drill down nested parentheses 
of course.

**

Two obvious drawbacks to this suggestion:

1. all variables need to be global -- unless you do a lot of other 
work

2. beware side effects of malformed calc strings. You would not like 
it to be "delete/any *.*"
Oldes
11-Feb-2008
[9063]
Maybe you can use an expression dialect to do the calculation.
Gregg
11-Feb-2008
[9064]
If you want to provide exact details, you're going to have to do 
some analysis and processing yourself.
Henrik
12-Feb-2008
[9065]
>> read http://store.apple.com

connecting to: store.apple.com
connecting to: store.apple.com

** User Error: Error.  Target url: http://store.apple.com/1-800-MY-APPLE/WebObjects/AppleStore
could not be retrieved.  Server response...
** Near: read http://store.apple.com

That's not a particularly useful error?
Sunanda
13-Feb-2008
[9066]
Nice thread contrasting LISP and REBOL:

http://coding.derkeiler.com/Archive/Lisp/comp.lang.lisp/2008-02/msg00756.html