The function date∆US in workspace date should accept any valid US date as characters and return a three element vector of year month day.

Today (as the log will show) date∆US date∆parse '15 JAN 2012' did more than that.

I hope I've included all the files thee needs to replicate this. If not try https://sourceforge.net/projects/apl-library/ . Please use

 git clone git://git.code.sf.net/p/apl-library/code apl-library-code


I await your pleasure before updating the tar ball.


w


Network listener started. Connection information: mode:tcp addr:34574
      )load 1 date
DUMPED 2016-12-11 12:56:37 (GMT-5)
DUMPED 2016-12-11 12:59:03 (GMT-5)
DUMPED 2016-11-13 08:46:53 (GMT-5)
      date∆US date∆parse '15 JAN 2012'

*** Attempt to start a new joblist at ScalarFunction.cc:429 while joblist from ScalarFunction.cc:429 is not finished

----------------------------------------
-- Stack trace at Parallel.hh:442
----------------------------------------
0x7fabd5ea5830 __libc_start_main
0x4460d5  main
0x56b6fd   Workspace::immediate_execution(bool)
0x487e59    Command::process_line()
0x487efd     Command::do_APL_expression(UCS_string&)
0x492398      Executable::execute_body() const
0x520080       StateIndicator::run()
0x4c5779        Prefix::reduce_statements()
0x4c04f2         Prefix::reduce_A_F_B_()
0x51b542          Bif_F2_EQUAL::eval_AB(Value_P, Value_P)
0x515d2c           ScalarFunction::eval_scalar_AB(Value_P, Value_P, ErrorCode (Cell::*)(Cell*, Cell const*) const)
========================================

*** Attempt to start a new joblist at ScalarFunction.cc:429 while joblist from ScalarFunction.cc:429 is not finished

----------------------------------------
-- Stack trace at Parallel.hh:442
----------------------------------------
0x7fabd5ea5830 __libc_start_main
0x4460d5  main
0x56b6fd   Workspace::immediate_execution(bool)
0x487e59    Command::process_line()
0x487efd     Command::do_APL_expression(UCS_string&)
0x492398      Executable::execute_body() const
0x520080       StateIndicator::run()
0x4c5779        Prefix::reduce_statements()
0x4c04f2         Prefix::reduce_A_F_B_()
0x51b542          Bif_F2_EQUAL::eval_AB(Value_P, Value_P)
0x515d2c           ScalarFunction::eval_scalar_AB(Value_P, Value_P, ErrorCode (Cell::*)(Cell*, Cell const*) const)
========================================
2012 1 15
      
#!/usr/local/bin/apl --script
 ⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝
⍝
⍝ date 2016-11-29 12:51:06 (GMT-5)
⍝
⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝

⍝ date workspace implements lillian dates
⍝ Copyright (C) 2016 Bill Daly

⍝ This program is free software: you can redistribute it and/or modify
⍝ it under the terms of the GNU General Public License as published by
⍝ the Free Software Foundation, either version 3 of the License, or
⍝ (at your option) any later version.

⍝ This program is distributed in the hope that it will be useful,
⍝ but WITHOUT ANY WARRANTY; without even the implied warranty of
⍝ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
⍝ GNU General Public License for more details.

⍝ You should have received a copy of the GNU General Public License
⍝ along with this program.  If not, see <http://www.gnu.org/licenses/>.

)copy 1 util

∇date←date∆lillian ts;b1;b2;b3;yrs;days
⍝ Function to convert time stamp dates to lillian dates
ts[1]←ts[1]-date∆dates lex∆lookup 'Year 0'
⍝yrs←¯1+⍳ts[1]
yrs←⍳ts[1]
b1←0=400|yrs
b2←0=100|(~b1)/yrs
b3←0=4|(~b2)/(~b1)/yrs
days←(b3×366)+(~b3)×365
days←(b2×365)+(~b2)\days
days←(b1×366)+(~b1)\days
ix←1+365=days[ts[1]]
date←+/¯1↓days
date←date++/(ts[2]-1)↑date∆cal[ix;]
date←date+ts[3]
date←date-date∆dates lex∆lookup 'Pre lillian'
⎕es (date ≤ 0)/'PRE LILLIAN DATE'
∇

