On Thu, 24 Apr 2025 11:36:10 -0400, Rick McGuire wrote:
>::routine checkDate
>  use arg date
>  signal on syntax
>  d = date('s', date, 's')
>  return .true
>  syntax: return .false

I'd want to make this more general with:

  Use Arg date, format, sep

But it's a pain when a function cares whether an argument is omitted vs.
blank or null.  For a method, you can stick the arguments in an array and
use FORWARD, but for a function it takes enumerating all the different
call formats:

  If Arg(1, 'E') Then
    If Arg(2, 'E') Then 
      If Arg(3, 'E') Then
        Call Date , date, format, , sep
      Else
        Call Date , date, format
    Else
      If Arg(3, 'E') Then
        Call Date , date,       , , sep
      Else
        Call Date , date
  Else
    Raise Syntax 40.5 Array('DATE', 2) /* missing argument 2 */

My assumption here is that it wouldn't be useful to return 1 when no args
at all were provided, even though DATE() would happily return the current
date.  I suppose there could be an argument for allowing that, so you can
validate the full argument list before calling DATE.  Since the error is
this same missing argument 2 when a format or separator is provided
without a date, no need to fill in the whole decision tree:

  Else
    If Arg(2, 'E') | Arg(3, 'E') Then
      Raise Syntax 40.5 Array('DATE', 2) /* missing argument 2 */
/*  Else Nop -- no arguments at all, we're fine */ 

Or I suppose if you want a trace to show the successful result, you could
go ahead and make the call with no arguments:

  Else
    If Arg(2, 'E') | Arg(3, 'E') Then
      Raise Syntax 40.5 Array('DATE', 2) /* missing argument 2 */
    Else Call Date

¬R




_______________________________________________
Oorexx-users mailing list
Oorexx-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-users

Reply via email to