How to resolve the algorithm Take notes on the command line step by step in the APL programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Take notes on the command line step by step in the APL programming language

Table of Contents

Problem Statement

Invoking NOTES without commandline arguments displays the current contents of the local NOTES.TXT if it exists. If NOTES has arguments, the current date and time are appended to the local NOTES.TXT followed by a newline. Then all the arguments, joined with spaces, prepended with a tab, and appended with a trailing newline, are written to NOTES.TXT. If NOTES.TXT doesn't already exist in the current directory then a new NOTES.TXT file should be created.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Take notes on the command line step by step in the APL programming language

Source code in the apl programming language

#!/usr/local/bin/apl -s --

rch Join ls                          ⍝ Join list of strings with character 
        r1ch,¨ls


dDate                                ⍝ Get system date as formatted string
        d'/'Join ¨13⎕TS


tTime;t24                            ⍝ Get system time as formatted string
        tt2433⎕TS                  ⍝ Get system time
        t[1]t[1]-12×t24[1]12         ⍝ If PM (hour≥12), subtract 12 from hour
        t[1]t[1]+12×t[1]=0            ⍝ Hour 0 is hour 12 (AM)
        t¯2¨'0',¨¨t                 ⍝ Convert numbers to 2-digit strings
        t(':'Join t),(1+t24[1]12)' AM' ' PM'  ⍝ Add AM/PM and ':' separator


Read;f
        (¯2f⎕FIO[49]'notes.txt')/0  ⍝ Read file, stop if not found
        f                           ⍝ Output file line by line


Write note;f;_
        note' 'Join note              ⍝ flatten input and separate with spaces
        noteDate,' ',Time,(⎕UCS 10 9),note,⎕UCS 10   ⍝ note format
        f'a'⎕FIO[3]'notes.txt'        ⍝ append to file
        _(⎕UCS note)⎕FIO[7]f          ⍝ write note to end of file
        _⎕FIO[4]f                     ⍝ close the file


Notes;note
        ('Read' 'Write note')[1+0note4⎕ARG]


Notes
)OFF


  

You may also check:How to resolve the algorithm Hello world/Line printer step by step in the N/t/roff programming language
You may also check:How to resolve the algorithm Random number generator (device) step by step in the Delphi programming language
You may also check:How to resolve the algorithm Dinesman's multiple-dwelling problem step by step in the Lua programming language
You may also check:How to resolve the algorithm Ascending primes step by step in the Fortran programming language
You may also check:How to resolve the algorithm Palindrome dates step by step in the FreeBASIC programming language