∇days←date∆marshalYears ts;yrs;b1;b2;b3
 ⍝ Function to assemble vector of days in each year starting with rarg
 yrs←⍳''⍴ts-date∆dates lex∆lookup 'Year 0'
 b1←0=400|yrs
 b2←0=100|(~b1)/yrs
 b3←0=4|(~b2)/(~b1)/yrs
 days←(b3×366)+(~b3)×365
 days←(b2×365)+(~b2)\days
 days←(b1×366)+(~b1)\days
∇

∇ts←date∆unlillian date;yrs;b1;b2;b3;ix
 ⍝ Function to covert a lillian date to a ts formatted date.
 date←date + date∆dates lex∆lookup 'Pre lillian'
 yrs←⍳2+⌈date÷365.25
 b1←0=400|yrs
 b2←0=100|(~b1)/yrs
 b3←0=4|(~b2)/(~b1)/yrs
 days←(b3×366)+(~b3)×365
 days←(b2×365)+(~b2)\days
 days←(b1×366)+(~b1)\days
 ts←3⍴0
 ts[1]←1++/date>+\days
 date←date-+/days[⍳ts[1]-1]
 ix←1+365=days[ts[1]]
 ts[2]←+/date>+\date∆cal[ix;]
 ts[3]←date-+/date∆cal[ix;⍳ts[2]]
 ts[1]←ts[1] + date∆dates lex∆lookup 'Year 0'
 ts[2]←ts[2]+1
∇

∇ts←locale date∆parse str;num;epoch
 ⍝ Function to parse a string and return a integer vector of year, month, day.
 ⍝ One ISO 8601 format
 ⍎(util∆numberp str)/'ts←''NOT TEXT''◊→0'
 str← date∆delim util∆split str
 →(∧/~num←util∆numberis ¨ str)/err
 str[num/⍳⍴num]←⍎,' ',⊃num/str
 →(3=⍴ts←locale date∆parse∆ISO str)/tests
 →(3=⍴ts←locale date∆parse∆long str)/tests
 →(3=⍴ts←locale date∆parse∆short str)/tests
 tests:
 epoch←locale lex∆lookup 'epoch'
 →(ts[1]=0)/er2         ⍝ Year tests failed
 →((ts[1]=epoch[1])^ts[2]<epoch[2])/er2
 →(∧/(ts[1 2]=epoch[1 2]),ts[3]<epoch[3])/er2
 →((ts[2]<1)∨ts[2]>12)/err
 max_days←(locale lex∆lookup 'days')[ts[2]]
 mex_days←max_days+date∆US date∆parse∆leap_day ts
 →((ts[3]<1)∨ts[3]>max_days)/err
 →0
 err:
 ts←'NOT A DATE'
 →0
 er2:
 ts←'DATE BEFORE EPOCH STARTING ','0006-06-06'⍕epoch
 →0
∇

∇dt←locale date∆parse∆ISO txt
 ⍝ Function attempts to convert text in an ISO 8601 format to a date
 ⍝ made up of year month day.
 dt←3⍴0
 →(3=⍴txt)/extended
 →(1≠⍴txt)/err
 basic_iso:
 dt[1]←⌊txt÷10000
 txt←10000 | txt
 dt[2]←⌊txt÷100
 dt[3]←100 | txt
 →0
 extended:
 →(3≠+/util∆numberp ¨ txt)/err
 →(0=⍴dt[1]←locale date∆test∆year txt)/err
 →(dt[1]=txt[1])/iso_date
 dt[2 3]←txt[(locale lex∆lookup 'month_pos'),locale lex∆lookup 'day_pos']
 →0
 iso_date:
 dt←txt
 →0
 err:
 dt←''
 →0
∇

∇dt←locale date∆parse∆leap_day ts;leap_month
 ⍝ Function returns 1 if the leap-month number of days should be incremented.
 leap_month←locale lex∆lookup 'leap-month'
 →(~dt←ts[2]=leap_month)/0
 →(dt←0=400|ts[1])/0
 →(~dt←0≠100|ts[1])/0
 dt←0=4|ts[1]
