Re: RFD: Suggested Enhancement: Namespace

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

I've just read JeffZ's message, and I think I can sum it up in one word:
Overloading. The ability to declare functions with the same name, but with
different parameters, and the ablility, should the parameters be the same,
to discern which .e file they came from.

I know this is possible by passing variable length sequences (that are
possibly type defined before the procedure), but it's not
half as user friendly as being able to do this.

e.g. snippets from non-existent BASICish.e, seqmisc.e and mainprog.ex:
-- MID$ like function(s) in BASICish.e
global function midseq(sequence seq, integer start, integer places)
    return seq[start..start+places-1]
end function

global function midseq(sequence seq, integer start) -- Overloading!
    return seq[start..length(seq)]
end function
-- End BASICish.e

-- Middle string function in seqmisc.e
global function midseq(sequence seq, integer numofchars)
    -- Same parameter types. Oo-er! :)
    integer temp
    temp = floor((length(seq)-numofchars)/2)

    return seq[temp+1..temp+numofchars-1]
end function
-- End seqmisc.e

-- Start mainprog.ex
include BASICish.e
include seqmisc.e

puts(1, midseq("goldfish",3,4)) -- = "ldfi"
  -- It's obvious which one this is because it's of type func(seq,int,int)
puts(1, midseq("goldfish",5))   -- causes an error. Which midseq(seq,int)?
puts(1, BASICish.e.midseq("goldfish",5)) -- = "fish"
  -- Note that the whole of the name of BASICish.e has to be included
  -- because you can call euphoria libraries what you like! ".e" is just a
  -- standard imposed by RDS that most of us faithfully follow.
puts(1, seqmisc.e.midseq("goldfish",5)) -- = "oldfi"
-- End mainprog.ex

Just my 2 pence worth (3 1/3 cents) :)
Carl

--
Carl R White - "FBIbait: The President will be castrated in his sleep."
E-mail...: cyrek- at -bigfoot.com              / Remove the hyphens before
Finger...: crwhite- at -dcsun1.comp.brad.ac.uk \ mailing or fingering...
Url......: http://www.bigfoot.com/~cyrek/

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

Search



Quick Links

User menu

Not signed in.

Misc Menu