routine_id mishaps

new topic     » topic index » view thread      » older message » newer message

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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu