1. prefixes and namespaces?

Ok, another question now about the standard library.

Currently, two files have been added that are prefixed.... map.e and datetime.e.
Functions are like:

include map.e
map m
m = map_new()
m = map_put(m, "name", "John Doe")
puts(1, "Name: " & map_get(m, "name"))

include datetime.e
datetime dt
dt = datetime_now()
dt = datetime_new(2008, 10, 20, 11, 12, 13)
dt = datetime_add_days(30)
-- ...etc...


All function names in these two items thus far: map_new(), map_get(), map_put(),
map_remove(), map_size(), map_keys(), map_values() and datetime_new(),
datetime_compare(), datetime_from_date(), datetime_now(), datetime_dow(),
datetime_to_unix(), datetime_from_unix(), datetime_add_seconds(),
datetime_add_days(), datetime_diff_seconds(), datetime_diff_days(). Global
constants: DT_YEAR, DT_MONTH, DT_DAY, DT_HOUR, DT_MINUTE, DT_SECOND.

Should we omit the map_ and datetime_ and do things like:

include datetime.e as dt

dt:now()
dt:add_days(30)
dt:from_unix(1029382)

map:put(m, "name", "John")
map:get(m, "name")


One concern I have is both map and datetime have the "new" function. Also,
datetime has datetime_compare, which would become compare(). That does not matter
if you do include with a namespace but...

Thoughts?

--
Jeremy Cowgar
http://jeremy.cowgar.com

new topic     » topic index » view message » categorize

2. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Ok, another question now about the standard library.
> 
> Currently, two files have been added that are prefixed.... map.e and
> datetime.e.

Jeremy:

     I have no idea what map.e is or what it is used for and

      who said it is an important library ?

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

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

3. Re: prefixes and namespaces?

Jeremy Cowgar wrote:

> One concern I have is both map and datetime have the "new" function. Also,
> datetime
> has datetime_compare, which would become compare(). That does not matter if
> you do include with a namespace but...
> 
> Thoughts?
> 

I vote for prefixes. I think the datetime_compare() example 
is great beacuse it shows how confusing it could be for a newbie.

I think somebody has already suggested to have "dt_" prefix instead 
of "datetime_" one. Please reconsider this idea...

Üdv: 

Salix

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

4. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Ok, another question now about the standard library.
> 
> Currently, two files have been added that are prefixed.... map.e and
> datetime.e.
> Functions are like:
> 
> }}}
<eucode>
> include map.e
> map m
> m = map_new()
> m = map_put(m, "name", "John Doe")
> puts(1, "Name: " & map_get(m, "name"))
> 
> include datetime.e
> datetime dt
> dt = datetime_now()
> dt = datetime_new(2008, 10, 20, 11, 12, 13)
> dt = datetime_add_days(30)
> -- ...etc...
> </eucode>
{{{

> 
> All function names in these two items thus far: map_new(), map_get(),
> map_put(),
> map_remove(), map_size(), map_keys(), map_values() and datetime_new(),
> datetime_compare(),
> datetime_from_date(), datetime_now(), datetime_dow(), datetime_to_unix(),
> datetime_from_unix(),
> datetime_add_seconds(), datetime_add_days(), datetime_diff_seconds(),
> datetime_diff_days().
> Global constants: DT_YEAR, DT_MONTH, DT_DAY, DT_HOUR, DT_MINUTE, DT_SECOND.
> 
> Should we omit the map_ and datetime_ and do things like:
> 
> }}}
<eucode>
> include datetime.e as dt
> 
> dt:now()
> dt:add_days(30)
> dt:from_unix(1029382)
> 
> map:put(m, "name", "John")
> map:get(m, "name")
> </eucode>
{{{

> 
> One concern I have is both map and datetime have the "new" function. Also,
> datetime
> has datetime_compare, which would become compare(). That does not matter if
> you do include with a namespace but...
> 
> Thoughts?
> 
> --
> Jeremy Cowgar
> <a href="http://jeremy.cowgar.com">http://jeremy.cowgar.com</a>

In my opinion it is not a good idea to prefix those functions.

Neither is good to have so many functions like ...add_days, ..add_minutes,
weeks, months and so on.

It would be enough to have an ADD function where you set the interval (year,
month, week, day...):
For example,
- add 30 days: ..._ADD(DAY, 30, mydate or mydatetime)
- add 1 week:  ..._ADD(WEEK, 1, mydate or mydatetime)

JG

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

5. Re: prefixes and namespaces?

Bernie Ryan wrote:
> 
> 
>      I have no idea what map.e is or what it is used for and
>       who said it is an important library ?

Bernie,

map is a dictionary. It's vital to many applications. If you doubt it's
usefulness, look at the archive at how many implementations there are and then
look at any other modern language and you will find map.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

6. Re: prefixes and namespaces?

Julio C. Galaret Viera wrote:
> 
> In my opinion it is not a good idea to prefix those functions.

Ok, noted as a vote no prefix.
 
> Neither is good to have so many functions like ...add_days, ..add_minutes,
> weeks,
> months and so on.
> 
> It would be enough to have an ADD function where you set the interval (year,
> month, week, day...):
> For example,
> - add 30 days: ..._ADD(DAY, 30, mydate or mydatetime)
> - add 1 week:  ..._ADD(WEEK, 1, mydate or mydatetime)

There are two methods for adding/subtracting. you saw them both add_seconds and
add_days. They can be used to subtract by doing add_days(-10....).

The reason there are those two is due to simplicity. Adding seconds allows you
to easily manipulate time. For instance, 3600*5 would add 5 hours. Adding days
allows you to easily manipulate a day.

As for adding weeks, months, etc... That gets very difficult because what is a
month, for instance? The average is 4.3 weeks, but that's an average. I think in
most programs you don't wind up adding in intervals of weeks, months, etc... It's
possible. But you could use, if you wish, add_days(7*4.3...) and add months,
weeks, or whatever you wanted.

So, we did try to make things as minimal as possible by adding just two
functions, add days and add seconds, as to work well with manipulating times and
dates.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

7. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Ok, another question now about the standard library.
> 
> Currently, two files have been added that are prefixed.... map.e and
> datetime.e.
> Functions are like:
> 
> }}}
<eucode>
> include map.e
> map m
> m = map_new()
> m = map_put(m, "name", "John Doe")
> puts(1, "Name: " & map_get(m, "name"))
> 
> include datetime.e
> datetime dt
> dt = datetime_now()
> dt = datetime_new(2008, 10, 20, 11, 12, 13)
> dt = datetime_add_days(30)
> -- ...etc...
> </eucode>
{{{

> 
> All function names in these two items thus far: map_new(), map_get(),
> map_put(),
> map_remove(), map_size(), map_keys(), map_values() and datetime_new(),
> datetime_compare(),
> datetime_from_date(), datetime_now(), datetime_dow(), datetime_to_unix(),
> datetime_from_unix(),
> datetime_add_seconds(), datetime_add_days(), datetime_diff_seconds(),
> datetime_diff_days().
> Global constants: DT_YEAR, DT_MONTH, DT_DAY, DT_HOUR, DT_MINUTE, DT_SECOND.
> 
> Should we omit the map_ and datetime_ and do things like:
> 
> }}}
<eucode>
> include datetime.e as dt
> 
> dt:now()
> dt:add_days(30)
> dt:from_unix(1029382)
> 
> map:put(m, "name", "John")
> map:get(m, "name")
> </eucode>
{{{

> 
> One concern I have is both map and datetime have the "new" function. Also,
> datetime
> has datetime_compare, which would become compare(). That does not matter if
> you do include with a namespace but...
> 
> Thoughts?
> 
> --
> Jeremy Cowgar
> <a href="http://jeremy.cowgar.com">http://jeremy.cowgar.com</a>

\Hello all,

as far as date and time I have written my own routines using the existing now.

I call it more_dates.e in the archives.

Such as getDayStr(),getDayDec().getStdTime(),getMilTime(), getESTime() etc...

I don't see why everybody can't do that for their own preferences. I see no need
to re write anything.


Don Cole

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

8. Re: prefixes and namespaces?

Salix wrote:
>  
> I vote for prefixes. I think the datetime_compare() example 
> is great beacuse it shows how confusing it could be for a newbie.

That's one big stumbling block to me about totally no prefix. I'd like to hear
an solution that addresses compare() directly.

> I think somebody has already suggested to have "dt_" prefix instead 
> of "datetime_" one. Please reconsider this idea...

Yes, that's in the back of my head.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

9. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Bernie Ryan wrote:
> > 
> > 
> >      I have no idea what map.e is or what it is used for and
> >       who said it is an important library ?
> 
> Bernie,
> 
> map is a dictionary. It's vital to many applications. If you doubt it's
> usefulness,
> look at the archive at how many implementations there are and then look at any
> other modern language and you will find map.
> 
> --

Jeremy:

   Where did map come from ?

   It is not in the archive.
   
   I don't see.

   Why aren't you using Associative Lists (Tables) by Jiri Babor

   who is a master at writing fast precise code.  



     	Associative Lists (Tables) 	17K	Jiri Babor




Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

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

10. Re: prefixes and namespaces?

Julio C. Galaret Viera wrote:
> 
> Jeremy Cowgar wrote:
> > 
> > Ok, another question now about the standard library.
> > 
> > Currently, two files have been added that are prefixed.... map.e and
> > datetime.e.
> > Functions are like:
> > 
> > }}}
<eucode>
> > include map.e
> > map m
> > m = map_new()
> > m = map_put(m, "name", "John Doe")
> > puts(1, "Name: " & map_get(m, "name"))
> > 
> > include datetime.e
> > datetime dt
> > dt = datetime_now()
> > dt = datetime_new(2008, 10, 20, 11, 12, 13)
> > dt = datetime_add_days(30)
> > -- ...etc...
> > </eucode>
{{{

> > 
> > All function names in these two items thus far: map_new(), map_get(),
> > map_put(),
> > map_remove(), map_size(), map_keys(), map_values() and datetime_new(),
> > datetime_compare(),
> > datetime_from_date(), datetime_now(), datetime_dow(), datetime_to_unix(),
> > datetime_from_unix(),
> > datetime_add_seconds(), datetime_add_days(), datetime_diff_seconds(),
> > datetime_diff_days().
> > Global constants: DT_YEAR, DT_MONTH, DT_DAY, DT_HOUR, DT_MINUTE, DT_SECOND.
> > 
> > Should we omit the map_ and datetime_ and do things like:
> > 
> > }}}
<eucode>
> > include datetime.e as dt
> > 
> > dt:now()
> > dt:add_days(30)
> > dt:from_unix(1029382)
> > 
> > map:put(m, "name", "John")
> > map:get(m, "name")
> > </eucode>
{{{

> > 
> > One concern I have is both map and datetime have the "new" function. Also,
> > datetime
> > has datetime_compare, which would become compare(). That does not matter if
> > you do include with a namespace but...
> > 
> > Thoughts?
> > 
> > --
> > Jeremy Cowgar
> > <a href="http://jeremy.cowgar.com">http://jeremy.cowgar.com</a>
> 
> In my opinion it is not a good idea to prefix those functions.
> 
> Neither is good to have so many functions like ...add_days, ..add_minutes,
> weeks,
> months and so on.
> 
> It would be enough to have an ADD function where you set the interval (year,
> month, week, day...):
> For example,
> - add 30 days: ..._ADD(DAY, 30, mydate or mydatetime)
> - add 1 week:  ..._ADD(WEEK, 1, mydate or mydatetime)

While I recognize the potential for this devolving into a religious war, I
concur.  Maybe we need a description for referencing legacy concepts.  BASIC-y
was used in a prior message.  The above is decidedly SPREADSHEET-y.

Numeric functions on spreadsheets are (nicely) overloaded, IMO.  

As far as a descriptor goes, I have always been partial to moment.  It is
shorter than datetime, yet communicates that "it" is something different from
either a date or a time.  It is also part of the vernacular, as one has probably
used the expression "precise moment in time" before.

It has the distinct disadvantage of never having been used in programming,
thereby making me think others have gone down this path and rejected its use. 
Probably because one of the definitions of moment is that it can be used to
reference a span of time rather than an instant (and hence the need for the
expression PRECISE moment).

Mike

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

11. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Bernie Ryan wrote:
> > 
> > 
> >      I have no idea what map.e is or what it is used for and
> >       who said it is an important library ?
> 
> Bernie,
> 
> map is a dictionary. It's vital to many applications. If you doubt it's
> usefulness,
> look at the archive at how many implementations there are and then look at any
> other modern language and you will find map.

What is the difference between a hash table and a map?

Mike

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

12. Re: prefixes and namespaces?

Bernie Ryan wrote:
> 
>    Where did map come from ?

yuku
 
>    It is not in the archive.
>    
>    I don't see.
> 
>    Why aren't you using Associative Lists (Tables) by Jiri Babor
>    who is a master at writing fast precise code.  

Because map is simpler, a cleaner interface and a little more than 3 times
faster.

tables:
include stables.e

integer n
sequence t
object v

n = 10000
t = ET

for i = 1 to n do
    t = insert(t, sprintf("key%d", {i}), sprintf("value%d", {i}))
end for

for i = 1 to n do
    v = fetch(t, sprintf("key%d", {i}))
    if equal(v, sprintf("value%d", {i})) = 0 then
        puts(1, "Invalid find\n")
        abort(1)
    end if
end for


map:
include map.e

integer n
object v
map m

n = 10000
m = map_new()

for i = 1 to n do
    m = map_put(m, sprintf("key%d", {i}), sprintf("value%d", {i}))
end for

for i = 1 to n do
    v = map_get(m, sprintf("key%d", {i}), 0)
    if equal(v, sprintf("value%d", {i})) = 0 then
        puts(1, "Invalid find\n")
        abort(1)
    end if
end for


Timing:

$ time exu benchmap.exu 

real    0m0.266s
user    0m0.267s
sys     0m0.000s

$ time exu benchother.exu 

real    0m0.886s
user    0m0.880s
sys     0m0.007s

I ran the above 2 commands 10 times each. All results were within 0.005s of
themselves. stable was the fastest of the three. tables took 2.203s to complete
the same test.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

13. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Julio C. Galaret Viera wrote:
> > 
> > In my opinion it is not a good idea to prefix those functions.
> 
> Ok, noted as a vote no prefix.
>  
> > Neither is good to have so many functions like ...add_days, ..add_minutes,
> > weeks,
> > months and so on.
> > 
> > It would be enough to have an ADD function where you set the interval (year,
> > month, week, day...):
> > For example,
> > - add 30 days: ..._ADD(DAY, 30, mydate or mydatetime)
> > - add 1 week:  ..._ADD(WEEK, 1, mydate or mydatetime)
> 
> There are two methods for adding/subtracting. you saw them both add_seconds
> and add_days. They can be used to subtract by doing add_days(-10....).
> 
> The reason there are those two is due to simplicity. Adding seconds allows you
> to easily manipulate time. For instance, 3600*5 would add 5 hours. Adding days
> allows you to easily manipulate a day.
> 
> As for adding weeks, months, etc... That gets very difficult because what is
> a month, for instance? The average is 4.3 weeks, but that's an average. I
> think
> in most programs you don't wind up adding in intervals of weeks, months,
> etc...
> It's possible. But you could use, if you wish, add_days(7*4.3...) and add
> months,
> weeks, or whatever you wanted.
> 
> So, we did try to make things as minimal as possible by adding just two
> functions,
> add days and add seconds, as to work well with manipulating times and dates.

On this subject I can speak.  I work with addition and determination of dates
and ages frequently.  And it is all a crapshoot.  If you have access to Excel,
take a look at the types of dates they perceive can underly these determinations.
 Bankers rules are commonly used.  Completed periods are sometimes used. 
Rounding is sometimes used.  Rounding itself can be based on the interval in
question or a theoretical one.  That is, for some purposes, months are considered
to always have 30 days (daily compounding of interest between a certain number of
months, leading to the rule of 360).

In other words, I concur that having an add_months function is quite involved
(although certainly not impossible) and would require at least one additional
parameter to deal with the inconsistencies created by the months of our calendar
having different numbers of days.

Mike

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

14. Re: prefixes and namespaces?

Mike777 wrote:
> 
> What is the difference between a hash table and a map?
> 

Technically, a hash table would store a key/value pair using a hashing
technique. There are other methods of doing it. A map is a generic term for
key/value type structures. It may use one of many methods for the key/value
relation. Our map, however, uses a hash and it could have been called a hash
table, but map is a bit simpler of a name. dictionary is simpler yet, but not
always correct in that when you think of a dictionary you think of a word and
description. Our map can use strings as keys, complex sequences, integers, atoms,
etc...

Practically? no difference. Both are key/value type devices.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

15. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Mike777 wrote:
> > 
> > What is the difference between a hash table and a map?
> > 
> Practically? no difference. Both are key/value type devices.

Well, when I did my search on what to use, I came up with Hash Tables
(htables.zip) from jiri babor.  It is a year and a third newer than his
Associative Lists, referenced a few messages ago.

It has certainly worked for me.

Mike

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

16. Re: prefixes and namespaces?

Mike777 wrote:
> 
> Well, when I did my search on what to use, I came up with Hash Tables
> (htables.zip)
> from jiri babor.  It is a year and a third newer than his Associative Lists,
> referenced a few messages ago.
> 
> It has certainly worked for me.
> 

Yes, it works indeed. I've used it many times. The benchmark I listed previously
was for stable (also by him), part of 3tables.zip. stable from 3table.zip
benchmarks almost 2x as htable from htable.zip . The three benchmark results are:

== htable:

real    0m1.342s
user    0m1.340s
sys     0m0.000s

== stable:

real    0m0.885s
user    0m0.880s
sys     0m0.007s

== map in Euphoria 4.0 (SVN trunk)

real    0m0.266s
user    0m0.267s
sys     0m0.000s

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

17. Re: prefixes and namespaces?

I vote for prefix,

jacques d.

Jeremy Cowgar wrote:
> 
> Ok, another question now about the standard library.
> 
> Currently, two files have been added that are prefixed.... map.e and
> datetime.e.
> Functions are like:
> 
> }}}
<eucode>
> include map.e
> map m
> m = map_new()
> m = map_put(m, "name", "John Doe")
> puts(1, "Name: " & map_get(m, "name"))
> 
> include datetime.e
> datetime dt
> dt = datetime_now()
> dt = datetime_new(2008, 10, 20, 11, 12, 13)
> dt = datetime_add_days(30)
> -- ...etc...
> </eucode>
{{{

> 
> All function names in these two items thus far: map_new(), map_get(),
> map_put(),
> map_remove(), map_size(), map_keys(), map_values() and datetime_new(),
> datetime_compare(),
> datetime_from_date(), datetime_now(), datetime_dow(), datetime_to_unix(),
> datetime_from_unix(),
> datetime_add_seconds(), datetime_add_days(), datetime_diff_seconds(),
> datetime_diff_days().
> Global constants: DT_YEAR, DT_MONTH, DT_DAY, DT_HOUR, DT_MINUTE, DT_SECOND.
> 
> Should we omit the map_ and datetime_ and do things like:
> 
> }}}
<eucode>
> include datetime.e as dt
> 
> dt:now()
> dt:add_days(30)
> dt:from_unix(1029382)
> 
> map:put(m, "name", "John")
> map:get(m, "name")
> </eucode>
{{{

> 
> One concern I have is both map and datetime have the "new" function. Also,
> datetime
> has datetime_compare, which would become compare(). That does not matter if
> you do include with a namespace but...
> 
> Thoughts?
> 
> --
> Jeremy Cowgar
> <a href="http://jeremy.cowgar.com">http://jeremy.cowgar.com</a>

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

18. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Mike777 wrote:
> > 
> > Well, when I did my search on what to use, I came up with Hash Tables
> > (htables.zip)
> > from jiri babor.  It is a year and a third newer than his Associative Lists,
> > referenced a few messages ago.
> > 
> > It has certainly worked for me.
> > 
> 
> Yes, it works indeed. I've used it many times. The benchmark I listed
> previously
> was for stable (also by him), part of 3tables.zip. stable from 3table.zip
> benchmarks
> almost 2x as htable from htable.zip . The three benchmark results are:
> 
> == htable:
> 
> real    0m1.342s
> user    0m1.340s
> sys     0m0.000s
> 
> == stable:
> 
> real    0m0.885s
> user    0m0.880s
> sys     0m0.007s
> 
> == map in Euphoria 4.0 (SVN trunk)
> 
> real    0m0.266s
> user    0m0.267s
> sys     0m0.000s

Ouch.  If I understand the above, the time for your benchmark to run was more
than 5 times slower using htable than map?  I smell some refactoring....

Mike

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

19. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Bernie Ryan wrote:
> > 
> >    Where did map come from ?
> 
> yuku

I think you got your ku's mixed up.  Aku.

Mike

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

20. Re: prefixes and namespaces?

Mike777 wrote:
> 
> > == htable:
> > 
> > real    0m1.342s
> > user    0m1.340s
> > sys     0m0.000s
> > 
> > == stable:
> > 
> > real    0m0.885s
> > user    0m0.880s
> > sys     0m0.007s
> > 
> > == map in Euphoria 4.0 (SVN trunk)
> > 
> > real    0m0.266s
> > user    0m0.267s
> > sys     0m0.000s
> 
> Ouch.  If I understand the above, the time for your benchmark to run was more
> than 5 times slower using htable than map?  I smell some refactoring....

No. htable took 1.342s, stable took 0.885s and map (in SVN Euphoria (4.0)) took
0.266s. What is in Euphoria now is the fastest. 5 times faster than htable.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

21. Re: prefixes and namespaces?

Mike777 wrote:
> 
> Jeremy Cowgar wrote:
> > 
> > Bernie Ryan wrote:
> > > 
> > >    Where did map come from ?
> > 
> > yuku
> 
> I think you got your ku's mixed up.  Aku.

I think they are the same person. You'll see posts here where he signs Aku and
also yuku. I guess he's better known as Aku.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

22. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Mike777 wrote:
> > 
> > > == htable:
> > > 
> > > real    0m1.342s
> > > user    0m1.340s
> > > sys     0m0.000s
> > > 
> > > == stable:
> > > 
> > > real    0m0.885s
> > > user    0m0.880s
> > > sys     0m0.007s
> > > 
> > > == map in Euphoria 4.0 (SVN trunk)
> > > 
> > > real    0m0.266s
> > > user    0m0.267s
> > > sys     0m0.000s
> > 
> > Ouch.  If I understand the above, the time for your benchmark to run was
> > more
> > than 5 times slower using htable than map?  I smell some refactoring....
> 
> No. htable took 1.342s, stable took 0.885s and map (in SVN Euphoria (4.0))
> took
> 0.266s. What is in Euphoria now is the fastest. 5 times faster than htable.

How do I get access to that?  BTW, I think we were agreeing.

Mike

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

23. Re: prefixes and namespaces?

Mike777 wrote:
> 
> How do I get access to that?  BTW, I think we were agreeing.
> 

Oh! I read your message wrong. I thought you were saying map in euphoria was 5
times slower. Re-read, my bad. Your saying my benchmark showed htable 5 times
slower than map, not map 5 times slower. Ok.

How do you get map or how do you get the benchmark?

The benchmark code for map is located in the message:

http://www.openeuphoria.org/EUforum/m19908.html

The benchmark for stable (faster than htable) can be found in that same message.
The benchmark for htable, as found in htable.zip, is slightly different than the
one for stable. It is:

include htables.e

integer n
sequence t
object v

n = 10000
t = new(1)

for i = 1 to n do
    t = make(t, sprintf("key%d", {i}), sprintf("value%d", {i}))
end for

for i = 1 to n do
    v = fetch(t, sprintf("key%d", {i}))
    if equal(v, sprintf("value%d", {i})) = 0 then
        puts(1, "Invalid find\n")
        abort(1)
    end if
end for


To get the new Euphoria, you need to use svn:

svn co http://rapideuphoria.svn.sourceforge.net/svnroot/rapideuphoria/trunk
euphoria-4.0

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

24. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> I think they are the same person. You'll see posts here where he signs Aku and
> also yuku. I guess he's better known as Aku.


Yes, it's the same :D

I was trying to post from my mobile but I don't know the password for Aku
(It was stored in my Opera browser on desktop).
So I just created a new account to post messages here.

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

25. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Should we omit the map_ and datetime_ and do things like:
> 
> }}}
<eucode>
> include datetime.e as dt
> 
> dt:now()
> dt:add_days(30)
> dt:from_unix(1029382)
> 
> map:put(m, "name", "John")
> map:get(m, "name")
> </eucode>
{{{


I think so.

> One concern I have is both map and datetime have the "new" function. Also,
> datetime
> has datetime_compare, which would become compare(). That does not matter if
> you do include with a namespace but...

Can someone please justify datetime_compare()?  It just seems to add 
overhead to what could be accomplished with the built-in compare().  We
definitely need to be careful when overriding a built-in.

Matt

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

26. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Julio C. Galaret Viera wrote:
> > 
> > It would be enough to have an ADD function where you set the interval
> > (year, month, week, day...):
> > For example,
> > - add 30 days: ..._ADD(DAY, 30, mydate or mydatetime)
> > - add 1 week:  ..._ADD(WEEK, 1, mydate or mydatetime)

<snip>
 
> As for adding weeks, months, etc... That gets very difficult because what is
> a month, for instance? The average is 4.3 weeks, but that's an average. I
> think
> in most programs you don't wind up adding in intervals of weeks, months,
> etc...
> It's possible. But you could use, if you wish, add_days(7*4.3...) and add
> months,
> weeks, or whatever you wanted.
> 
> So, we did try to make things as minimal as possible by adding just two
> functions,
> add days and add seconds, as to work well with manipulating times and dates.

I agree with Julio.  A single add would be better.  It should be documented
that only fixed units are allowed (YEAR, DAY, WEEK, HOUR, MINUTE, SECOND).

Matt

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

27. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> Salix wrote:
> >  
> > I vote for prefixes. I think the datetime_compare() example 
> > is great beacuse it shows how confusing it could be for a newbie.
> 
> That's one big stumbling block to me about totally no prefix. I'd like to hear
> an solution that addresses compare() directly.

Since the format of a datetime is:
  {year, month, date, hour, minute, second}
...it already works with the built-in compare, so datetime_compare() is
redundant.  If it didn't, an alternative solution would be to either
make it so, or to call it something other than compare.  Better to change
one exception than an encumber an entire library.

Matt

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

28. Re: prefixes and namespaces?

Matt Lewis wrote:
> 
> Jeremy Cowgar wrote:
> > 
> > Salix wrote:
> > >  
> > > I vote for prefixes. I think the datetime_compare() example 
> > > is great beacuse it shows how confusing it could be for a newbie.
> > 
> > That's one big stumbling block to me about totally no prefix. I'd like to
> > hear
> > an solution that addresses compare() directly.
> 
> Since the format of a datetime is:
>   {year, month, date, hour, minute, second}
> ...it already works with the built-in compare, so datetime_compare() is
> redundant.  If it didn't, an alternative solution would be to either
> make it so, or to call it something other than compare.  Better to change
> one exception than an encumber an entire library.

It is because the current implementation use that data structure. (I simplified
it from the {{d,m,y},{h,n,s}} used by original datetime.e). But can we be  sure
that it is fixed like that?

One pitfall for users: they won't be able to use built-in date() as argument to
compare().

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

29. Re: prefixes and namespaces?

yuku wrote:
> 
> It is because the current implementation use that data structure. (I
> simplified
> it from the {{d,m,y},{h,n,s}} used by original datetime.e). But can we be 
> sure
> that it is fixed like that? 

I think Matt is right.
 
> One pitfall for users: they won't be able to use built-in date() as argument
> to compare().

I'm not so sure that matters much because we have the datetime type. Users
should only be comparing 2 datetime types.

I'm in favor of dropping the datetime_compare function.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

30. Re: prefixes and namespaces?

Matt Lewis wrote:
> 
> I agree with Julio.  A single add would be better.  It should be documented
> that only fixed units are allowed (YEAR, DAY, WEEK, HOUR, MINUTE, SECOND).
> 

I have no strong opinion one way or the other. Each is very easy. However, since
multiple people think 1 add function is better, I've changed it. I have not yet
committed as I am doing testing and going to document all of this now that we
settled prefix/no prefix, and the add issue. Here's the way it works now in my
copy and soon SVN:

dt = d:add(dt, 3 * HOURS)
dt = d:add(dt, 3 * WEEKS)
dt = d:add(dt, 7 * DAYS)
dt = d:subtract(dt, 30 * DAYS)
dt = d:subtract(dt, 12.5 * HOURS)


Note, I did not add YEARS as it is not a fixed unit. To do that correctly we
would need to add a function add_years, which accounts for leap year.

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

31. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> }}}
<eucode>
> dt = d:add(dt, 3 * HOURS)
> dt = d:add(dt, 3 * WEEKS)
> dt = d:add(dt, 7 * DAYS)
> dt = d:subtract(dt, 30 * DAYS)
> dt = d:subtract(dt, 12.5 * HOURS)
> </eucode>
{{{

> 
> Note, I did not add YEARS as it is not a fixed unit. To do that correctly we
> would need to add a function add_years, which accounts for leap year.


I don't think that using multiplication like this is a good solution. 
We will not be able to add MONTHS and YEARS. Why do we omit months and years
if we can write HOURS MINUTES DAYS and WEEKS ?

Year and Month addition is more tricky, I will take examples from mysql.

+-----------------------------------------+
| date_add('2008-4-25', interval 1 month) |
+-----------------------------------------+
| 2008-05-25                              |
+-----------------------------------------+

+-----------------------------------------+
| date_add('2008-5-25', interval 1 month) |
+-----------------------------------------+
| 2008-06-25                              |
+-----------------------------------------+
So "1 month" is not translated to 30 or 31 days but it directly 
modifies based on the original date.


+-----------------------------------------+
| date_add('2008-5-31', interval 1 month) |
+-----------------------------------------+
| 2008-06-30                              |
+-----------------------------------------+
If the result is an invalid date, it is adjusted.

+----------------------------------------+
| date_add('2008-2-29', interval 1 year) |
+----------------------------------------+
| 2009-02-28                             |
+----------------------------------------+
The same goes for year.

+-----------------------------------------+
| date_add('2008-2-29', interval -1 year) |
+-----------------------------------------+
| 2007-02-28                              |
+-----------------------------------------+
Subtraction has the same result.

+-----------------------------------------+
| date_add('2008-2-29',interval 1.5 hour) |
+-----------------------------------------+
| 2008-02-29 02:00:00                     |
+-----------------------------------------+
No fractions allowed. Really important! Because how can we define 0.5 months or
0.5 years etc. Will be very messy.

...

So in order to accomodate year and month add/sub, why don't we make it

dt = d:add(dt, 3, HOURS)
dt = d:add(dt, 3, WEEKS)
dt = d:add(dt, 7, DAYS)
dt = d:add(dt, -30, MONTHS)
dt = d:add(dt, -12, YEARS)


1. I think subtract is not necessary, just use minus.

2. No fractions allowed except for SECONDS.

If fractions were allowed, d:add(dt, 1/6, HOURS) may not be 
equal to d:add(dt, 10, MINUTES) because of the floating point error.

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

32. Re: prefixes and namespaces?

yuku wrote:
> 
> 
> So in order to accomodate year and month add/sub, why don't we make it
> 
> dt = d:add(dt, 3, HOURS)
> dt = d:add(dt, 3, WEEKS)
> dt = d:add(dt, 7, DAYS)
> dt = d:add(dt, -30, MONTHS)
> dt = d:add(dt, -12, YEARS)

I agree with this format.

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

33. Re: prefixes and namespaces?

yuku wrote:
> 
> So in order to accomodate year and month add/sub, why don't we make it
> 
> }}}
<eucode>
> dt = d:add(dt, 3, HOURS)
> dt = d:add(dt, 3, WEEKS)
> dt = d:add(dt, 7, DAYS)
> dt = d:add(dt, -30, MONTHS)
> dt = d:add(dt, -12, YEARS)
> </eucode>
{{{

> 
> 1. I think subtract is not necessary, just use minus.

I think a minus function is cake to implement and makes coding a bit more
readable... for instance:

integer days
puts(1, "Enter how many days ago you got paid: ")
days = get_integer_from_user()

dt = d:add(dt, -(days), DAYS)

--
-- vs...
--

integer days
puts(1, "Enter how many days ago you got paid: ")
days = get_integer_from_user()

dt = d:subtract(dt, days, DAYS)


Sure it's easy to write -(days), but it does not read naturally, and the sub
function nearly be:

global function subtract(datetime d, atom qty, integer interval)
    return add(dt, -(qty), interval)
end function


So, why not?

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

34. Re: prefixes and namespaces?

c.k.lester wrote:
> 
> yuku wrote:
> > 
> > 
> > So in order to accomodate year and month add/sub, why don't we make it
> > 
> > dt = d:add(dt, 3, HOURS)
> > dt = d:add(dt, 3, WEEKS)
> > dt = d:add(dt, 7, DAYS)
> > dt = d:add(dt, -30, MONTHS)
> > dt = d:add(dt, -12, YEARS)
> 
> I agree with this format.

Ok, changing again smile

--
Jeremy Cowgar
http://jeremy.cowgar.com

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

35. Re: prefixes and namespaces?

Jeremy Cowgar wrote:
> 
> yuku wrote:
> > 
> > }}}
<eucode>
> > dt = d:add(dt, 3, HOURS)
> > </eucode>
{{{

> > 
> > 1. I think subtract is not necessary, just use minus.
> 
> I think a minus function is cake to implement and makes coding a bit more
> readable...
> for instance:

I prefer to use (and read) just the add() function, but if others think
subtract is clearer...

Matt

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

Search



Quick Links

User menu

Not signed in.

Misc Menu