Christian Back in August, I started using GNU APL -- the first thing I did was to bring up the Toronto Toolkit. The second was to implement edit function and edit array. Find attached my work.
I convert the text of the function to a 'del' definition, edit it, and then read it in with )copy. A )reset could be added, but I decided against that. Yes, I understand that xed and xeda are horrible hacks -- they work for me. If you want to generalize and and to bits&pieces, feel free to do so. cr2lf is defined here to allow "easier" bringing in of external data into a workspace. howdel is a reminder of the features of the del editor (and some tricks, like capturing interactive for definition). Fred Weigel
#!/usr/local/bin/apl --script â â These functions are written as a sample extension of the Toronto â Toolkit. "explain 'xed'" will work, as will "comments 'xed'". â 'xed', 'xeda' and 'cr2lf' are added to toolkitlist, but only if the â toolkit is present. So, use ")copy 1 toolkit" before ")copy 1 xed" â for proper integration with the toolkit. â â xed is set to call up my "e" editor, which is a terminal application. â It launches xterm to run a new terminal with the editor. This is done â because )host doesn't restore terminal settings before running its â given command. â â As well, "explain 'del'" will provide a reminder of the features of â the del editor in GNU APL. (I used del until xed itself was â operational). â â 'xeda array' edits an array by converting to csv, and using an â external editor (libreoffice calc). It returns the edited array. â It uses CSV to convert the array to a CSV, libreoffice calc to edit â the array, and CSV to read it in again. The CSV library brings in â FILE_IO, which is also needed. â â )COPY 5 FILE_IO )COPY 1 CSV gânl â âUCS 10 gâtmp â '/tmp/' gâeditor â 'e ' gâeditorcsv â 'oocalc ' gâterminal â 'xterm -xrm XTerm.vt100.initialFont:6 -e ' 'â' âEA 'toolkitlist â toolkitlist on ''xed''' 'â' âEA 'toolkitlist â toolkitlist on ''xeda''' 'â' âEA 'toolkitlist â toolkitlist on ''cr2lf''' ârâcr2lf s âconvert CR to LF in string <s> â.k text-editing â.n fmgw â.t 2015.8.5.10.33.0 â.v 1.0 / 05aug15 râs r[(s = âUCS 13)/(â³â´s)]âgânl â âdel âdescribe 'del' editor usage â.k text-editing â.n fmgw â.t 2015.8.5.10.33.0 â.v 1.0 / 05aug15 'Enter: explain ''del''' 'for a brief explanation of the â editor and its use with GNU APL.' â howcr2lfâ'DOS (and APL2) used ASCII CR (carrier return, 13)' howcr2lfâhowcr2lf, ' to separate lines.', gânl howcr2lfâhowcr2lf, 'Linux (GNU APL) uses ASCII LF (line feed, 10)' howcr2lfâhowcr2lf, ' for this function.', gânl howcr2lfâhowcr2lf, 'cr2lf converts any CR characters in a string' howcr2lfâhowcr2lf, ' to LF characters.' howdelâ'Help for GNU APL built-in del (â) editor', gânl, gânl howdelâhowdel, 'âFUN open function FUN', gânl howdelâhowdel, 'âFUN[â] open with command, â and â not' howdelâhowdel, ' allowed', gânl howdelâhowdel, 'âFUN[â]â open, list, close', gânl, gânl howdelâhowdel, 'â close', gânl howdelâhowdel, 'â« close and lock', gânl, gânl howdelâhowdel, '[â] show [â] [nâ] [âm] [nâm] [ân-m]' howdelâhowdel, gânl howdelâhowdel, '[â] delete [nâ] [âm] [nâm] [ân-m]' howdelâhowdel, ' [ân1 n2 ...]', gânl howdelâhowdel, '[â] escape (clear definition, keep' howdelâhowdel, ' header)', gânl howdelâhowdel, '[n] goto', gânl howdelâhowdel, '[n] text replace existing text on line n' howdelâhowdel, gânl howdelâhowdel, ' text replace existing text', gânl, gânl howdelâhowdel, 'After opening function, up and down arrows will' howdelâhowdel, ' retrieve function', gânl howdelâhowdel, '^K - kill to end of line, ^Y yank, ^A/^E, ^N/^P (can' howdelâhowdel, ' retrieve input', gânl howdelâhowdel, 'line, ^K, define a function, then ^Y).' howxedâ'xed ''function''. Edits function by calling out to an external' howxedâhowxed, ' editor.', gânl howxedâhowxed, 'Uses globals gânl, gâtmp, gâeditor and gâterminal.' howxedaâ'r â xed a. Edits array by calling out to an external' howxedaâhowxeda, ' editor.', gânl howxedaâhowxeda, 'Uses globals gânl, gâtmp and gâeditorcsv.' âxed f;fn;s;r;cmd;h;n;q;âIO âedit function <f> with external editor â.k text-editing â.n fmgw â.t 2015.8.5.11.0.0 â.v 1.0 /05aug15 âIO â 1 q â '"' â â Convert function to del edit sequence, with lines separated â by unix newlines. â s â âCR f s â ,(' ', s[â³(â´s)[1];], gânl) s[1] â 'â' s â s, 'â' â â Write out character string representing function to ./function.APL â file. Prepend line to indicate that this is a "dump" format. â fn â gâtmp, f, '.APL' h â 'w' FIOâfopen fn n â ('#!/usr/local/bin/apl --script', gânl) FIOâfwrite_utf8 h n â s FIOâfwrite_utf8 h r â FIOâfclose h â â Call external editor on file. Use terminal because APL messes with â terminal control. â cmd â gâterminal, q, gâeditor, fn, q r â â')host ', cmd â â No convenient way to read utf-8 string. Could read file as byte â vector and then use âCR to convert... but, easier to "dress up" the â function as a del editor definition, and use ")copy" to bring it back â in. Note that we add the directory to fn, to allow this to work in â other than workspaces/. â r â â')copy ', fn â â We could erase the external edit file, and backup. Keep these around â for now. The new function is in ./fn.APL, the original in â ./fn.APL.bak â â r â â')host rm ', fn, ' ', fn, '.bak' â âra â xeda a;fn;s;cmd;h;n;âIO âedit array <a> with external editor â.k text-editing â.n fmgw â.t 2015.8.7.20.40.0 â.v 1.0 / 07aug15 âIO â 1 â â Convert array to edit sequence, with lines separated â by unix newlines. â s â ',' makeâcsv a s â ,(s[â³(â´s)[1];], gânl) â â Write out character string representing array to ./ARRAY.csv â file. â fn â gâtmp, 'ARRAY.csv' h â 'w' FIOâfopen fn n â s FIOâfwrite_utf8 h r â FIOâfclose h â â Call external editor on file. Doesn't use a terminal, because CSV â editor is a GUI application. â cmd â gâeditorcsv, fn r â â')host ', cmd â â Read in resulting CSV file. â ra â ',' readâcsvfile fn â â We could erase the external edit file, and backup. â â r â â')host rm ', fn, ' ', fn, '.bak' â