/ ======= / HIGHLIGHT THIS LINE AND TAP F9 / ======= / NEWJOB `YourName / =================== / BASIC INSTRUCTIONS BELOW / ==================== / / =================== / / ==================== / / ==================== / /(/ / © 20011021 - 200205 Bob Armstrong / /(/ " It takes a lot of living to make a House a Home " / / Mike Montalbano , APL~81 , JCL poem , ala Edgar Guest . / /)/ /(/ GETTING STARTED : / Tap f1 for defined keys and their help attributes . / ( see also the K Reference Manual and the "\" displays in the raw console ) Note that this text is in the variable `text in the dictionary `CoSy which is in the root of the K-tree . 1 - 2 / Tap the f6 key to execute this line . note what happened / to `l and `r . ( change the numbers and see what happens ) The unique aspect of the CoSy environment is that if you hit "Enter" , CoSy essentially just leaves your text alone . On the other hand , if you tap "f6" it will execute the line in K , saving the line itself in `l ( the previous line is stored in `ll ) and presenting any result in `r . Tapping `f5 inserts `r into `text below the line you are on . `ctrl_s SAVES the dictionary you are in ( in this case `.CoSy ) to your disk under the same name with "." changed to "/" ( MS "\" ) and ".csd" suffixed . Thus you have the immediacy and non-linearity of the traditional APL workspace rather than the construction of a script which must be recompiled for each change . *** I strongly suggest that you make a copy of your originally downloaded CoSy.csd file for convenient referral *** *** ( TAP ctrl_s NOW JUST TO GET THE SAVEing HABIT ) *** NB : A directory must exist in the operating system for the parent of the Job you are saving . For instance , since `.CoSy.Fact will save to \CoSy\Fact.csd , the directory \CoSy already has to exist in the operating system . The direct mapping of "dot"ed names in K.CoSy to *.csd files in the OS directory is very convenient . *.csd files can simply be attached in to emails to transfer entire Jobs or branches of the K-tree . / Hit f1 for a list of function keys and their definitions . / The CoSy environment is constructed totally in K`s Graphical User Interface . Because K's GUI was designed more for spreadsheet type display and editing , it has some serious quirks and limitations when used to edit text like this . Most profoundly , because each cell in a display ( e.g : this line in the variable `text ) is considered an atom , the position of the cursor within a line is not available in the language . Thus , it is not possible to , for instance , define a key to split a line or insert or delete characters at the cursor location . I`ve therefore defined the `ins key to insert a blank line and the `del key to delete the line under the cursor ( backing it up in `Undo ) . TO DELETE CHARACTERS , YOU MUST USE THE BACKSPACE KEY . To somewhat make up for this deficiency , I have defined `ctrl_y to merge the line the cursor is on with the next line . /(/ thu.jul.20010719.1201/ I have implemented `ctrl_u to split the line above a line with a single non blank character , at that charater . /)/ Almost all definitions use the relative addressing of , e.g. : functions , thru the root variable `.R which is set to `.CoSy . Use of absolute references in definitions , e.g. : " html.tok " instead of " ( html `tok ) " or html[ `tok ] , is asking for reference errors -- -- which blow away the entire dictionary affected . You don`t want to go there . A corollary of this fear is that when you`ve been doing some hacking , do a SAVE ( ctrl_s while in `.CoSy ) and try to start the new copy . If there are ref errors , you can delete or ammend the offending links before quitting the environment you are working in . NB : if the display stops responding , check the naked K session . Most likely an un trapped key error has occured and a "\" on a line by itself in the K session will get things going again . NB : parse errors are often really value ( undefined symbol ) errors which show up in the K session rather than being returned . / ======================== // ======================== / Here are some examples to get you started and show you the fundamental structures making up CoSy . Just `f6 them to execute . ( I`ve commented out some dangerous but important examples ) NB : I am a fanatic about white space being the fundamental delimiter . Any extensions to the language will depend upon it . Therefore , I always separate tokens in K expressions IF they can be . This is oposite the common practice of most K programmers to run things together unless they must be spaced . Frankly , I find my style much easier to read . Extensions , like the multi line comment token at the end of this line , depend on it . /)/ 5 - ! 10 / Tap the f6 key to execute this line . note what happened / / to `l and `r . / / Tap f5 . See it inserts r in the text . : Q : | r / You can save anything to a name using ":" . Normally assignment / / returns nil , _n , and doesn't display in `r . / / The monadic ":" on the left is "result" , a useful trick . 3 * Q / Now you can do something else with it . ( _d ; _v ; MVs ( $ _i ) ) / Where you are in the K-tree . ! .CoSy / show objects in the dictionary .CoSy . ! ` / show objects in root "." `.k and `.t are intrinsic in K . .R / `.R is set to `.CoSy for reference from anywhere . / / `.S is a stack on which `ctrl_c pushes and `ctrl_v pops / / lines of text . / / `.r is a general purpose "scratch pad" . / / `.Cmds is a window , evoked by f8 , of useful commands . dics _d / subdictionaries of current dictionary . Jobs _d / Jobs ( like .CoSy ) in current dictionary . f4 @ 5::' r / insert as tokens in text below for simple "f9"ing . / / The identifying feature of Jobs is : / `l `r `text ~ 3 # .CoSy..a newjob / prototype Job dictionary . newjob / prototype Job dictionary displayed as a list of 3 item lists . / / each 3 item list is of the form : ( `name ; value ; attributes ) / / note the attribute dictionaries on `r `text and `GL . / / These are where keystroke definitions , etc are stored . `show $ `newjob / Show the dictionary `newjob as its own window . / `f9 is programmed to / `show $ . / the part of a line after the last comment / symbol , "/" , on the line . thus you can show a Job by typing its name / like on this line , and tapping `f9 / `newjob / ( a number of functions , like `iz , return the name of the object / they create or modify . Thus you can get tricky and both execute the line / like `f6 , and display the resulting object , all by tapping `f9 . text. / The definitions of all the programmed keys under `text . / text. : r / Redefine programmed keys after editing `r . / text. : Dsel[ text. ; sort @ ! text. ] / sort key names alphabetically r. / Key defs under `r , the result of `f6ing a line in `text . .r. / Key defs under `.r . Note the self show trigger . / EDITing objects in K.CoSy is in many cases surprizingly easy . / You simply display them , edit them , and reassign them . fns _d / Functions in the current dictionary in order of definition . / You can define a function like any other variable : rtb : { ( nctb x ) _ x } rtb..h : " remove trailing blanks / Eugene McD " / You can redefine one line functions , or even dictionaries of one / line functions directly just by displaying them in `r and after editing , / simply redefining by , e.g. : rtb / display definition of RemoveTrailingBlanks in `r . / Edit `r as desired / rtb : r / redefine rtb to value of `r . rtb..h / Help for the function `rtb . Can be edited similarly . / The global scratchpad result variable .r is often useful for this . / For multi line functions , I simply format and display in .r , e.g. : .r : VMn @ $ / Display the function `save in `.r . edit it . / save : . MVn .r / after editing , redefine . / save : . _ssr[ $ save ; ".D" ; ".R" ] / example of replacing a variable in a function / Likewise , I edit the startup script using the following : 0: "/cosy/kboot.k" / read & display / "/cosy/kboot.k" 0: r / redefine after editing . ( ( ! text. ) ; text.[ . ; `h ] ) / help on each key . The definition of `f1 / text.[ . ; `h ] : r 1 / edit help from above display . / When my friend Raj was here 010810 , it became clear that this / should be the definition of `f1 , so we did . / To edit help on all fns : tap f2 , edit the help , the execute next line . / .CoSy[ ~ r 0 ; `h ] : r[ 1 ] / reassign edited help . .r : viewhelp sort @ ! _d / Safer , editing All items in _d in .r / .CoSy[ ~ .r 0 ; `h ] : .r[ 1 ] / reassign edited help . / Editing a text file .r : 0: "/CoSy/K/KonsolDoc.txt" / for convenience : the K consol "\" doc / "/CoSy/K/KonsolDoc.txt" 0: .r / is reproduced in .r in distribtion copy / ":" only assigns the value , not the attributes of an object . / `iz replicates both value and attributes . Since it returns the name of / the new object , f9 , which takes names , will both create and show the object . iz . `People.BobA `BobA / Clone a Job to another place . / `NEWJOB creates empty "CoSy" like sub-dictionary or "Job"s : / newjob[ `r. `text. ] : ( r. ; text. ) / update newjob for any key changes Current : newjob ; Current. : newjob. / `newjob stores a prototype of `.CoSy . `show $ `Current / display it . / DELETEing objects is somewhat complicated by the fact that you cannot / delete objects from the dictionary you are in , or that have references / to themselves . This mainly effects deleting objects from .CoSy itself . / Generally to delete names from a dictionary , simply list it by f6ing it , / deleting lines in `r , and reassigning it . No other editing actions / work with dictionaries displayed in `r or `.r . Example : tst : .() ; tst[ `a `s `d `f ] : "asdf" ; tst / make and display a dictionary / delete one of the lines in the `r display . then : tst : r / obviously you can assign r to tst . done . / To delete objects in .CoSy itself , assign them the value `delete and they / will be garbage collected the next time you do a `save . `QWE : `delete / Mark object `QWE for deletion from future "save"s . / The word `delete sets whole lists of words to `delete at once . -20 # ! _d / I displayed last 20 objects defined in _d , `f5ed to insert in text . `s0 `s2 `tst / edited down to this list . delete `s0 `s2 `tst / They will be left out in next `save . ----- f4 @ 5::' Jobs _d / list Jobs in dictionary for convenient `f9ing . f4 @ _dvl/ ( dics ; Jobs ) @\: _d / All dictionaries which are not Jobs / RESTORING FROM *.csd FILES / ======================================= / ( saved `.CoSy ) `text / `text from the saved "\CoSy.csd" file ( saved "/CoSy/Fact" ) `text / `text from the saved "\CoSy\Fact.csd" file . / You can use either the K.CoSy symbol name , or the OS name w/o the ".csd" restore[ `tst ; `.CoSy.Fact ] / creates a dictionary named tst from file /CoSy/Fact text : _ssr[ ; "O " ; ": " ]' text / replace all occurances of a string . text -1 0 1 + * & ~ "C" = nc' text / find rows of `text which are not char strs . `show $ `acnt / simple ledger template . /(/ Hope this helps get you started . It is just the beginning . Please direct all questions and comments to the mail list . -- Bob A -- /)/ / ======================== / mon jul 20010709 / ======================== / /1120/ /sat.jul.20010728.1105/ /(/ wed.oct.20011024.837 /)/ / ======================== // ======================== / /(/ Color pallet : / ------------------------------------- I created this to have a numerical pallet on my Sony which I could understand . This is also on http://CoSy.com . /)/ `show $ `Pallet / Already created . / Here is the "script" to recreate . Execute each line in sequence . d2h : { "0123456789ABCDEF" @ 16 16 _vs x } d2h..h : " format integers as hex " Pallet.colors : ( 0 , 3 + 4 * ! 25 ) */: 10000 100 1 / K's R G B encoding / / K's R G B encoding , 0 - 99 each , stepping by 4 . Pallet.colors..bg : Pallet.colors / Set background colors to the same values Pallet.colors..k : " .[ `ci ; _i 0 ; : ; _v . _i ] ; " / / set cursor klik to update `ci . Pallet.ci : 3 # 0 0 0 / initialize index keeping variable Pallet.ci..t / : " hexcolor..bg : color..bg : color : +/ ci " / / set trigger to update `color to sum of ci . Pallet.scalecolor : { _ ( ( 3 # 100 ) _vs x ) * 255 % 99 } Pallet.hexcolor..d : " ,/ ( .R `d2h )' scalecolor color " Pallet..c : `form ; Pallet..a : ( `color `hexcolor ; `colors ) Pallet..h : " color picking pallet . shows sum of colors clicked in each column " `show $ `Pallet .r..bg : 809940 / set .r background color . / ------------------------------------------------------- / Simplest way to get things to the clip board . oF : "/cosy/tmp.txt" oF..h : " standard scratch output file " oF 0: text /(/ Examine unknown file / ====================== // ====================== / Q : "c" 1: "/temp/Rechnung Herr Nieswiatowski.doc.lnk" cut[ "\n" ; Q ] / This was in fact an email virus . I didn`t open it . /)/ ,/ 3 # , hr "/ ==================== // ==================== // ==================== /" Plot : ! 1000 ; Plot..c : `chart ; `show $ `Plot Plot : +\-1 + 2 * 1000 _draw 2 / execute a few times Plot : `delete / ==================== // ==================== // ==================== / /(/ Starting to be used in scripts : kc : " /(/ " ; ck : " /)/ " kc..h : " start token for multi line K comment . " ck..h : " end token for multi line K comment . " /)/ / ====================== / bob@CoSy.com / ====================== / / wed.oct.20011024 / "/ ======================== / All for Now / ======================== /" .r : 0: "/CoSy/K/KonsolDoc.txt" / for convenience : the K consol "\" doc / ======================== / \/ \/ \/ / ======================== / KLOK..d : " tsl TS :: _ltime .t " \t 1 `KLOK /(/ NB : It's always a good idea to keep a few blank lines at the bottom of a window because ctrl_v inserts ABOVE the current line . You'll figure out the consequences for your self . /)/