∇

∇dt←locale date∆parse∆long txt
 ⍝ Function attempts to convert test in a long, spelled out form to a
 ⍝ date made up of year month day.
 dt←3⍴0
 '→err' ⎕ea 'dt[2]←(locale lex∆lookup ''months'') util∆stringSearch util∆lower 
⊃txt[1]'
 →(∨/0≠≡¨txt[2 3])/err
 dt[1]←txt[3]
 dt[3]←txt[2]
 →0
 err:
 dt←''
 →0
∇

∇dt←locale date∆parse∆short txt;m
 ⍝ Function attempts to convert text in a short abbreviate form to a
 ⍝ date made up of year month day.
 dt←3⍴0
 m←locale lex∆lookup 'MTH'
 '→mil' ⎕ea 'dt[2]←m util∆stringSearch util∆upper ⊃txt[1]'
 dt[1]←txt[3]
 dt[3]←txt[2]
 →0
 mil:                           ⍝ Try military format
 '→err' ⎕ea 'dt[2]←m util∆stringSearch util∆upper ⊃txt[2]'
 dt[1]←txt[3]
 dt[3]←txt[1]
 →0
 err:
 dt←''
 →0
∇

∇yr←locale date∆test∆year dt;e;t
 ⍝ Function called when all three elements of a date are numeric to
 ⍝ determine what the year is.
 yr←dt[1]                       ⍝ We try ISO dates first
 →(yr≥e←1↑locale lex∆lookup 'epoch')/0
 yr←dt[locale lex∆lookup 'year_pos']
 →(yr≥e)/0
 →((dt[1]>1000)∨yr≥100)/err
 t←locale lex∆lookup 'two-digit-cutoff'
 yr←yr+(1900 2000)[1+(yr>0)∧yr<t]
 →0
 err:
 yr←0
 →0
∇

date∆US←11 2⍴0 ⍝ prolog ≡1
  (,date∆US)[⍳22]←00 00 00 00 00 00 00 00 00 00 00 50 00 2 00 1 00 00 00 3 00 2
    ((⎕IO+(⊂0 0))⊃date∆US)←'months'
    ((⎕IO+(⊂0 1))⊃date∆US)←00 00 00 00 00 00 00 00 00 00 00 00
      ((⎕IO+(0 1) 0)⊃date∆US)←'january'
      ((⎕IO+(0 1) 1)⊃date∆US)←'february'
      ((⎕IO+(0 1) 2)⊃date∆US)←'march'
      ((⎕IO+(0 1) 3)⊃date∆US)←'april'
      ((⎕IO+(0 1) 4)⊃date∆US)←'may'
      ((⎕IO+(0 1) 5)⊃date∆US)←'june'
      ((⎕IO+(0 1) 6)⊃date∆US)←'july'
      ((⎕IO+(0 1) 7)⊃date∆US)←'august'
      ((⎕IO+(0 1) 8)⊃date∆US)←'september'
      ((⎕IO+(0 1) 9)⊃date∆US)←'october'
      ((⎕IO+(0 1) 10)⊃date∆US)←'november'
      ((⎕IO+(0 1) 11)⊃date∆US)←'december'
    ((⎕IO+(⊂1 0))⊃date∆US)←'MTH'
    ((⎕IO+(⊂1 1))⊃date∆US)←00 00 00 00 00 00 00 00 00 00 00 00
      ((⎕IO+(1 1) 0)⊃date∆US)←'JAN'
      ((⎕IO+(1 1) 1)⊃date∆US)←'FEB'
      ((⎕IO+(1 1) 2)⊃date∆US)←'MAR'
      ((⎕IO+(1 1) 3)⊃date∆US)←'APR'
      ((⎕IO+(1 1) 4)⊃date∆US)←'MAY'
      ((⎕IO+(1 1) 5)⊃date∆US)←'JUN'
      ((⎕IO+(1 1) 6)⊃date∆US)←'JUL'
      ((⎕IO+(1 1) 7)⊃date∆US)←'AUG'
      ((⎕IO+(1 1) 8)⊃date∆US)←'SEP'
      ((⎕IO+(1 1) 9)⊃date∆US)←'OCT'
      ((⎕IO+(1 1) 10)⊃date∆US)←'NOV'
      ((⎕IO+(1 1) 11)⊃date∆US)←'DEC'
    ((⎕IO+(⊂2 0))⊃date∆US)←'weeokdays'
    ((⎕IO+(⊂2 1))⊃date∆US)←00 00 00 00 00 00 00
      ((⎕IO+(2 1) 0)⊃date∆US)←'sunday'
      ((⎕IO+(2 1) 1)⊃date∆US)←'monday'
      ((⎕IO+(2 1) 2)⊃date∆US)←'tuesday'
      ((⎕IO+(2 1) 3)⊃date∆US)←'wednesday'
      ((⎕IO+(2 1) 4)⊃date∆US)←'thursday'
      ((⎕IO+(2 1) 5)⊃date∆US)←'friday'
      ((⎕IO+(2 1) 6)⊃date∆US)←'saturday'
    ((⎕IO+(⊂3 0))⊃date∆US)←'wkd'
    ((⎕IO+(⊂3 1))⊃date∆US)←00 00 00 00 00 00 00
      ((⎕IO+(3 1) 0)⊃date∆US)←'SUN'
      ((⎕IO+(3 1) 1)⊃date∆US)←'MON'
      ((⎕IO+(3 1) 2)⊃date∆US)←'TUE'
      ((⎕IO+(3 1) 3)⊃date∆US)←'WED'
      ((⎕IO+(3 1) 4)⊃date∆US)←'THU'
      ((⎕IO+(3 1) 5)⊃date∆US)←'FRI'
      ((⎕IO+(3 1) 6)⊃date∆US)←'SAT'
    ((⎕IO+(⊂4 0))⊃date∆US)←'days'
    ((⎕IO+(⊂4 1))⊃date∆US)←31 28 31 30 31 30 31 31 30 31 30 31
    ((⎕IO+(⊂5 0))⊃date∆US)←'two-digit-cutoff'
    ((⎕IO+(⊂6 0))⊃date∆US)←'leap-month'
    ((⎕IO+(⊂7 0))⊃date∆US)←'month_pos'
    ((⎕IO+(⊂8 0))⊃date∆US)←'epoch'
    ((⎕IO+(⊂8 1))⊃date∆US)←1582 10 15
    ((⎕IO+(⊂9 0))⊃date∆US)←'year_pos'
    ((⎕IO+(⊂10 0))⊃date∆US)←'day_pos'

∇Z←date⍙metadata
 Z←0 2⍴⍬
 Z←Z⍪'Author'          'Bill Daly'
 Z←Z⍪'BugEmail'        '[email protected]'
 Z←Z⍪'Documentation'   'date.txt'
 Z←Z⍪'Download'        
'https://sourceforge.net/p/apl-library/code/ci/master/tree/date.apl'
 Z←Z⍪'License'         'GPL v3.0'
 Z←Z⍪'Portability'     'L1'
 Z←Z⍪'Provides'        ''
 Z←Z⍪'Requires'        ''
 Z←Z⍪'Version'         '0 0 1'
∇

date∆delim←'/\- ,'

date∆dates←((lex∆init) lex∆assign 'Year 0' 1200) lex∆assign 'Pre lillian' 139444

date∆cal←31,29 28,2 10 ⍴ 31 30 31 30 31 31 30 31 30 31
#!/usr/local/bin/apl --script

⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝
⍝
⍝ lex 2016-08-29 15:55:56 (GMT-5)
⍝
⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝⍝

⍝ Copyright (C) 2016  Bill Daly

⍝ This program is free software: you can redistribute it and/or modify
⍝ it under the terms of the GNU General Public License as published by
⍝ the Free Software Foundation, either version 3 of the License, or
⍝ (at your option) any later version.

⍝ This program is distributed in the hope that it will be useful,
⍝ but WITHOUT ANY WARRANTY; without even the implied warranty of
⍝ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
⍝ GNU General Public License for more details.

⍝ You should have received a copy of the GNU General Public License
⍝ along with this program.  If not, see <http://www.gnu.org/licenses/>.

∇nx←lx lex∆assign item;ix;keys;keyShape
  ⍝ Function to assign a value to a key where larg is the lexicon and
  ⍝ rarg is a key value pair. Pair will be added if the key is not in
  ⍝ the lexicon.
  nx←lx
  →(' '≠1↑0⍴⊃item[1])/err
  →(0=1↑⍴nx)/add                        ⍝ Test for empty lexicon
  keyShape←⍴keys←⊃nx[;1]
  ix←(keys∧.=keyShape[2]↑⊃item[1])/⍳keyShape[1]
  →(0=⍴ix)/add
replace:
  nx[ix;2]←item[2]
  →0
add:
  nx←nx,[1]item
  →0
err:
  ⍞←'Lexicon entries must use a character string as a key'
  →0
∇

∇new←lex lex∆drop key;rlex;tbl
  ⍝ Function to drop a key value pair
  ⍎(0=1↑⍴lex)/'new←lex◊→0'
  rlex←(⍴tbl←⊃lex[;1])⌈0,⍴key←,key
  new←(~(rlex↑tbl)∧.=rlex[2]↑key)⌿lex
∇

∇bool←lex lex∆haskey key;rkey;keys
  ⍝ Function searches for key in lexicon lex and returns true if found.
  ⍎(0=1↑rkey←⍴keys←⊃lex[;1])/'bool←0◊→0'
  rkey[2]←rkey[2]⌈⍴key←,key
  bool←∨/(rkey↑keys)∧.=rkey[2]↑,key
∇

∇lex←lex∆init
  ⍝ Function to initiate a lexicon
  lex←0 2⍴''
∇

∇b←lex∆is lex
  ⍝ Predicate returns true if argument is in fact a lexicon
  ⍎(2≠⍴⍴lex)/'b←0◊→0'
  ⍎(∧/0 2=⍴lex)/'b←1◊→0'
  ⍎(2>≡lex)/'b←0◊→0'
  b←∧/' '=1↑0⍴⊃lex[;1]
∇

∇keys←lex∆keys lx
  ⍝ Function returns a list of keys in a lexicon
  keys←lx[;1]
∇

∇value←lex lex∆lookup key;keyShape;keys;ix
  ⍝ Function returns the value of key in a lexicon
  keyShape←⍴keys←⊃lex[;1]
  ⍎(0=ix←''⍴(keys∧.=keyShape[2]↑key)/⍳keyShape[1])/'value←''''◊→0'
  value←⊃lex[ix;2]
∇

∇vals←lex∆values lx
  ⍝ returns the valus in a lexicon
  vals←lx[;2]
∇

∇Z←lex⍙metadata
  Z←0 2⍴⍬
  Z←Z⍪'Author'          'Bill Daly'
  Z←Z⍪'BugEmail'        '[email protected]'
  Z←Z⍪'Documentation'   'lex.txt'
  Z←Z⍪'Download'        
'https://sourceforge.net/p/apl-library/code/ci/master/tree/lex.apl'
  Z←Z⍪'License'         'GPL v3.0'
  Z←Z⍪'Portability'     'L1'
  Z←Z⍪'Provides'        ''
  Z←Z⍪'Requires'        ''
  Z←Z⍪'Version'         '0 0 1'
∇
#! /usr/local/bin/apl --script
⍝ ********************************************************************
⍝   $Id: $
⍝ $desc: Library of useful apl functions $
⍝ ********************************************************************

⍝ Util
⍝ Copyright (C) 2016  Bill Daly

⍝ This program is free software: you can redistribute it and/or modify
⍝ it under the terms of the GNU General Public License as published by
⍝ the Free Software Foundation, either version 3 of the License, or
⍝ (at your option) any later version.

⍝ This program is distributed in the hope that it will be useful,
⍝ but WITHOUT ANY WARRANTY; without even the implied warranty of
⍝ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
⍝ GNU General Public License for more details.

⍝ You should have received a copy of the GNU General Public License
⍝ along with this program.  If not, see <http://www.gnu.org/licenses/>.

)copy 1 lex

∇rpt←bfld util∆breakon data;bv;b2;cols;bc;tl
 ⍝ Function builds a report of the data by inserting subtotals where
 ⍝ bfld changes
 cols←(,⊃∧⌿util∆numberp¨data)/⍳1↓⍴data
 tl←(1↓⍴data)⍴⊂' '
 →(∧/bv←∧\bfld=bfld[1])/exit
 tl[cols]←+⌿bv⌿data[;cols]
 rpt←(bv⌿data),[1]tl,[1](b2/bfld) util∆breakon (b2←~bv)⌿data
 →0
 exit:
 tl[cols]←+⌿data[;cols]
 rpt←data,[1]tl
 →0
∇

∇msg←util∆helpFns fn;src
  ⍝ Function to display help about a function
  src←⎕cr fn
  msg←(1,∧\'⍝'=1↓src[;1])⌿src
∇

∇t←util∆numberp v
  ⍝ Fns returns true if its argument is a number.
  ⍎(1<≡v)/'t←0◊→0'
  t←''⍴0=1↑0⍴v
∇

∇b←util∆numberis tst
  ⍝ Function test if a number can be obtained by executing a string
  b←(∧/tst∊'1234567890-¯.')∧∨/0 1=+/tst='.'
  b←b∧∧/~(1↓tst)∊'-¯'
∇

∇a←t util∆over b;w;tr;br
  ⍝ fn to return an array (of rank 2) with t on the top and b on the bottom.
  t←(rt←¯2↑1 1,⍴t)⍴t
  b←(br←¯2↑1 1,⍴b)⍴b
  w←rt[2]⌈br[2]
  rt[2]←br[2]←w
  a←(rt↑t),[1]br↑b
∇

∇new←ws util∆reduce∆whitespace txt;bv
 ⍝ Function to reduce whitespace to one space
 ⍎(2≠⎕nc'ws')/'ws←⎕av[10 11 14 33]'     ⍝ Space, tab and line feed and return
 bv←txt∊ws
 bv←~bv∧(⍴bv)↑0,bv
 new←bv/txt
 new[(new∊ws)/⍳⍴new]←' '
∇

∇New←util∆trim old;b
  ⍝ Function to strip off leading and  trailing spaces.
  New←(+/∧\old=' ')⌽old
  b←⌊/+/∧\⌽New=' '
  →(V,M,E)[3⌊⍴⍴old]
  ⍝ Vector
V:
  New←New[⍳-b-⍴New]
  →0
  ⍝ Matrix
M:
  New←New[;⍳-b-1↓⍴New]
  →0
  ⍝ Error -- rank of old is too high
E:
  ⎕es 'Rank of array is too high'
∇

∇o←k util∆sub d
  ⍝ Function to calculate subtotals for each break point in larg
  o←+\[1]d
  ⍝ Test for rank of data
  ⎕es (~(⍴⍴d) ∊ 1 2)/'RANK ERROR'
  →(V,A)[⍴⍴d]
  ⍝ Vectors
V:o←o[k]-¯1↓0,o[k]
  →0
  ⍝ Arrays (of rank 2)
A: o←o[k;]-0,[1] o[¯1↓k;]
  →0
∇

∇n←util∆import∆numbers s;bv
  ⍝ Function to turn a column of figures (ie characters) into numbers
  ⍎(2=≡s)/'s←⊃s'
  bv←~∧/s=' '
  s[(s='(')/⍳⍴s←,' ',s]←'¯'
  n←bv\⍎(~s∊'),')/s
∇

∇string←delim util∆join array
 ⍝ Function returns a character string with delim delimiting the items
 ⍝ in array.
 string←1↓∊,delim,(⌽1,⍴array)⍴array
∇

∇v←delim util∆split string;b;c
 ⍝ Function splits a character string into a nested array of strings
 ⍝ using delim as the delimiter.
 →(1≠⍴delim←,delim)/many
 →(∧/b←string ≠ delim)/last
 →exit
 many:
 →(∧/~b←string∊delim)/last
 string←(c←~b∧1⌽b)/string
 b←c/~b
 →exit
 exit:
 v←(⊂b/string),delim util∆split 1↓(~b←∧\b)/string
 →0
 last:
 v←⊂string
∇

∇ix← list util∆stringSearch item;rl;ri;l
 ⍝ Utility to search a character list for an item.
 →(1=≡list)/arr
 list←⊃list
 arr:
 ⎕es(2≠⍴rl←⍴list)/'RANK ERROR'
 ri←⍴item←,item
 l←rl[2]⌈ri
 ix←(((rl[1],l)↑list)∧.=l↑,item)⌿⍳rl[1]
∇

∇ix←txt util∆search word;⎕io;old∆io;ixx;bv
  ⍝ Function to search for larg in rarg
  old∆io←⎕io
  ⎕io←0
  ixx←⍳⍴txt←,txt
  bv←(txt=1↑word←,word)∧ixx≤(⍴txt)-⍴word
  ix←bv/ixx
  ix←old∆io+(txt[ix∘.+⍳⍴word]∧.=word)/ix
∇

∇new←txt util∆replace args;ix
  ⍝ Function to search for and replace an item in rarg.  Larg is a two
  ⍝ element vector where Larg[1] is the text to search for, Larg[2] is
  ⍝ the replacement text.
  ix← txt util∆search ⊃args[1]
  new←((¯1+ix)↑txt),(,⊃args[2]),(¯1+(ix←''⍴ix)+⍴,⊃args[1])↓txt
∇


∇resp←util∆prompt prompt;test;sink;ans
 ⍝ Subroutine to prompt for user input.
   sink←⍞←prompt
   ans←⍞
   test←(∧\ans≠' ')/ans
   →(util∆numberp test←util∆∆keys ans)/kw
   resp←ans
   →0
 kw:
   resp←test
   →0
∇

∇t←n util∆execTime c;ts;lb;i
  ⍝ Function returns the number of milliseconds a command took. larg
  ⍝ is the number of to execute command.  If larg is missing we
  ⍝ execute once.
  →(2=⎕nc 'n')/many
  ts←⎕ts
  ⍎c
  →ed
many:
  lb←(n⍴st),ed
  i←0
  ts←⎕ts
st:
  ⍎c
  →lb[i←i+1]
ed:
  t←⎕ts
  t←(60 1000⊥t[6 7])-60 1000⊥ts[6 7]
  →0
∇

∇o←util∆∆keys i;k
   ⍝ Function to return a keyword number if i is a keyword.
   k←((4 4 ⍴ 'quittop doneback')∧.=4↑o←,i)/⍳4
   →((4<⍴i)∨0=⍴k)/0
   o←k-⎕io
   →0
∇

∇today←util∆today;ts
 ⍝ Function to return today's date as a string
 ts←⎕ts[2 3 1]
 today←('05'⍕ts[1]),'/',('05'⍕ts[2]),'/','5000'⍕ts[3]
∇

∇txt←util∆lower m;ix
  ⍝ Function to convert text to all lower case.
  m←⎕ucs m←,m
  ix←((m≥65)∧m≤90)/⍳⍴m
  m[ix]←m[ix]+32
  txt←⎕ucs m
∇

∇txt←util∆upper m;ix
  ⍝ Function to convert text to all lower case.
  m←⎕ucs m←,m
  ix←((m≥97)∧m≤122)/⍳⍴m
  m[ix]←m[ix]-32
  txt←⎕ucs m
∇

∇Z←util⍙metadata
  Z←0 2⍴⍬
  Z←Z⍪'Author'          'Bill Daly'
  Z←Z⍪'BugEmail'        '[email protected]'
  Z←Z⍪'Documentation'   'lex.txt'
  Z←Z⍪'Download'        
'https://sourceforge.net/p/apl-library/code/ci/master/tree/util.apl'
  Z←Z⍪'License'         'GPL v3.0'
  Z←Z⍪'Portability'     'L1'
  Z←Z⍪'Provides'        ''
  Z←Z⍪'Requires'        ''
  Z←Z⍪'Version'         '0 0 5'
∇

Reply via email to