Re: SWITCH question

new topic     » goto parent     » topic index » view thread      » older message » newer message
irv said...

...

Hopefully, someone can explain that.

I typed up your examples to "cut-and-paste" form so others can test them.


A OE built-in function: FAIL.

constant op = cos(0) 
? op 
	-->1 
 
    switch 1  do  
        case op then  
            puts(1, "\n result is first stack \n" )  
        case else  
            puts(1, "\n result is something else \n")  
    end switch  
  
--> FAIL 

A home-brew function: SUCCESS

function foo( atom x ) 
	return x+1 
end function 
 
constant op = foo(0) 
? op 
	-->1 
 
    switch 1  do  
        case op then  
            puts(1, "\n result is first stack \n" )  
        case else  
            puts(1, "\n result is something else \n")  
    end switch  
  
--> success 

An attempt to sanitize the return from an include file: FAIL

include std/stack.e 
 
function OP( ) 
	object x = stack:new(FIFO) 
	 
	return x 
 
    /*  -- this version works 

	if x=1 then return 1 end if 
	*/ 
	 
end function 
 
? OP() 
 
constant op = OP() 
? op 
	-->1 
 
 
    switch 1  do  
        case op then  
            puts(1, "\n result is first stack \n" )  
        case else  
            puts(1, "\n result is something else \n")  
    end switch  
  
--> FAIL 

Testing idea that it's a scope or namespace problem.

Home-made include file: success.

-- mylib.e 
 
export function foo( atom x ) 
	return x+1 
end function 
include mylib.e 
 
constant op = foo(0) 
? op 
	-->1 
 
    switch 1  do  
        case op then  
            puts(1, "\n result is first stack \n" )  
        case else  
            puts(1, "\n result is something else \n")  
    end switch  
  
--> success 

OE functions, built-in and std/lib, are possessed.

_tom

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

Search



Quick Links

User menu

Not signed in.

Misc Menu