1. routine_id mishaps

Hello all,

This is strange code (below) because routine_id assigns "my_proc" & "my_func"
the same value...Can someone (Rob C maybe!) give me a reason why?

<snip>
with trace
trace(1)

constant
    TRUE = 1,
    FALSE = 0

sequence
    types,
    handles,
    rps

handles = {}
rps = {}
types = {}

global procedure add_routine (object handle, integer rp)
integer pos
    pos = find (handle, handles)
    if pos then
        types[pos] = TRUE         -- It does return something
        rps[pos] = rp
    else
        handles = append(handles, handle)
        types = append(types, TRUE)
        rps = append(rps, TRUE)
    end if
end procedure

global function call_routine (object handle, sequence arg)
integer pos
    pos = find (handle, handles)
    if pos then
        if types[pos] then
            return {TRUE, call_func (rps[pos], arg)} --function call
        else
            call_proc (rps[pos], arg) -- procedure call
            return {TRUE}
        end if
    else
        return {FALSE}
    end if
end function

procedure my_proc (integer a, integer b)
    puts (1, {a,b})
end procedure
add_routine ("my_proc", routine_id ("my_proc"))

function my_func (integer a, integer b)
    return "Hello!"
end function
add_routine ("my_func", routine_id ("my_func"))

sequence result

result = call_routine ("my_proc", {'a','b'})
-- result is now {TRUE}

result = call_routine ("my_func", {'a','b'})
-- result is now {TRUE, "Hello!"}

<snip>

new topic     » topic index » view message » categorize

2. Re: routine_id mishaps

>From: xanax at bellsouth.net
>Subject: routine_id mishaps
>
>
>Hello all,
>
>This is strange code (below) because routine_id assigns "my_proc" & 
>"my_func"
>the same value...Can someone (Rob C maybe!) give me a reason why?
>
><snip>
>with trace
>trace(1)
>
>constant
>     TRUE = 1,
>     FALSE = 0
>
>sequence
>     types,
>     handles,
>     rps
>
>handles = {}
>rps = {}
>types = {}
>
>global procedure add_routine (object handle, integer rp)
>integer pos
>     pos = find (handle, handles)
>     if pos then
>         types[pos] = TRUE         -- It does return something
>         rps[pos] = rp
>     else
>         handles = append(handles, handle)
>         types = append(types, TRUE)
>         rps = append(rps, TRUE)

I think this is wrong. It should be:
          rps = append(rps, rp)

>     end if
>end procedure
>
>global function call_routine (object handle, sequence arg)
>integer pos
>     pos = find (handle, handles)
>     if pos then
>         if types[pos] then
>             return {TRUE, call_func (rps[pos], arg)} --function call
>         else
>             call_proc (rps[pos], arg) -- procedure call
>             return {TRUE}
>         end if
>     else
>         return {FALSE}
>     end if
>end function
>
>procedure my_proc (integer a, integer b)
>     puts (1, {a,b})
>end procedure
>add_routine ("my_proc", routine_id ("my_proc"))
>
>function my_func (integer a, integer b)
>     return "Hello!"
>end function
>add_routine ("my_func", routine_id ("my_func"))
>
>sequence result
>
>result = call_routine ("my_proc", {'a','b'})
>-- result is now {TRUE}
>
>result = call_routine ("my_func", {'a','b'})
>-- result is now {TRUE, "Hello!"}
>
><snip>
>


Euphoria Instant Messenger
Have YOU Joined?
http://groups.yahoo.com/group/euim/

new topic     » goto parent     » topic index » view message » categorize

3. Re: routine_id mishaps

OK folks,

Here is the ammended code! good luck

with trace
trace(1)

constant
    TRUE = 1,
    FALSE = 0

sequence
    types,
    handles,
    rps

    handles = {}
    rps = {}
    types = {}
    
integer proc, 
        func
        
        proc = 0
        func = 1


global procedure add_routine (integer pf, object handle, integer rp)
integer pos
    pos = find (handle, handles)
    if pos then
        types[pos] = pf   
        rps[pos] = rp
    else
        handles = append(handles, handle)
        types = append(types, pf)
        rps = append(rps, rp)
    end if
end procedure

global function call_routine (object handle, sequence arg)
integer pos
    pos = find (handle, handles)
    if pos then
        if types[pos] then
            return {TRUE, call_func (rps[pos], arg)}
        else
            call_proc (rps[pos], arg)
            return {TRUE}
        end if
    else
        return {FALSE}
    end if
end function

procedure my_proc (integer a, integer b)
    puts (1, {a,b})
end procedure
add_routine (proc,"my_proc", routine_id ("my_proc"))

function my_func (integer a, integer b)
    return "HellO!"
end function
add_routine (func, "my_func", routine_id ("my_func"))

sequence result

result = call_routine ("my_proc", {'a','b'})
-- result is now {TRUE}

result = call_routine ("my_func", {'a','b'})
-- result is now {TRUE, "HellO!"}

result = call_routine ("my_house", {'a','b'})

new topic     » goto parent     » topic index » view message » categorize

4. Re: routine_id mishaps

On Sat, 14 Dec 2002 15:37:46 -0500, xanax at bellsouth.net wrote:

>Here is the ammended code! good luck

What did you expect it to do?
Shouldn't add_routine be flagging an error if passed an already
existing handle?
If you used proc=3D'P', func=3D'F', and replace TRUE and FALSE with say
"OK" and "NotOK", it might make it easier to debug.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu