Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Experiment - Date literals and data type

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> ViviFire language
View previous topic :: View next topic  
Author Message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jul 23rd, 2014, 12:43am    Post subject: Experiment - Date literals and data type Reply with quote

I recently had the thought that VF could use a date literal and (maybe) a Date type. A date literal would add consistency by allowing the compiler to check for correctness instead of relying on opaque string literals, as LB does.

Visual Basic also has a date literal, but I'm sure that many people find it odd because it insists on using the US-centric mm/dd/yyyy format for dates and assumes a 12-hour time format. For example, the current date and time here is #7/22/2014 8:43 PM#.

The format I propose for VF would be a bit more internationalized. The same value from above would be represented as @2014-7-22:20:43:00.

The date parts could also be separated by slashes (@2014/7/22) or dots (@2014.7.22). The time part can be left off a date and defaults to 00:00:00.0. Or the literal can leave the date part off and just represent a time value; the date part defaulting to 0001-01-01 (or whatever is appropriate).

A Date type would almost certainly be represented with a 64-bit integer, given the looming Y2038 problem. But then I have to consider how much resolution to have in the time. VB's Date type uses 64 bits with a 100 nanosecond resolution and a range between #1/1/0001# and #12/31/9999#. I suppose that would be alright.

Do you have any comments or questions?

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
STPendl
Full Member


Joined: 20 Aug 2007
Posts: 161
Location: Austria

PostPosted: Jul 26th, 2014, 8:26am    Post subject: Re: Experiment - Date literals and data type Reply with quote

I like the approach of using the sortable date format, which makes it much easier to understand the parts of it.

How about using a semicolon to separate the date from the time?
This would make it easier to parse the string and split it up into date and time.

In general time resolution of milliseconds should be sufficient, so 100 nanoseconds would be enough.

_________________
Stefan

Any code I post can be freely used, just give credit.
Back to top
View user's profile Send private message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jul 26th, 2014, 10:29pm    Post subject: Re: Experiment - Date literals and data type Reply with quote

STPendl wrote:
How about using a semicolon to separate the date from the time?
This would make it easier to parse the string and split it up into date and time.

I'm not sure about people's ability to distinguish a semicolon from a colon in unspaced text. I'd guess that many people would see colons instead, and get syntax errors.

My reason for using a colon is because the Apache Web server's logs use a date/time format like 26/Jul/2014:12:34:56. Of course that isn't exactly the same format as I suggested and might confuse people as well.

I wonder how you all think about a format like
@2014-07-26@12:34:56
?

It sounds pretty natural if you read it out loud in English IMO.

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Jul 26th, 2014, 11:12pm    Post subject: Re: Experiment - Date literals and data type Reply with quote

Here's an example that uses a couple Dates in a struct.
Code:
Struct person
   name As String
   birth As Date
   death As Date
End Struct
Dim US_presidents() As person = { _
   { "George Washington", @1732-02-22, @1799-12-14 }, _
   { "Abraham Lincoln", @1809-02-12, @1865-04-15 }, _
   { "Theodore Roosevelt", @1858-10-27, @1919-01-06 } _
}

Dim randDate As Date = RandomDate()
For Each prez In US_presidents()
   If prez.birth <= randDate <= prez.death Tol @12:00:00
      #out "President " & prez.name & " was alive in " & randDate & "."
   End If
End For
End

Note that when a Date is converted into a string, it is automatically formatted for the user's locale.

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
STPendl
Full Member


Joined: 20 Aug 2007
Posts: 161
Location: Austria

PostPosted: Aug 2nd, 2014, 8:55am    Post subject: Re: Experiment - Date literals and data type Reply with quote

Just tried to run the example, but failed to get it run correctly with the latest VF.exe
May be the debug output could contain the version number of the VF.exe to make sure the latest version is used for testing.

Code:

require IO #out
Struct person
   name As String
   birth As Date
   death As Date
End Struct
Dim US_presidents() As person = { _
   { "George Washington", @1732-02-22, @1799-12-14 }, _
   { "Abraham Lincoln", @1809-02-12, @1865-04-15 }, _
   { "Theodore Roosevelt", @1858-10-27, @1919-01-06 } _
}

Dim randDate As Date = RandomDate()
For Each prez In US_presidents()
   If prez.birth <= randDate <= prez.death Tol @12:00:00
      #out "President " & prez.name & " was alive in " & randDate & "."
   End If
End For
End


Quote:

C:\Users\Stefan\Documents\Prog\ViviFire>VF.exe -v2 "Date Sample.txt"

138:require
24:IO
26:#out
1:?-- line 3 col 1: invalid UserModule

141:Struct
24:person
1:?
24:name
89:As
122:String
1:?
24:birth
89:As
132:Date
1:?
24:death
89:As
132:Date
1:?
48:End Struct
1:?-- line 8 col 1: EOF expected

-- 2 errors


It seems that struct is not a recognized keyword.

_________________
Stefan

Any code I post can be freely used, just give credit.
Back to top
View user's profile Send private message
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 797

PostPosted: Aug 2nd, 2014, 4:37pm    Post subject: Re: Experiment - Date literals and data type Reply with quote

Hi Stefan,

The root of the problem is that the code I posted is unlabeled pseudocode.

So far, STRUCTs (and several other declarations) are legal only within LIBRARY modules. However, after giving it some thought, I can see that this was a rather arbritrary decision on my part. Most people would be annoyed to have to create a new source file just to declare a tiny STRUCT. So, expect to see this corrected in the next release.
EDIT

So, now I go look at the grammar and I see that STRUCTs are allowed inside user modules, but only after the END statement. If you simply move the STRUCT in the code to the end, it should parse with no errors.

Would you prefer the ability to place STRUCTs wherever you want? Or at least wherever you want at the module level?

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
STPendl
Full Member


Joined: 20 Aug 2007
Posts: 161
Location: Austria

PostPosted: Aug 3rd, 2014, 9:21am    Post subject: Re: Experiment - Date literals and data type Reply with quote

The following is now parsed without error.
Code:

require IO #out
Dim US_presidents() As person = { _
   { "George Washington", @1732-02-22, @1799-12-14 }, _
   { "Abraham Lincoln", @1809-02-12, @1865-04-15 }, _
   { "Theodore Roosevelt", @1858-10-27, @1919-01-06 } _
}

Dim randDate As Date = RandomDate()
For Each prez In US_presidents()
   If prez.birth <= randDate <= prez.death Tol @12:00:00
      #out "President " & prez.name & " was alive in " & randDate & "."
   End If
End For
End
Struct person
   name As String
   birth As Date
   death As Date
End Struct


I would appreciate being able to place the declaration wherever I want in the module.

I usually prefer to place variable declarations at the beginning of the code for global variables and at the beginning of a procedure for local variables.

It is strange to have a variable or custom type used before its declaration.

Having procedures declared after the main code looks familiar, even so many languages force declaration of procedures before their use too.

_________________
Stefan

Any code I post can be freely used, just give credit.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> ViviFire language All times are GMT
Page 1 of 1
Jump to:  
Quick Reply
Username:
Message:
   Shortcut keys: Alt+Q to activate, Alt+P to preview, Alt+S to submit
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group