[OE] Suggestion for OpenEuphoria 'Next' | Module

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

Forked from Alternative: Module -- Re: fake class in OE

Draft for OpenEuphoria += Next

An alternative to "class ..."

An explicit defined module must be instanciated to be accessible.
Not like a file with/without a namespace.


For short

  1. a module is like a namespace and like a routine
    1. but module must be instanciated
    2. and needs a procedure "new"
    3. "Module#routine(..)" and "Module#var" if it's export/public or have a "get_var" or "set_var" (both or one of them)
  2. only anything above "module" will be usable if only namespace is used


namespace module_animal -- still optional 
 
-- "export module" is equal to "export function/procedure" 
export module Animal is Class  -- or as above, but I think, that's better then Animal : Class (it seems like a namespace) 
-- a module does NOT inheritance from Class automaticly! 
-- Class is more like a struct/type 
 
-- anything like above 

Use as above ...
but include loads ONLY anything above module definition

-- "public module" is equal to "public function/procedure" 
public module Cow is Animal 
use mymods/Animal.em -- .em Euphoria Module -- a Module could be self executable but I think it must not. 
-- 'use' could be before 'module'  
-- [...] 


The Horns Example (simple)

namespace module_cow 
 
public module Cow is Animal 
use mymods/Animal.em 
 
integer horns 
sequence name 
 
-- procedure new() is required for any module! 
export procedure new(sequence name, integer horns = 2) 
  #name = name 
  #horns = horns 
export procedure 
 
export procedure rename(sequence name) 
  #name = name 
end procedure 
 
export function get_horns() 
  return horns 
end function 
 
export procedure set_horns(integer amount) 
  horns = amount 
end procedure 
use mymods/Cow.em 
 
my_cow = Cow() 
? my_cow#name  -- "Luisa" 
? my_cow#horns -- 2 
 
your_cow = Cow("Priceless", 3) 
? your_cow#name  -- "Priceless" 
? your_cow#horns -- 3 
 
your_cow#horns = 0 
your_cow#rename("Princess") 
? your_cow#horns -- 0 
? your:cow#name  -- "Princess" 
my_cow = Cow() 
your_cow = Cow() 
? equal(my_cow, your_cow) -- 0 
new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu