Skip to content
Browse files

merging bills changes

  • Loading branch information...
2 parents 361a609 + 46c7e64 commit 39c6bdeda7189c245350094c22b2700e018939fd @mdykman committed Nov 19, 2012
Showing with 16,794 additions and 487 deletions.
  1. +11 −2 AndroidManifest.xml
  2. +120 −0 assets/addons/api/expat/expat.ijs
  3. +4 −0 assets/addons/api/expat/history.txt
  4. +16 −0 assets/addons/api/expat/manifest.ijs
  5. +3 −0 assets/addons/api/jni/history.txt
  6. +22 −0 assets/addons/api/jni/jni.ijs
  7. +5 −5 assets/addons/data/ddsqlite/ddsqlite.ijs
  8. +3 −0 assets/addons/data/ddsqlite/history.txt
  9. BIN assets/addons/data/ddsqlite/lib/sqlite3.dll
  10. +1 −1 assets/addons/data/ddsqlite/manifest.ijs
  11. BIN assets/addons/data/sqlite/lib/sqlite3.dll
  12. BIN assets/addons/data/sqlite/lib/sqlite3_64.dll
  13. +398 −0 assets/addons/general/misc/bigfiles.ijs
  14. +338 −0 assets/addons/general/misc/clippaste.ijs
  15. +16 −0 assets/addons/general/misc/evolute.ijs
  16. +132 −0 assets/addons/general/misc/fndef.ijs
  17. +125 −0 assets/addons/general/misc/fndisplay.ijs
  18. +67 −0 assets/addons/general/misc/font.ijs
  19. +301 −0 assets/addons/general/misc/format.ijs
  20. +48 −0 assets/addons/general/misc/guid.ijs
  21. +34 −0 assets/addons/general/misc/inverted.ijs
  22. +143 −0 assets/addons/general/misc/numeric.ijs
  23. +95 −0 assets/addons/general/misc/pack.ijs
  24. +90 −0 assets/addons/general/misc/parts.ijs
  25. +26 −0 assets/addons/general/misc/test_bigfiles.ijs
  26. +49 −0 assets/addons/general/misc/test_clippaste.ijs
  27. +217 −0 assets/addons/general/misc/trace.ijs
  28. +68 −0 assets/addons/general/misc/validate.ijs
  29. +1 −1 assets/addons/graphics/plot/history.txt
  30. +1 −1 assets/addons/graphics/plot/jzplot.ijs
  31. +1 −1 assets/addons/graphics/plot/manifest.ijs
  32. +3,251 −9 assets/addons/gui/android/android.ijs
  33. +6 −0 assets/addons/gui/android/history.txt
  34. +3 −3 assets/addons/gui/android/manifest.ijs
  35. +3,396 −0 assets/addons/gui/droidwd/droidwd.ijs
  36. +4 −0 assets/addons/gui/droidwd/history.txt
  37. +106 −0 assets/addons/gui/droidwd/isigraph.ijs
  38. +342 −0 assets/addons/gui/droidwd/jview.ijs
  39. +31 −0 assets/addons/gui/droidwd/manifest.ijs
  40. +142 −0 assets/addons/gui/droidwd/view2.ijs
  41. +80 −0 assets/addons/gui/droidwd/vkeys.ijs
  42. +505 −0 assets/addons/gui/droidwd/wdviewmat.ijs
  43. +18 −11 assets/addons/ide/jhs/jfif.ijs
  44. +6 −1 assets/addons/ide/jhs/jfile.ijs
  45. +37 −0 assets/addons/ide/jhs/jhelp.ijs
  46. +57 −26 assets/addons/ide/jhs/jijs.ijs
  47. +228 −0 assets/addons/ide/jhs/jijsta.ijs
  48. +173 −0 assets/addons/ide/jhs/js/codemirror/codemirror.css
  49. +3,143 −0 assets/addons/ide/jhs/js/codemirror/codemirror.js
  50. +95 −0 assets/addons/ide/jhs/js/codemirror/j/j.js
  51. +8 −0 assets/addons/ide/jhs/js/codemirror/j/jtheme.css
  52. +6 −1 assets/addons/ide/jhs/manifest.ijs
  53. +162 −0 assets/addons/math/misc/amoeba.ijs
  54. +22 −0 assets/addons/math/misc/bigpi.ijs
  55. +81 −0 assets/addons/math/misc/brent.ijs
  56. +3 −0 assets/addons/math/misc/build.ijs
  57. +49 −0 assets/addons/math/misc/cheby.ijs
  58. +37 −0 assets/addons/math/misc/contfrac.ijs
  59. +16 −0 assets/addons/math/misc/det.ijs
  60. +41 −0 assets/addons/math/misc/fermat.ijs
  61. +83 −0 assets/addons/math/misc/gamesolver.ijs
  62. +28 −0 assets/addons/math/misc/gcd.ijs
  63. +10 −0 assets/addons/math/misc/history.txt
  64. +86 −0 assets/addons/math/misc/integer.ijs
  65. +103 −0 assets/addons/math/misc/integrat.ijs
  66. +77 −0 assets/addons/math/misc/jacobi.ijs
  67. +55 −0 assets/addons/math/misc/legendre.ijs
  68. +168 −0 assets/addons/math/misc/linear.ijs
  69. +92 −0 assets/addons/math/misc/makemat.ijs
  70. +52 −0 assets/addons/math/misc/matfacto.ijs
  71. +31 −0 assets/addons/math/misc/math.txt
  72. +31 −0 assets/addons/math/misc/mathutil.ijs
  73. +113 −0 assets/addons/math/misc/matutil.ijs
  74. +20 −0 assets/addons/math/misc/mean.ijs
  75. +67 −0 assets/addons/math/misc/misc.ijp
  76. +108 −0 assets/addons/math/misc/numbers.ijs
  77. +76 −0 assets/addons/math/misc/pollard.ijs
  78. +72 −0 assets/addons/math/misc/poly.ijs
  79. +131 −0 assets/addons/math/misc/primutil.ijs
  80. +82 −0 assets/addons/math/misc/quatern.ijs
  81. +51 −0 assets/addons/math/misc/rsa.ijs
  82. +122 −0 assets/addons/math/misc/simplex.ijs
  83. +302 −0 assets/addons/math/misc/simplexnr.ijs
  84. +84 −0 assets/addons/math/misc/spline.ijs
  85. +32 −0 assets/addons/math/misc/svd.ijs
  86. +56 −0 assets/addons/math/misc/trig.ijs
  87. +24 −0 assets/system/config/fkeys.cfg
  88. +32 −0 assets/system/config/gtkide.cfg
  89. +4 −2 assets/system/main/stdlib.ijs
  90. +1 −0 assets/system/util/scripts.ijs
  91. +4 −7 jni/Android.mk
  92. +8 −1 jni/Application.mk
  93. +0 −19 jni/hostdefs/Android.mk
  94. +0 −19 jni/netdefs/Android.mk
  95. +1 −1 jni/pcre-8.21/README
  96. +0 −347 jni/pcre-8.21/config.h.android
  97. +1 −0 res/layout/main.xml
  98. +1 −0 res/values/colors.xml
  99. +1 −1 res/values/strings.xml
  100. +11 −14 res/xml/num.xml
  101. +2 −2 src/org/dykman/j/JInterface.java
  102. +6 −4 src/org/dykman/j/android/AbstractActivity.java
  103. +4 −1 src/org/dykman/j/android/Console.java
  104. +32 −7 src/org/dykman/j/android/JConsoleApp.java
  105. +27 −0 src/org/dykman/j/android/SoftKeyboard.java
  106. +10 −0 src/org/dykman/jn/android/view/MenuItem$OnMenuItemClickListener.java
  107. +10 −0 src/org/dykman/jn/android/view/MenuItem$OnMenuItemClickListener2.java
  108. +10 −0 src/org/dykman/jn/android/view/View$OnClickListener2.java
  109. +10 −0 src/org/dykman/jn/android/view/View$OnCreateContextMenuListener.java
  110. +10 −0 src/org/dykman/jn/android/view/View$OnFocusChangeListener.java
  111. +10 −0 src/org/dykman/jn/android/view/View$OnKeyListener.java
  112. +10 −0 src/org/dykman/jn/android/view/View$OnLongClickListener.java
  113. +19 −0 src/org/dykman/jn/android/widget/AbsoluteLayout.java
  114. +10 −0 src/org/dykman/jn/android/widget/AdapterView$OnItemClickListener.java
  115. +10 −0 src/org/dykman/jn/android/widget/AdapterView$OnItemLongClickListener.java
  116. +11 −0 src/org/dykman/jn/android/widget/AdapterView$OnItemSelectedListener.java
View
13 AndroidManifest.xml
@@ -1,10 +1,19 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.dykman.j.android"
android:versionCode="1"
- android:versionName="1.0.5" >
+ android:versionName="1.0.6" >
+
+ <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="7" />
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
+ <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
+
+ <uses-permission android:name="android.permission.BIND_APPWIDGET"/>
+
+ <uses-permission android:name="android.permission.BROADCAST_SMS"/>
- <uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"/>
+
<uses-permission android:name="android.permission.PERSISTENT_ACTIVITY"/>
<uses-permission android:name="android.permission.BIND_INPUT_METHOD"/>
<uses-permission android:name="android.permission.READ_INPUT_STATE"/>
View
120 assets/addons/api/expat/expat.ijs
@@ -0,0 +1,120 @@
+coclass 'jexpat'
+
+SZI=: IF64{4 8
+expat_characterData=: ''
+
+3 : 0''
+if. UNAME-:'Linux' do.
+ LIB=: 'libexpat.so.1'
+elseif. UNAME-:'Android' do.
+ LIB=: 'libexpat.so'
+elseif. UNAME-:'Darwin' do.
+ if. -.fexist LIB=: '/usr/lib/libexpat.dylib' do.
+ LIB=: 'libexpat.dylib'
+ end.
+elseif. UNAME-:'Win' do.
+ if. fexist f=. jpath '~install/gtk/bin/libexpat-1.dll' do.
+ LIB=: '"', '"',~ f
+ else.
+ LIB=: 'libexpat-1.dll'
+ end.
+end.
+)
+
+XML_ErrorString=: (LIB, ' XML_ErrorString >', (IFWIN#' +'), ' x x')&(15!:0)
+XML_GetCurrentColumnNumber=: (LIB, ' XML_GetCurrentColumnNumber >', (IFWIN#' +'), ' i x')&(15!:0)
+XML_GetCurrentLineNumber=: (LIB, ' XML_GetCurrentLineNumber >', (IFWIN#' +'), ' i x')&(15!:0)
+XML_GetErrorCode=: (LIB, ' XML_GetErrorCode >', (IFWIN#' +'), ' i x')&(15!:0)
+XML_Parse=: (LIB, ' XML_Parse >', (IFWIN#' +'), ' i x *c i i')&(15!:0)
+XML_ParserCreate=: (LIB,' XML_ParserCreate >', (IFWIN#' +'), ' x *c')&(15!:0)
+XML_ParserFree=: (LIB, ' XML_ParserFree >', (IFWIN#' +'), ' n x')&(15!:0)
+XML_SetCharacterDataHandler=: (LIB, ' XML_SetCharacterDataHandler >', (IFWIN#' +'), ' n x x')&(15!:0)
+XML_SetElementHandler=: (LIB, ' XML_SetElementHandler >', (IFWIN#' +'), ' n x x x')&(15!:0)
+XML_StopParser=: (LIB, ' XML_StopParser >', (IFWIN#' +'), ' i x i')&(15!:0)
+
+XML_FALSE=: 0
+XML_TRUE=: 1
+
+XML_STATUS_OK=: 1
+XML_STATUS_ERROR=: 0
+XML_STATUS_SUSPENDED=: 2
+expat_initx=: 0:
+expat_start_elementx=: 0:
+expat_end_elementx=: 0:
+expat_parse_xmlx=: 3 : ' 0;'''';'''' '
+expat_parse_xml=: 3 : 0
+'' expat_parse_xml y
+:
+expat_init x
+parser=. XML_ParserCreate <<0
+f=. [: 15!:13 (IFWIN#'+') , ' x' $~ +:@>:
+XML_SetElementHandler parser, (f 3), (f 2)
+XML_SetCharacterDataHandler parser, (f 4)
+
+if. XML_STATUS_ERROR = XML_Parse parser; y; (PARLEN=: #y); XML_TRUE do.
+ err=. memr 0 _1 2,~ XML_ErrorString XML_GetErrorCode parser
+ lncol=. (XML_GetCurrentLineNumber parser), XML_GetCurrentColumnNumber parser
+ XML_ParserFree parser
+ _1;err;lncol return.
+end.
+
+XML_ParserFree parser
+expat_parse_xmlx''
+)
+expat_init=: 3 : 0
+expat_characterData=: ''
+expat_initx y
+EMPTY
+)
+expat_start_element=: 3 : 0
+'data element attribute'=. y
+expat_characterData=: ''
+elm=. evalbs memr 0 _1 2,~ element
+att=. val=. 0$<''
+i=. 0
+while. pa1=. {.memr 0 1 4,~ attribute+SZI*i do.
+ pa2=. {.memr 0 1 4,~ attribute+SZI*i+1
+ att=. att, <evalbs memr 0 _1 2,~ pa1
+ val=. val, <evalbs memr 0 _1 2,~ pa2
+ i=. 2+i
+end.
+y expat_start_elementx~ elm;att;<val
+EMPTY
+)
+
+expat_end_element=: 3 : 0
+'data element'=. y
+expat_characterData=: evalbs dltb (LF,' ',TAB,' ') charsub expat_characterData
+expat_end_elementx y
+expat_characterData=: ''
+EMPTY
+)
+cdcallback=: 3 : 0
+y=. 15!:17''
+if. 3=#y do. expat_start_element y
+elseif. 2=#y do. expat_end_element y
+elseif. 4=#y do. expat_char_data 3{.y
+end.
+)
+expat_char_data=: 3 : 0
+'data s len'=. y
+expat_characterData=: expat_characterData, memr s,0,len,2
+EMPTY
+)
+
+subst2=: (_2<\'\"\\\/\b\f\n\r\t')&(i.{(34 92 47 8 12 10 13 9{&.><a.),])"0
+hexchars=. 'ABCDEF0123456789abcdef'
+dfh=: 16 #. 16 | _6 + hexchars i. ]
+subst6=: (8 u:[:u:@dfh 2}.]) ::]^:(6&=@#*.('\'={.)*.'uU'e.~{.@}.)&.>
+
+splitbs=: (0;(0 10#:10*".;._2]0 :0);(a.e.hexchars)+(2*a.='\')+3*a.e.'Uu')&;:
+ 1.1 1.1 2.1 1.1
+ 1.0 1.0 2.2 1.0
+ 3.0 3.0 3.0 4.0
+ 1.2 1.2 2.2 1.2
+ 1.2 5.0 2.2 1.2
+ 1.2 6.0 2.2 1.2
+ 1.2 7.0 2.2 1.2
+ 1.2 3.0 2.2 1.2
+)
+evalbs=: [:; [:subst2 [:subst6 splitbs^:(*@#)
View
4 assets/addons/api/expat/history.txt
@@ -0,0 +1,4 @@
+api/expat - change history
+
+== 1.0.0 ==
+ * initial import
View
16 assets/addons/api/expat/manifest.ijs
@@ -0,0 +1,16 @@
+NB. api/expat manifest
+
+CAPTION=: 'libexpat'
+
+DESCRIPTION=: 0 : 0
+libexpat interface
+)
+
+VERSION=: '1.0.0'
+
+RELEASE=: 'j701'
+
+FILES=: 0 : 0
+history.txt
+expat.ijs
+)
View
3 assets/addons/api/jni/history.txt
@@ -5,3 +5,6 @@ api/jni - change history
== 1.0.1 ==
* tidy up
+
+== 1.0.2 ==
+ * add verbs
View
22 assets/addons/api/jni/jni.ijs
@@ -501,6 +501,28 @@ z=. memr str,0,_1
jniCheck ReleaseStringUTFChars y;<<str
z
)
+jniFromObjarr=: 3 : 0
+jniCheck GetObjectArrayElement"1 y;"0 i. GetArrayLength <y
+)
+jniToObjarr=: 3 : 0
+clz=. FindClass <'java/lang/Object'
+z=. jniCheck NewObjectArray (#y);clz;0
+jniCheck DeleteLocalRef <clz
+for_i. i.#y do.
+ jniCheck SetObjectArrayElement z;i;i{y
+end.
+z
+)
+jniToStringarr=: 3 : 0
+clz=. FindClass <'java/lang/String'
+z=. jniCheck NewObjectArray (#y);clz;0
+jniCheck DeleteLocalRef <clz
+for_i. i.#y do.
+ jniCheck SetObjectArrayElement z;i;s=. NewStringUTF i{y
+ jniCheck DeleteLocalRef <s
+end.
+z
+)
jniException=: 3 : 0
try.
ExceptionClear''
View
10 assets/addons/data/ddsqlite/ddsqlite.ijs
@@ -733,7 +733,7 @@ r=. (r<0){r,_1
if. 0=#ci=. getallcolinfo sh do.
errret sh_to_ch sh
else.
- z=. ci getdata sh,r
+ z=. ci getdata sh,r,1
if. UseErrRet do.
if. (<<<0)-:{.z do.
r=. fmtfch&.>^:(_2~:x) }.z
@@ -757,7 +757,7 @@ r=. (r<0){r,_1
if. 0=#ci=. getallcolinfo sh do.
errret sh_to_ch sh
else.
- z=. ci getdata sh,r
+ z=. ci getdata sh,r,0
if. UseErrRet do.
if. (<<<0)-:{.z do.
r=. }.z
@@ -1364,7 +1364,7 @@ else.
end.
)
getdata=: 4 : 0
-'sh r'=. y
+'sh r ignorelongdata'=. 3{.y
assert. 15={:$x
oty=. ; 8 {"1 x
ln=. ; 9 {"1 x
@@ -1412,9 +1412,9 @@ while.do.
elseif. (SQL_CHAR,SQL_WCHAR,SQL_VARCHAR,SQL_WVARCHAR) e.~ i{ty do.
(pref,":i)=. (pref,":i)~, datchar i{cc
elseif. (SQL_LONGVARCHAR,SQL_WLONGVARCHAR) e.~ i{ty do.
- (pref,":i)=. (pref,":i)~, datchar i{cc
+ (pref,":i)=. (pref,":i)~, datchar`((<'')"_)@.ignorelongdata i{cc
elseif. SQL_LONGVARBINARY = i{ty do.
- (pref,":i)=. (pref,":i)~, datblob i{cc
+ (pref,":i)=. (pref,":i)~, datblob`((<'')"_)@.ignorelongdata i{cc
elseif. SQL_TYPE_DATE = i{ty do.
(pref,":i)=. (pref,":i)~, datdate i{cc
elseif. SQL_TYPE_TIME = i{ty do.
View
3 assets/addons/data/ddsqlite/history.txt
@@ -11,3 +11,6 @@ data/ddsqlite - change history
== 1.0.4/9 ==
* android/iOS limitation
+
+== 1.0.10 ==
+ * ddfch should coerce long data to empty
View
BIN assets/addons/data/ddsqlite/lib/sqlite3.dll
Binary file not shown.
View
2 assets/addons/data/ddsqlite/manifest.ijs
@@ -11,7 +11,7 @@ For 32-bit windows, download from http://www.sqlite.org/download.html. Binary fo
See wiki page http://www.jsoftware.com/jwiki/JDD for help.
)
-VERSION=: '1.0.9'
+VERSION=: '1.0.10'
RELEASE=: 'j602 j701'
View
BIN assets/addons/data/sqlite/lib/sqlite3.dll
Binary file not shown.
View
BIN assets/addons/data/sqlite/lib/sqlite3_64.dll
Binary file not shown.
View
398 assets/addons/general/misc/bigfiles.ijs
@@ -0,0 +1,398 @@
+NB. big file utilities
+NB.
+NB. Use Windows API for common file access verbs.
+NB. These handle files (and drives) with sizes greater than 2^31 bytes.
+NB.
+NB. They represent 64 bit integers as 2 element integer vectors.
+NB.
+NB. Indexed read and write have an optional flag indicating the use of the index.
+NB. If the flag is non-negative, the index is from the start of the file.
+NB. If the flag is negative, the index is from the end of the file.
+NB.
+NB. f can be either a text file name or a file handle (from bopen).
+NB.
+NB. bytes written=.data bappend f append to end
+NB. data=.bixread f;start0,start1[,len[,dirflag]] indexed read
+NB. bytes written=.data bixwrite f;start0,start1[,dirflag] indexed write
+NB. free space=.bdiskfreespaceex dir get disk free space
+NB. free space=.bdiskfreespace drive root get disk free space (device units)
+NB. size=.bfsize f get file size
+NB. fh=.[mode] bopen filename open file input or inout
+NB. success=.bclose fh close open file
+NB. sys_drives=.getdrives '' return vector of windows drive letters
+NB. sys_drive_free_space=.getdrivespace '' return matrix of drive letters
+NB. are_same=.f1 bfcomp f2 compare 2 files
+NB.
+NB. Contributed by David Mitchell in J Forum posting April 2003.
+
+require 'dll'
+
+coclass 'jbf'
+
+jsystemdefs 'hostdefs'
+
+coinsert 'jdefs'
+
+NB. jbf api
+
+NULLPTR=: <0
+NULL=: <<0
+K32=: 2^32
+K31=: 2^31
+
+CREATE_ALWAYS=: 2
+CREATE_NEW=: 1
+FALSE=: 0
+FILE_BEGIN=: 0
+FILE_END=: 2
+GENERIC_READ=: _2147483648
+GENERIC_WRITE=: 1073741824
+OPEN_ALWAYS=: 4
+OPEN_EXISTING=: 3
+TRUNCATE_EXISTING=: 5
+
+CloseHandleR=: >@{.@('kernel32 CloseHandle i i'&(15!:0))
+CreateFileR=: >@{.@('kernel32 CreateFileW i *w i i * i i i'&(15!:0))
+GetFileSizeR=: >@{.@('kernel32 GetFileSize i i *i'&(15!:0))
+SetEndOfFile=: >@{.@('kernel32 SetEndOfFile i i'&(15!:0))
+SetFilePointerR=: >@{.@('kernel32 SetFilePointer i i i *i i'&(15!:0))
+WriteFile=: 'kernel32 WriteFile i i * i *i *'&(15!:0)
+ReadFile=: 'kernel32 ReadFile i i * i *i *'&(15!:0)
+GetDiskFreeSpaceEx=: >@{.@('kernel32 GetDiskFreeSpaceExW i *w * * *'&(15!:0))
+GetDiskFreeSpace=: >@{.@('kernel32 GetDiskFreeSpaceW i *w *i *i *i *i'&(15!:0))
+GetLogicalDrives=: >@{.@('kernel32 GetLogicalDrives i'&(15!:0))
+
+4!:55 <'t'
+t=: 2&=&(3!:0)
+
+NB. =========================================================
+NB.*bappend v append to end
+NB. form: data bappend f
+bappend=: 4 : 0
+x=. ,x
+'character data only!' assert t x
+if. t y do.
+ try. fh=. CreateFileR (uucp y,{.a.);(GENERIC_WRITE+GENERIC_READ);0;NULLPTR;OPEN_EXISTING;0;0 catch.
+ (13!:11 '');(13!:12 '')
+ return.
+ end.
+ if. fh=_1 do.
+ cderx''
+ return.
+ end.
+ F=. 1
+else.
+ fh=. y
+ F=. 0
+end.
+p0=. ,2-2
+try. r=. SetFilePointerR fh;0;p0;FILE_END catch.
+ r=. (13!:11 '');(13!:12 '')
+ if. F do. CloseHandleR fh end.
+ r
+ return.
+end.
+bw=. ,2
+try. r=. WriteFile fh;x;(#x);bw;NULL catch.
+ r=. (13!:11 '');(13!:12 '')
+ if. F do. CloseHandleR fh end.
+ r
+ return.
+end.
+if. ({.r)=0 do.
+ r=. cderx''
+ if. F do. CloseHandleR fh end.
+ r
+ return.
+end.
+if. F do. CloseHandleR fh end.
+bw
+)
+
+NB. =========================================================
+NB.*bixread v indexed read
+NB. form: bixread f;start0,start1[,len[,dirflag]]
+bixread=: 3 : 0
+'fn st'=. y
+'invalid index' assert (#st)e. 2 3 4
+st=. 4{.st
+if. t fn do.
+ try. fh=. CreateFileR (uucp fn,{.a.);GENERIC_READ;0;NULLPTR;OPEN_EXISTING;0;0 catch.
+ (13!:11 '');(13!:12 '')
+ return.
+ end.
+ if. fh=_1 do.
+ cderx''
+ return.
+ end.
+ F=. 1
+else.
+ fh=. fn
+ F=. 0
+end.
+if. (0>3{st) do.
+ b=. ,2
+ ts=. GetFileSizeR fh;b
+ b=. K32#.|:K32&|b,ts
+ ts=. K32#.|:K32&|2{.st
+ q=. (2$K32)#:b-ts
+ q=. <.((q>K31)*-K32)+q
+ st=. q 0 1}st
+end.
+if. (0=2{st) do.
+ b=. ,2
+ ts=. GetFileSizeR fh;b
+ b=. K32#.|:K32&|b,ts
+ ts=. K32#.|:K32&|2{.st
+ st=. (<.b-ts) 2 }st
+end.
+p0=. ,{.st
+try. r=. SetFilePointerR fh;(1{st);p0;FILE_BEGIN catch.
+ r=. (13!:11 '');(13!:12 '')
+ if. F do. CloseHandleR fh end.
+ r
+ return.
+end.
+br=. ,2
+try. r=. ReadFile fh;((2{st)#' ');(2{st);br;NULL catch.
+ r=. (13!:11 '');(13!:12 '')
+ if. F do. CloseHandleR fh end.
+ r
+ return.
+end.
+if. ({.r)=0 do.
+ r=. cderx''
+ if. F do. CloseHandleR fh end.
+ r
+ return.
+end.
+if. F do. CloseHandleR fh end.
+br{.>2{r
+)
+
+NB. =========================================================
+NB.*bixwrite v indexed write
+NB. form: data bixwrite f;start0,start1[,dirflag]
+NB. returns bytes written
+bixwrite=: 4 : 0
+x=. ,x
+'fn st'=. y
+'invalid index' assert (#st)e. 2 3
+'character data only!' assert t x
+st=. 3{.st
+if. t fn do.
+ try. fh=. CreateFileR (uucp fn,{.a.);(GENERIC_READ+GENERIC_WRITE);0;NULLPTR;OPEN_EXISTING;0;0 catch.
+ (13!:11 '');(13!:12 '')
+ return.
+ end.
+ if. fh=_1 do.
+ cderx''
+ return.
+ end.
+ F=. 1
+else.
+ fh=. fn
+ F=. 0
+end.
+if. (0>2{st) do.
+ b=. ,2
+ ts=. GetFileSizeR fh;b
+ b=. K32#.|:K32&|b,ts
+ ts=. K32#.|:K32&|2{.st
+ q=. b64to32 b-ts
+ st=. q 0 1}st
+end.
+p0=. ,{.st
+try. r=. SetFilePointerR fh;(1{st);p0;FILE_BEGIN catch.
+ r=. (13!:11 '');(13!:12 '')
+ if. F do. CloseHandleR fh end.
+ r
+ return.
+end.
+bw=. ,2
+try. r=. WriteFile fh;x;(#x);bw;NULL catch.
+ r=. (13!:11 '');(13!:12 '')
+ if. F do. CloseHandleR fh end.
+ r
+ return.
+end.
+if. ({.r)=0 do.
+ r=. cderx''
+ if. F do. CloseHandleR fh end.
+ r
+ return.
+end.
+if. F do. CloseHandleR fh end.
+bw
+)
+
+NB. =========================================================
+NB.*bdiskfreespaceex v return extended disk free space
+NB. form: [flag] bdiskfreespaceex dir
+NB. if flag=0 returns 3x2 matrix of integers, representing 3 64 bit values.
+NB. if flag=1 returns 3 element vector of floats, representing 64 bit values.
+NB. FreeBytesAvailable,TotalNumberOfBytes,TotalNumberOfFreeBytes
+NB. See MS SDK for more information.
+bdiskfreespaceex=: 3 : 0
+0 bdiskfreespaceex y
+:
+s1=. 2,2
+s2=. 2,2
+s3=. 2,2
+try. r=: GetDiskFreeSpaceEx (uucp y,{.a.);s1;s2;s3 catch.
+ (13!:11 '');(13!:12 '')
+ return.
+end.
+if. r=0 do.
+ cderx''
+ return.
+end.
+if. x do. K32#.|:K32&||.s1,.s2,.s3 else. |:|.s1,.s2,.s3 end.
+)
+
+
+NB. =========================================================
+NB.*bdiskfreespace v return disk free space
+NB. form: bdiskfreespace drive root (must be similar to 'c:\')
+NB. returns 4 elements: SectorsPerCluster,BytesPerSector,NumberOfFreeClusters,TotalNumberOfClusters
+bdiskfreespace=: 3 : 0
+s1=. ,2
+s2=. ,2
+s3=. ,3
+s4=. ,2
+try. r=: GetDiskFreeSpace (uucp y,{.a.);s1;s2;s3;s4 catch.
+ (13!:11 '');(13!:12 '')
+ return.
+end.
+if. r=0 do.
+ cderx''
+ return.
+end.
+s1,s2,s3,s4
+)
+
+NB. =========================================================
+NB.*bfsize v return size of file
+NB. form: bfsize f
+NB. returns 2 integer vector
+bfsize=: 3 : 0
+if. t y do.
+ try. fh=: CreateFileR (uucp y,{.a.);GENERIC_READ;0;NULLPTR;OPEN_EXISTING;0;0 catch.
+ (13!:11 '');(13!:12 '')
+ return.
+ end.
+ if. fh=_1 do.
+ cderx''
+ return.
+ end.
+ F=. 1
+else.
+ fh=. y
+ F=. 0
+end.
+b=. ,2
+ts=. GetFileSizeR fh;b
+if. F do. CloseHandleR fh end.
+NB. K32#.|:K32&|b,ts
+b,ts
+)
+
+
+NB. =========================================================
+NB.*bopen v open file read or readwrite
+NB. form: [mode] bopen filename
+NB. returns file handle
+NB. mode is 0 for read, 1 for readwrite, default read
+bopen=: 3 : 0
+0 bopen y
+:
+mode=. x{GENERIC_READ,GENERIC_WRITE+GENERIC_READ
+try. fh=: CreateFileR (uucp y,{.a.);mode;0;NULLPTR;OPEN_EXISTING;0;0 catch.
+ (13!:11 '');(13!:12 '')
+ return.
+end.
+if. fh=_1 do.
+ cderx''
+ return.
+end.
+fh
+)
+
+NB. =========================================================
+NB.*bclose v close open file handle
+NB. form: bclose fh
+NB. returns 1 if successful, 0 if not
+bclose=: 3 : 0
+CloseHandleR y
+)
+
+NB. =========================================================
+NB.*getdrives v get system drive letters
+NB. form: getdrives ''
+NB. returns drive letter vector if successful, error if not
+getdrives=: 3 : 0
+x=. GetLogicalDrives''
+if. x=0 do.
+ cderx''
+ return.
+end.
+|.(_26{.(32$2)#:x)#'zyxwvutsrqponmlkjihgfedcba'
+)
+
+
+NB. =========================================================
+NB.*getdrivespace v get system drive letters and free space
+NB. form: getdrivespace ''
+NB. returns nx2 drive letter, space available if successful, '' if not
+getdrivespace=: 3 : 0
+x=. getdrives''
+if. -.t x do.
+ x
+ return.
+end.
+x=. x,"0 1 ':\'
+(<"1 x),.<"0 {."1 diskfree"1 x
+)
+
+
+diskfree=: 3 : 0
+x=. 1 bdiskfreespaceex y
+if. 2=#x do. x=. 0 0 0 end.
+x
+)
+
+b64to32=: 3 : 0
+y=. (2$K32)#:y
+<.((y>K31)*-K32)+y
+)
+
+NB. =========================================================
+NB.*bfcomp v compare 2 big files
+NB. form: f1 bfcomp f2
+NB. returns 0 if different 1 if same
+bfcomp=: 4 : 0
+h1=. bopen x
+h2=. bopen y
+s1=. bfsize h1
+s2=. bfsize h2
+if. s1~:s2 do.
+ bclose h1
+ bclose h2
+ 0
+ return.
+end.
+blk=. 2048000
+for_s. i. >.s1%blk do.
+ bsize=. <.blk<.s1-(s*blk)
+ if. -.(bixread h1;(b64to32(s*blk)),bsize)-:(bixread h2;(b64to32(s*blk)),bsize) do.
+ bclose h1
+ bclose h2
+ 0
+ return.
+ end.
+ if. bsize < blk do. break. end.
+end.
+bclose h1
+bclose h2
+1
+)
View
338 assets/addons/general/misc/clippaste.ijs
@@ -0,0 +1,338 @@
+NB. cd replacement for wd'clippaste'
+NB.
+NB. wd'clippaste 1' -> getcliptext''
+NB. wd'clippaste 2' -> getclipfiles''
+NB. wd'clipcopy' -> setcliptext text
+NB.
+NB. getclip - gets text or file names from clipboard.
+NB. setclipfiles - puts one or more file names on clipboard.
+NB.
+
+coclass 'wdclip'
+require '~addons/general/misc/format.ijs'
+
+getcliptext_z_=: getcliptext_wdclip_
+getclipfiles_z_=: getclipfiles_wdclip_
+getclip_z_=: getclip_wdclip_
+setcliptext_z_=: setcliptext_wdclip_
+setclipfiles_z_=: setclipfiles_wdclip_
+
+OpenClipboard=: >@{.@:('user32 OpenClipboard i x'&cd)
+EmptyClipboard=: >@{.@:('user32 EmptyClipboard i'&cd)
+SetClipboardData=: >@{.@:('user32 SetClipboardData x i x'&cd)
+CloseClipboard=: >@{.@:('user32 CloseClipboard i'&cd)
+EnumClipboardFormats=: 0 1&{('user32 EnumClipboardFormats i i'&cd)
+CountClipboardFormats=: >@{.@:('user32 CountClipboardFormats i'&cd)
+GetClipboardData=: 0 1&{('user32 GetClipboardData x i'&cd)
+GetClipboardFormatName=: >@{.@:('user32 GetClipboardFormatNameA i i *c i'&cd)
+GetClipboardSequenceNumber=: >@{.@:('user32 GetClipboardSequenceNumber i'&cd)
+GlobalLock=: >@{.@:('kernel32 GlobalLock x x'&cd)
+GlobalUnlock=: >@{.@:('kernel32 GlobalUnlock i x'&cd)
+GlobalAlloc=: >@{.@:('kernel32 GlobalAlloc x i i'&cd)
+GlobalFree=: >@{.@:('kernel32 GlobalFree x x'&cd)
+GlobalReAlloc=: >@{.@:('kernel32 GlobalReAlloc x x i i'&cd)
+
+CF_HDROP=: 15
+CF_TEXT=: 2-1
+CF_OEMTEXT=: 7
+CF_UNICODETEXT=: 13
+
+GHND=: dfh'0042'
+GMEM_MODIFY=: dfh'0080'
+GMEM_MOVEABLE=: 2
+
+NULL=: 0{a.
+UNULL=: 0 0{a.
+
+ic=:3!:4
+memwic=: 4 : 0
+x=.2 ic x
+x memw y,(#x),2
+)
+
+NB. typedef struct _DROPFILES {
+NB. 4 DWORD pFiles; (12)
+NB. 8 POINT pt;
+NB. 4 BOOL fNC;
+NB. 4 BOOL fWide; } DROPFILES, *LPDROPFILES;
+NB. 20+len(files)+(#files(NULL))+2(NULL)
+
+
+NB. =========================================================
+NB.*getclipformatname v get registered clip format name from format number
+NB. form: getclipformatname n
+getclipformatname=: 3 : 0
+if. y<#ClipFormats do.
+ y{ClipFormats
+ return.
+end.
+buf=.200$' '
+c=.GetClipboardFormatName y;buf;200
+if. 0=c do.
+ 'Not a registered Clip Format Name: ',":y
+ else.
+ c{.buf
+end.
+)
+
+NB. =========================================================
+NB.*setcliptext v set clipboard to text string
+NB. form: setcliptext t
+setcliptext=: 3 : 0
+y=.clipfmt y
+drop=.GlobalAlloc GHND;1+#y
+if. 0=drop do. '' return. end.
+r=.GlobalLock drop
+(y,NULL) memw r,0,(1+#y),2
+GlobalUnlock drop
+if. 0=OpenClipboard 0 do.
+ GlobalFree drop
+ ''
+ return.
+end.
+EmptyClipboard''
+r=.SetClipboardData CF_TEXT;drop
+CloseClipboard ''
+if. 0=r do.
+ GlobalFree drop
+ ''
+ return.
+end.
+r
+)
+
+NB. =========================================================
+NB.*setclipfiles v set clipboard to list of one or more file names, boxed
+NB. form: setclipfiles f0[;fn]
+setclipfiles=: 3 : 0
+NB. 20 fixed header
+NB. Unicode bytes for text+UNULL
+NB. Unicode NULLS, 2 at end.
+NB. Pad to 8 or 16 byte boundary
+mk=.IF64{8 16
+n=.((mk&-@(mk&|))+])20+(2*+/;(>:@#)&.>y)+4
+drop=.GlobalAlloc GHND;n
+if. 0=drop do. '' return. end.
+r=.GlobalLock drop
+20 memwic r,0
+0 0 memwic r,4
+0 1 memwic r,12
+i=.20
+for_s. y do.
+ s=.(a.{~,|."1]256 256#:3 u: >s),UNULL
+ s memw r,i,(#s),2
+ i=.i+#s
+end.
+(2#UNULL) memw r,i,4,2
+GlobalUnlock drop
+if. 0=OpenClipboard 0 do.
+ GlobalFree drop
+ ''
+ return.
+end.
+EmptyClipboard''
+r=.SetClipboardData CF_HDROP;drop
+CloseClipboard ''
+if. 0=r do.
+ GlobalFree drop
+ ''
+ return.
+end.
+r
+)
+
+tst=: 3 : 0
+setclipfiles'c:\this';'c:\is';'c:\a';'c:\tst'
+)
+
+NB. =========================================================
+NB.*listclipformatnames v list clipboard formats by name
+NB. form: listclipformatnames ''
+listclipformatnames=: 3 : 0
+getclipformatname"0 listclipformats ''
+)
+
+NB. =========================================================
+NB.*listclipformats v list clipboard formats
+NB. form: listclipformats ''
+listclipformats=: 3 : 0
+if. 0=OpenClipboard 0 do. 0 return. end.
+r=.''
+f=.0
+while. 1 do.
+'f q'=.EnumClipboardFormats f
+if. 0=f do. break. end.
+r=.r,f
+end.
+CloseClipboard ''
+r
+)
+
+NB. =========================================================
+NB.*unicopy v make unicode noun from ptr,disp
+NB. form: unicopy ptr,disp
+unicopy=: 3 : 0
+r=.''
+while. 1 do.
+q=.memr y,2,2
+if. q-: UNULL do.
+ y;6 u: r
+ return.
+end.
+r=.r,q
+y=.y+0 2
+end.
+)
+
+NB. =========================================================
+NB.*droplist v return boxed list of names from drop list
+NB. form: droplist ptr
+droplist=: 3 : 0
+r=.''
+d=.y,256 256#. |.a.i. memr y,0,2,2
+while. 1 do.
+ 'd t'=.unicopy d
+ if. 0=#t do. r return. end.
+ r=.r,<t
+ d=.d+0 2
+end.
+)
+
+NB. =========================================================
+NB.*getclipdropinfo v display drop info
+NB. form: getclipdropinfo ''
+getclipdropinfo=: 3 : 0
+if. 0=OpenClipboard 0 do. 0 return. end.
+'m t'=.GetClipboardData CF_HDROP
+if. m=0 do.
+ CloseClipboard ''
+ 0
+ return.
+end.
+p=.GlobalLock m
+if. p do.
+ r=.droplist p
+ GlobalUnlock m
+end.
+CloseClipboard ''
+r
+)
+
+NB. =========================================================
+NB.*getclipfiles v get copied file names as enclosed vector
+NB. form: getclipfiles ''
+getclipfiles=: 3 : 0
+q=.getclipdropinfo ''
+if. q=0 do. return. end.
+q
+)
+
+NB. =========================================================
+NB.*getcliptext v display text
+NB. form: getcliptext ''
+getcliptext=: 3 : 0
+CF_TEXT getcliptext y
+:
+if. 0=OpenClipboard 0 do. 0 return. end.
+'m t'=.GetClipboardData x
+if. m=0 do.
+ CloseClipboard ''
+ 0
+ return.
+end.
+r=.''
+p=.GlobalLock m
+if. p do.
+ if. x=CF_UNICODETEXT do.
+ r=.>1{unicopy p,0
+ else.
+ r=.memr p,0,_1,2
+ end.
+ GlobalUnlock m
+end.
+CloseClipboard ''
+r
+)
+
+NB. =========================================================
+NB.*getclip v get text or files
+NB. form: getclip ''
+getclip=: 3 : 0
+q=.listclipformats''
+if. 1 e. q do. getcliptext'' return. end.
+if. 15 e. q do. getclipfiles'' return. end.
+''
+)
+
+ClipFormats=: >}:&.><;.2 ]0 : 0
+Null
+CF_TEXT
+CF_BITMAP
+CF_METAFILEPICT
+CF_SYLK
+CF_DIF
+CF_TIFF
+CF_OEMTEXT
+CF_DIB
+CF_PALETTE
+CF_PENDATA
+CF_RIFF
+CF_WAVE
+CF_UNICODETEXT
+CF_ENHMETAFILE
+CF_HDROP
+CF_LOCALE
+CF_DIBV5
+)
+
+NB. /*
+NB. * Predefined Clipboard Formats
+NB. */
+NB. #define CF_TEXT 1
+NB. #define CF_BITMAP 2
+NB. #define CF_METAFILEPICT 3
+NB. #define CF_SYLK 4
+NB. #define CF_DIF 5
+NB. #define CF_TIFF 6
+NB. #define CF_OEMTEXT 7
+NB. #define CF_DIB 8
+NB. #define CF_PALETTE 9
+NB. #define CF_PENDATA 10
+NB. #define CF_RIFF 11
+NB. #define CF_WAVE 12
+NB. #define CF_UNICODETEXT 13
+NB. #define CF_ENHMETAFILE 14
+NB. #if(WINVER >= 0x0400)
+NB. #define CF_HDROP 15
+NB. #define CF_LOCALE 16
+NB. #endif /* WINVER >= 0x0400 */
+NB. #if(WINVER >= 0x0500)
+NB. #define CF_DIBV5 17
+NB. #endif /* WINVER >= 0x0500 */
+NB.
+NB. #if(WINVER >= 0x0500)
+NB. #define CF_MAX 18
+NB. #elif(WINVER >= 0x0400)
+NB. #define CF_MAX 17
+NB. #else
+NB. #define CF_MAX 15
+NB. #endif
+NB.
+NB. #define CF_OWNERDISPLAY 0x0080
+NB. #define CF_DSPTEXT 0x0081
+NB. #define CF_DSPBITMAP 0x0082
+NB. #define CF_DSPMETAFILEPICT 0x0083
+NB. #define CF_DSPENHMETAFILE 0x008E
+NB.
+
+NB. DataObject
+NB. Shell IDList Array
+NB. DataObjectAttributes
+NB. DataObjectAttributesRequiringElevation
+NB. Shell Object Offsets
+NB. Preferred DropEffect
+NB. AsyncFlag
+NB. CF_HDROP
+NB. FileName
+NB. FileNameW
+NB. Ole Private Data
View
16 assets/addons/general/misc/evolute.ijs
@@ -0,0 +1,16 @@
+NB. evolute.ijs - evolutes
+NB.
+NB. ref: Eugene McDonnell Vector Vol 13#2
+NB.
+NB. example:
+NB. evolute 10
+
+cocurrent 'z'
+
+NB.*evolute v generate evolute
+
+e0=. }: @ (2: # >:@i.)
+e1=. <: @ +: $ _1: , ] , 1: , -
+e2=. _1 & |. @ (e0 # e1)
+
+evolute=: ,~ $ /: @ (+/\) @ e2 f.
View
132 assets/addons/general/misc/fndef.ijs
@@ -0,0 +1,132 @@
+NB. This script is to help begining users write J code
+NB. using a more literate style
+NB.
+NB. It is assumed users have stdlib.ijs available
+NB.
+NB. function 3 a synonym for verb
+
+NB. By Stitch
+NB. first first item in list
+NB. second second item from list
+NB. last last item in list
+NB. FN utility to insert x and y in a script
+NB. of conjunction for function definition
+NB. On laminates two vectors otherwise uses join
+NB. product the product of items in a list
+NB. run run a noun script
+NB. stoa script to array
+NB. sum the sum of items in a list
+NB. torow modifies a row of a table or matrix
+NB. tocol modifies a column of a table or matrix
+NB. wordsin Word formation ;:
+
+cocurrent 'z'
+
+NB. =============================================================
+NB. *function n integer 3
+function =: 3
+
+NB. =============================================================
+NB. *By v name for stitching two arrays
+By =: ,.
+
+NB. *first v name for {.
+first =: {.
+NB. *second v extracts second item from list
+second =: 1&{
+NB. *last v alternate name for {:
+last =: {:
+
+
+NB. *FN v dyadic, left argument is script, right argument character.
+NB. If right argument is a single word then it inserts a line
+NB. replacing the placeholder y as for a monadic function,
+NB. if the argument is two words it inserts lines for
+NB. placeholders x and y for a dyadic function. If the
+NB. definition permits both, monadic and dyadic forms are included.
+NB. If two arguments are supplied, the first is the left and the
+NB. second is the right. If the argument is empty no line is inserted.
+
+FN =: 4 : 0
+z =. #;: y NB. Number of arguments must be one or two
+w =: stoa x
+select. z
+case. 0 do. w
+case. 1 do.
+ if. ':' e. 0{"1 w do. 'Domain error' return.
+ else. ( y,'=.y'),w
+ end.
+case. 2 do.
+ x =. >{.;: y
+ y =. >{:;: y
+ s1 =. y,'=.y'
+ s2 =. x,'=.x'
+ if. ':' e. 0{"1 w do.
+ if. 0 = (0{"1 w) i. ':'
+ do. NB. dyadic only
+ ': ',s1,s2,}.w
+ else. NB. Ambivalent case
+ s =. s1,w NB. Monadic case
+ n =. (0{"1 s) i. ':'
+ ((n+1){.s), s1,s2,(n+1)}.s NB. Dyadic case
+ end.
+ else.
+ ': ',s1,s2,w NB. Dyadic only
+ end.
+end.
+)
+
+NB. *of c noun noun
+NB. the left argument is a name class for the item to be defined
+NB. and the right argument is the names of the verb arguments.
+NB. of is a conjunction which defines new verbs, adverbs and
+NB. conjunctions.
+
+NB. For example the following defines a function trianglearea
+
+NB. trianglearea =: function of 'base height'
+NB. 0.5 * base * height
+NB. )
+
+NB. In defining adverbs and conjunctions the usual place holders
+NB. u v m n are required.
+of =: 2 : 'm : (((0 : 0) FN n))'
+
+
+NB. *On v laminates two vectors otherwise uses join
+On =: 4 : 0
+ondim =. [: # $
+if. (1 >: ondim x) *. 1 >: ondim y
+ do. x,:y
+ else. x,y
+end.
+)
+
+NB. *product v forms product of a right numeric argument
+product =: */
+
+NB. *run v executes a noun script
+run =: 0!:1
+rund =: 0!:101
+
+NB. *stoa v argument script
+NB. stoa converts any character vector to an array using
+NB. the last item as 'fret'. The characteristic use - from
+NB. a string to array gives the name stoa
+stoa =: 3 : 0
+> < ;._2 y
+)
+
+NB. *sum v sums a right numeric argument
+sum =: +/
+
+NB. Amendment for matrices
+NB. *ToRow c data ToRow rownum matrix
+NB. *ToCol c data ToCol columnum matrix
+torow =: 2 : 'm n } y'
+tocol =: 2 : '|: m n}|: y'
+
+NB. *words v argument is string
+wordsin =: ;:
+
+cocurrent 'base'
View
125 assets/addons/general/misc/fndisplay.ijs
@@ -0,0 +1,125 @@
+NB. general/misc/fndisplay.ijs
+NB. Display hooks, forks and other syntax elements
+NB. version: 1.0.0
+NB.
+NB. This script allows you to see how hooks, forks, and other
+NB. structural elements affect the order of processing verbs.
+NB.
+NB. First, select the kind of display you want with 'setfnform'.
+NB. The operands are 'math' (display like f(x,y)), 'J' (display
+NB. like x f y), and 'Jv' (like J, but monads are followed by '_'
+NB. and dyads are preceded and followed by '_'). Example:
+NB. setfnform 'math'
+NB.
+NB. Then, define the verb-names you want to use:
+NB. defverbs 'f g h'
+NB.
+NB. Finally, define any names you want to use for nouns:
+NB. defnouns 'x y'
+NB.
+NB. Then, entering combinations of your verbs and nouns will
+NB. show you how the combinations will be executed.
+NB. By default a verb has infinite rank; you can append "r to
+NB. a verb-name in defverbs to assign the rank r to the verb.
+NB. Example:
+NB. x f&.g y
+NB. +----------------+
+NB. |g`(f(g(x),g(y)))|
+NB. +----------------+
+NB. where g` means the inverse of g.
+NB.
+NB.
+NB. This script implements a proposal made by Kirby Urner.
+NB. Henry H. Rich (glasss@bellsouth.net), September 2002
+
+NB. =========================================================
+NB.*setfnform v-- select template to use for displaying a function
+NB. Example: setfnform 'math'
+NB. y is 'math','J', or 'Jv'
+NB. if 'math', functions are f(y), f(x,y) and inverses f`(y), f`(x,y)
+NB. if 'J', functions are f y, x f y and inverses f` y, x f` y
+NB. if 'Jv', functions are f_ y, x _f_ y and inverses fI_ y, x _fI_ y
+NB. Or, the individual elements of the display can be specified:
+NB. y is (monadic form);(dyadic form);(monadic inverse form);(dyadic inverse form)
+NB. Where, in each, 'x' will be replaced by the x operand,
+NB. 'y' by the y operand, and 'f' by the function name
+setfnform =: 3 : 0
+if. 2 = 3!:0 y do.
+ select. y
+ case. 'math' do. y =. 'f(y)';'f(x,y)';'f`(y)';'f`(x,y)'
+ case. 'J' do. y =. 'f y';'x f y';'f` y';'x f` y'
+ case. 'Jv' do. y =. 'f_ y';'x _f_ y';'fI_ y';'x _fI_ y'
+ case. do. 'Invalid format selection' 13!:8 (3)
+ end.
+end.
+verbtemplate =: y
+0 0$0
+)
+
+NB. =========================================================
+defverbs =: (0 0$0)"_ @: (3 : 0 @ >) @: (<;._1 @: (' '&,) ^:(2: = 3!:0))
+prerank =. '"' taketo y
+if. (<prerank) e. ,each 'xy' do.
+ 'Names x and y are not permitted as verb names' return.
+end.
+rank =. _ ". '_'&[^:(0:=#) '"' takeafter y
+(prerank) =: (prerank defverb 0 " rank) :. (prerank defverb 2)
+''
+)
+
+NB. =========================================================
+NB.*defverbs v-- define names of verbs for function display
+NB. Example: defverbs 'f g h sin cos'
+NB. The verb name may be followed by "rank
+NB. names x and y are not permitted here
+defverbs =: 3 : 0
+if. L.y do.
+ nms=. y
+else.
+ nms=. <;._1 ' ',y
+end.
+r=. ;~.defverbs1 each nms
+if. 0=#r do. i.0 0 end.
+)
+
+NB. =========================================================
+defverbs1=: 3 : 0
+prerank =. '"' taketo y
+if. (<prerank) e. ,each 'xy' do.
+ 'Names x and y are not permitted as verb names' return.
+end.
+rank =. _ ". '_'&[^:(0:=#) '"' takeafter y
+(prerank) =: (prerank defverb 0 " rank) :. (prerank defverb 2)
+''
+)
+
+
+NB. =========================================================
+NB. verbtemplate is (monadic form);(dyadic form);(monadic inverse form);(dyadic inverse form)
+NB. u is name of function, v is 0 for fn, 2 for inverse
+NB. x and y are arguments
+defverb =: 2 : 0
+if. 1 < #$ cy =. ": >y do. cy =. (":$y),'$',, (') ' ,~ '(' , ])"1 cy end.
+rp =. 'y';cy;'f';u
+< (v {:: verbtemplate) rplc rp
+:
+if. 1 < #$ cx =. ": >x do. cx =. (":$x),'$',, (') ' ,~ '(' , ])"1 cx end.
+if. 1 < #$ cy =. ": >y do. cy =. (":$y),'$',, (') ' ,~ '(' , ])"1 cy end.
+if. ' 'e.,cx do. cx =. '(',cx,')' end.
+rp =. 'x';cx;'y';cy;'f';u
+< ((>:v) {:: verbtemplate) rplc rp
+)
+
+NB. =========================================================
+NB.*defnouns v-- define names of nouns for function display
+NB. Example: defnouns 'f g h sin cos'
+NB.
+NB. y is noun names, either as string of words (e. g. 'a b cd')
+NB. or a list of boxes (e. g. 'a';'b';'cd')
+NB. Each noun is defined as a boxed character string whose value equals its name
+defnouns =: 3 : 0
+nms=. ;: :: ] y
+txt=. > nms ,each (<'=: ''') ,each nms ,each ''''
+3 : '". y [ 4!:55<''y''' txt
+i. 0 0
+)
View
67 assets/addons/general/misc/font.ijs
@@ -0,0 +1,67 @@
+NB. font.ijs utilities for fonts
+NB.
+NB. Fonts are specified as: fontname size [bold] [italic]
+NB. The fontname should have "" delimiters if it contains blanks.
+NB.
+NB. Example:
+NB. "MS Sans Serif" 14 bold eom
+NB.
+NB. verbs:
+NB. getfont - returns font spec as boxed list
+NB. fontname;size;[bold;italic]
+NB.
+NB. getfontsize - get size of a font spec
+NB. setfontsize - set size into a font spec
+NB.
+NB. changefont - change various elements of a font spec
+
+cocurrent 'z'
+
+NB. =========================================================
+NB.*changefont v optlist changefont fontspec
+NB.
+NB. optlist may contain: bold nobold
+NB. italic noitalic
+NB. size fontsize
+NB.
+NB. font should be: fontname size [bold] [italic]
+NB.
+NB. e.g. ('bold';20) changefont '"Lucida Console" 20'
+changefont=: 4 : 0
+font=. getfont y
+opt=. x
+if. 0=L. opt do. opt=. cutopen ":opt end.
+opt=. a: -.~ (-.&' ' @ ":) each opt
+num=. _1 ~: _1 ". &> opt
+if. 1 e. num do.
+ font=. ({.num#opt) 1} font
+ opt=. (-.num)#opt
+end.
+ayes=. ;:'bold italic'
+noes=. ;:'nobold noitalic'
+font=. font , opt -. noes
+font=. font -. (noes e. opt)#ayes
+}: ; ,&' ' each ~. font
+)
+
+NB. =========================================================
+NB.*getfont v getfont fontspec
+getfont=: 3 : 0
+font=. ' ',y
+b=. (font=' ') > ~:/\font='"'
+a: -.~ b <;._1 font
+)
+
+NB. =========================================================
+NB.*getfontsize v getfontsize fontspec
+getfontsize=: 13 : '{.1{._1 -.~ _1 ". y'
+
+NB. =========================================================
+NB.*setfontsize v size setfontsize fontspec
+setfontsize=: 4 : 0
+b=. ~: /\ y='"'
+nam=. b#y
+txt=. ;:(-.b)#y
+ndx=. 1 i.~ ([: *./ e.&'0123456789.') &> txt
+nam, }: ; ,&' ' &.> (<": x) ndx } txt
+)
View
301 assets/addons/general/misc/format.ijs
@@ -0,0 +1,301 @@
+NB. formatting utilities
+
+NB. center width center text
+NB. clipfmt format data for clipboard
+NB. clipunfmt unformat data read from clipboard
+NB. colhdr column headers
+NB. expandby expand data with fit value
+NB. expandn expand data at every nth item
+NB. flatten flatten array to a character string
+NB. fold fold text to width
+NB. hexdump show text as hex and ascii characters
+NB. nfmt simple numeric formatter
+NB. ruler returns formatted ruler
+NB. sqzint squeeze list of positive integers into short form
+NB. sqzrun squeeze list of numbers into short form
+NB. xfmt format extended integers
+
+cocurrent 'z'
+
+NB. =========================================================
+NB.*center v center text in given width
+NB. form: width center text
+center=: 4 : 0
+rot=. +/ @ (*./\)"1 y = ' '
+txt=. x {."1 rot |."0 1 y
+rot=. - <. -: +/ @ (*./\.)"1 txt = ' '
+rot |."0 1 txt
+)
+
+NB. =========================================================
+NB.*clipfmt v format data for clipboard
+NB. format array of rank 0 1 or 2 for clipboard.
+NB. columns are separated by TAB, rows by CRLF.
+clipfmt=: 3 : 0
+if. 0 e. $y do. '' return. end.
+t=. 3!:0 y
+if. 2=t do.
+ y=. ,y,"1 CRLF
+elseif. 32<:t do.
+ y=. ,&TAB @ ": &.>y
+ y=. ;,&CRLF@}: &.><@;"1 y
+elseif. 1 do.
+ y=. ;,&CRLF @ ": &.><"1 y
+ y=. '-' (I. y='_') } y
+ y=. TAB (I. y=' ') } y
+end.
+y
+)
+
+NB. =========================================================
+NB.*clipunfmt v unformat data read from clipboard
+NB. returns boxed matrix from clipboard result,
+NB. recognizing TAB and CRLF as separators.
+NB. characters are not converted to numbers.
+NB. e.g. try: clipunfmt clipfmt i.5 6
+clipunfmt=: 3 : 0
+if. 0 e. $y do. 0 0 $ a: return. end.
+(<;._2~ e.&(9 10{a.));.2 y,LF -. {:y=. toJ y
+)
+
+NB. =========================================================
+NB.*colhdr v define column headers
+NB. returns matrix of column headers.
+NB.
+NB. y = list with columns delimited by semicolons; and lines
+NB. in each column delimited by commas.
+NB. x is wid or (wid;just), where:
+NB. wid = column widths
+NB. just = a singleton or vector of:
+NB. 0 = centre header, then right justify (default)
+NB. 1 = center header in wid
+NB. 2 = right justify
+NB. 3 = left justify
+NB.
+NB. e.g. hdr=. 'Number,of,employees;Total,salary;Monthly,net,payment'
+NB. (15 12 12;1) colhdr hdr
+colhdr=: 4 : 0
+
+('wid';'just')=. 2{.(boxopen x),<0
+max=. >./wid=. (c=. >:+/y e.';')$wid
+
+hdr=. ,/ ];._2@(,&',');._2 y,';'
+rws=. #hdr
+lns=. rws%c
+hdr=. (rws,max){.hdr
+len=. max-+/@(*./\)@|.@(e.&' ')"1 hdr
+rot=. rws#0
+just=. lns#c$just
+
+if. 0 e. just do.
+ ndx=. I. just=0
+ cls=. >./"1(c,lns)$len
+ j=. (lns#cls-wid)+0<.<.0.5*len-lns#cls
+ rot=. (ndx{j) ndx } rot
+end.
+
+if. 1 e. just do.
+ ndx=. I. just=1
+ j=. 0<.<.0.5*len-lns#wid
+ rot=. (ndx{j) ndx } rot
+end.
+
+if. 2 e. just do.
+ ndx=. I. just=2
+ j=. len-lns#wid
+ rot=. (ndx{j) ndx } rot
+end.
+
+hdr=. rot |."0 1 hdr
+hdr=. (lns,c*max)$,1 0 2|:(c,lns,max)$,hdr
+(,wid >/ i.max)#"1 hdr
+)
+
+NB. =========================================================
+NB.*expandby c expand data with a given value
+NB. e.g. 0 1 0 0 1 expandby 99 [ 10 20
+NB. 99 10 99 99 20
+expandby=: 2 : 'm&# ^:_1 !. n'
+
+NB. =========================================================
+NB.*expandn v expand data at every nth item
+NB. n expandn dat
+NB. expand array at every nth cell.
+NB. e.g. 'ABC DEF G' = 3 expandn 'ABCDEFG'
+expandn=: 4 : 0
+y #~ (#y)$>:(-x){.0j1
+)
+
+NB. =========================================================
+NB.*flatten v flatten array to a character string
+NB. flattens array to a character string with same display
+flatten=: 3 : 0
+dat=. ": y
+select. # $ dat
+case. 1 do.
+case. 2 do.
+ }. , LF ,. dat
+case. do.
+ dat=. 1 1}. _1 _1}. ": < dat
+ }: (,|."1 [ 1,.-. *./\"1 |."1 dat=' ')#,dat,.LF
+end.
+)
+
+NB. =========================================================
+NB.*fold v fold text to width
+NB. syntax: {width} fold data
+NB. data is character vector
+NB. width defaults to screenwidth
+fold=: 3 : 0
+w=. {.wcsize''
+w fold y
+:
+r=. i.0 0
+x1=. >: x
+txt=. y
+while.
+ r=. r, txt {.~ ndx=. x1 - >: x1 | ind=. ' ' i.~ |. x1{.txt
+ #txt=. (ndx+ind<x1) }. txt
+do.
+end.
+r
+)
+
+NB. =========================================================
+NB.*hexdump v show text as hex and ascii characters
+hexdump=: 3 : 0
+val=. ,y
+if. 0=#val do. i.0 0 return. end.
+bar=. 9 { , 9!:6''
+mav=. '.' ((i.32),128+i.128) } a.
+hex=. '0123456789ABCDEF'
+sep=. ' ';'-';' ';' ';' ';'-';' ';' '
+sep=. 3 1 3 1 3 1 3 1 # sep
+rws=. >. (#val) %16
+wid=. >. 16^. rws
+dat=. a. i. (rws*16) {. val
+end=. 2+ (3*j) + 7<j=. 16 | <: #val
+txt=. _16 [\ dat { mav
+txt=. bar,.txt,.bar
+dmp=. (16 16#: dat) { hex
+dmp=. ;"1 (_16 [\ <"1 dmp) ,&.>"1 sep
+dmp=. (}:dmp),end {. {: dmp
+ind=. (((wid$16) #: i.rws){ hex),"1 '0 '
+exp=. rws $ >: _8{. 0j1
+exp # ind,.dmp,.txt
+)
+
+NB. =========================================================
+NB.*nfmt v simple numeric formatter
+NB. simple format of numeric vector or matrix in readable form.
+NB. opt is optional, up to 3 elements:
+NB. 0 = maximum decimal places, max 9 (4)
+NB. 1 = minimum field width (0)
+NB. 2 = display width (screenwidth)
+nfmt=: 3 : 0
+'' nfmt y
+:
+('dp';'fw';'pw')=. x,(#x)}.4 0,{.wcsize''
+x=. (<.0.5+j*y)%j=. 10^dp=. dp<.9
+mat=. 2<:#shape=. $x
+pw=. pw-6*mat
+j=. 30>.fw
+x=. ,x
+d=. j+j.>./+/*(*/\1,dp#0.1) |/ x
+x=. d ": ,.x
+b=. (-j) {. (0>.fw-1)#1
+x=. (b+.c+.1|.c=. ' '+./ .~:x) #"1 x
+len=. <.pw%cls=. >:{:$x
+
+if. mat do.
+ 'r c'=. shape
+ j=. >.c%len
+ exp=. (>:j.(j*len)-c) (<:c*>:i.r) } (#x)#1
+ x=. exp#x
+ b=. ' '={."1 ind=. ":,.i.r
+ ind=. '[',"1 b|."0 1 ind,"1']'
+ lab=. (>:j.j-1)#ind
+end.
+
+rws=. >.(#x)%len
+r=. (rws,len*cls)$,((rws*len),cls){.x
+
+if. mat do. r=. lab,.r end.
+)
+
+NB. =========================================================
+NB.*ruler v formatted ruler
+NB. returns a formatted ruler
+NB. e.g. ruler 75 horizontal
+NB. 1 ruler 30 vertical
+ruler=: 3 : 0
+0 ruler y
+:
+j=. >. 0.2*len=. y
+'a b c'=. 1 4 7 { , 9!:6''
+if. x
+do.
+ r=. len # ,: b,' ',b
+ i=. 0,}. 5*i.j
+ r=. b (<i;0 3) } r
+ (2 ": ,.100|i) (<i;1 2) } r
+else.
+ r=. len #"1 ,. c,' ',a
+ i=. }. 5*i.j
+ r=. b (<0 2;0,i) } r
+ r=. '0' (<1;0) } r
+ if. len > 5 do.
+ r=. (3 ": ,.i) (<1;i-/2 1 0) } r
+ end.
+end.
+)
+
+NB. =========================================================
+NB.*sqzint v squeeze list of positive integers into short form
+NB. Squeeze list of positive integers into short character list.
+NB. If x = 1, sort y first.
+NB. e.g. sqzint 1 2 3 7 8 9 10 = 1-3,7-10
+NB. see also <sqzrun>
+sqzint=: 3 : 0
+0 sqzint y
+:
+if. x = 1 do. n=. /:~ y else. n=. y end.
+ndx=. ((1|.n) ~: >:n) # i.#n
+a=. (0,}:>:ndx){n
+b=. ndx{n
+one=. (a=b)#i.#a
+r=. (10":,.a),.'-',.10":,.b
+ndx=. ((a=b)#i.#b) { i.$r
+r=. (21":one{,.a) one } r
+r=. ' ' -.~ }:,r,.','
+)
+
+NB. =========================================================
+NB.*sqzrun v squeeze list of numbers into short form
+NB. Squeeze list of numbers into short character list.
+NB. e.g. sqzrun 1.1 1.1 1.1 7 9 9 10.25 = 3#1.1,7,2#9,10.25
+NB. See also <sqzint>.
+sqzrun=: 3 : 0
+y=. (b=. ((}.y) ~: }:y),1)#y
+j=. j-_1,}: j=. I. b
+c=. (":,.j),.'#'
+c=. ' ' ((j=1)#i.#j) } c
+' ' -.~ }.,',',.c,.":,.y
+)
+
+NB. =========================================================
+NB.*xfmt v format extended integers
+NB. form: [width] xfmt number
+NB. groups in 3's up to 1e12, and 5's thereafter
+xfmt=: 3 : 0
+({.wcsize'') xfmt y
+:
+t=. ": x: y
+c=. 1j1 1 1,(12<#t)#1 1
+t=. (|.(#t)$c)#t
+if. x>:<:#t do.
+ }:t
+else.
+ (-<.x%6) ;\ <@(_6&{.) ;.2 t
+end.
+)
View
48 assets/addons/general/misc/guid.ijs
@@ -0,0 +1,48 @@
+NB. general/misc/guid.ijs
+NB. Create guids in various formats
+NB. version: 1.0.0
+NB.
+NB. All guid verbs take the shape of guids to return, eg
+NB.
+NB. $guids $0 ==> 16 (create guid as a 16-byte character string)
+NB. $guids 2 3 ==> 2 3 16 (create 2x3 array of 16-byte strings)
+NB.
+NB. guids - return guids as 16-byte strings
+NB. guidsn - return guids as 24-character file names
+NB. guidsr - return guids as 36-character strings, without braces
+NB. guidss - return guids as 38-character strings, with braces
+NB. guidsx - return guids as extended precision integers
+
+cocurrent 'z'
+
+NB. =========================================================
+guids=: 3 : 0
+if. IFWIN do.
+ cmd=. 'ole32 CoCreateGuid i *c'
+else.
+ cmd=. ((UNAME-:'Darwin'){::'libuuid.so.1';'libSystem.B.dylib'),' uuid_generate n *c'
+end.
+>{:"1 cmd 15!:0"1 0 <"1 (y,16)$' '
+)
+
+NB. =========================================================
+guidsn=: 3 : 0
+g=. (24 # 41) #: guidsx y
+g { '+-0123456789=ABCDEFGHIJKLMNOPQRSTUVWXYZ^_'
+)
+
+NB. =========================================================
+guidsr=: 3 : 0
+g=. ,"2 '0123456789ABCDEF' {~ 16 16 #: a. i. guids */y
+y $ }."1 > ,.&.>/ '-',.&.> ('';0 8 12 16 20 e.~ i.32) <;.1 g
+)
+
+NB. =========================================================
+guidss=: 3 : 0
+'{',"1 (guidsr y) ,"1 '}'
+)
+
+NB. =========================================================
+guidsx=: 3 : 0
+256 #. x: a. i. guids y
+)
View
34 assets/addons/general/misc/inverted.ijs
@@ -0,0 +1,34 @@
+NB. Title Essays/Inverted Table - J Wiki
+NB. Current URL http://www.jsoftware.com/jwiki/Essays/Inverted%20Table
+NB.
+NB. Collected Definitions
+
+cocurrent 'z'
+
+ifa =: <@(>"1)@|: NB. inverted from atoms
+afi =: |:@:(<"_1@>) NB. atoms from inverted
+
+tassert=: 3 : 0
+ assert. (1>:#$y) *. 32=3!:0 y NB. boxed scalar or vector
+ assert. 1=#~.#&>y NB. same # items in each box (with at least one box)
+ 1
+)
+
+ttally =: #@>@{.
+tfrom =: <@[ {&.> ]
+tindexof =: i.&>~@[ i.&|: i.&>
+tmemberof =: i.&>~ e.&|: i.&>~@]
+tless =: <@:-.@tmemberof #&.> [
+tnubsieve =: ~:@|:@:(i.&>)~
+tnub =: <@tnubsieve #&.> ]
+tkey =: 1 : '<@tindexof~@[ u/.&.> ]'
+tgrade =: > @ ((] /: {~)&.>/) @ (}: , /:&.>@{:)
+tgradedown=: > @ ((] \: {~)&.>/) @ (}: , \:&.>@{:)
+tsort =: <@tgrade {&.> ]
+
+NB. alternatives
+tmemberof1=: tindexof~ < ttally@]
+tnubsieve1=: tindexof~ = i.@ttally
+ranking =: i.!.0~ { /:@/:
+tgrade1 =: /: @ |: @: (ranking&>)
+
View
143 assets/addons/general/misc/numeric.ijs
@@ -0,0 +1,143 @@
+NB. general/misc/numeric.ijs
+NB. Various numeric utilities
+NB. version: 1.0.0
+NB.
+NB. baserep y in base x
+NB. clean clean y to tolerance of x (default 1e_10)
+NB. colsum sum data columns of matrix by key
+NB. groupndx group indices of y in x
+NB. int01 interval in n steps from 0 to 1 (= steps 0 1,n)
+NB. linsert linear insert x (default 2) steps into y
+NB. randomize sets a random value into random link
+NB. range range from a to b [in steps of c]
+NB. recur solves recurrence r(i)=a(i)+r(i-1)*m(i-1)
+NB. round round y to nearest x (e.g. 1000 round 12345)
+NB. roundbanker round y to nearest x with bankers rounding
+NB. rounddist round y to nearest x preserving total
+NB. rounddown round y down to nearest x
+NB. roundint round to nearest integer
+NB. roundup round y up to nearest x
+NB. steps steps from a to b in c steps
+
+cocurrent 'z'
+
+NB.*baserep v y in base x
+baserep=: (&#.) (^:_1)
+
+NB.*int01 v interval in n steps from 0 to 1 (= steps 0 1,n)
+int01=: i.@(+ *) % |
+
+NB.*linsert v linear insert x (default 2) steps into y
+linsert=: 2&$: : ([: +/\ {.@] , [ # (}. - }:)@] % [)
+
+NB.*round v round y to nearest x (e.g. 1000 round 12345)
+round=: [ * [: <. 0.5 + %~
+
+NB.*rounddown v round y down to nearest x (e.g. 1000 round 12345)
+rounddown=: [ * [: <. %~
+
+NB.*roundint v round to nearest integer
+roundint=: <.@:+&0.5
+
+NB.*roundup v round y up to nearest x (e.g. 1000 round 12345)
+roundup=: [ * [: >. %~
+
+NB. =========================================================
+NB.*clean v clean y to tolerance of x (default 1e_10)
+NB. form: tolerance (default 1e_10) clean numbers
+NB. sets values less than tolerance to 0
+clean=: 1e_10&$: : (4 : 0)
+if. L. y do.
+ x clean each y
+else.
+ if. (3!:0 y) e. 16 16384 do.
+ j./"1 y * x <: | y=. +.y
+ else.
+ y * x <: |y
+ end.
+end.
+)
+
+NB. =========================================================
+NB.*colsum v sum data columns of matrix by key
+NB. form: key colsum mat
+NB. sum data columns of matrix on key columns
+NB. e.g. if column 2 of mat is age, then
+NB. 2 colsum mat
+NB. sums the remaining columns by age
+colsum=: 4 : 0
+nub=. ~. key=. x{"1 y
+nub /:~ nub x}"_1 1 key +//. y
+)
+
+NB. =========================================================
+NB.*groupndx v group indices of y in x
+NB. Return group indices of elements of y
+NB. x is an integer vector of the starting numbers of each group,
+NB. assumed to be in ascending order.
+NB. e.g. 0 0 0 1 1 1 2 2 = 0 3 6 groupndx i.8
+NB. i.e. <:@(+/@(<:/))
+NB. groupndx=: 4 : '<: (#x) }. (+/\r<#x) /: r=. /: x,y'
+groupndx=: [: <: I. + e.~
+
+NB. =========================================================
+NB.*randomize v sets a random value into random link
+randomize=: 3 : 0
+ try.
+ require 'guid'
+ tmp=. _2 (3!:4) , guids 1
+ catch. NB. general/misc/guid.ijs not available
+ tmp=. >:<.0.8*0 60 60 24 31#.0 0 0 0 _1+|.<.}.6!:0 ''
+ end.
+ ([ 9!:1) {.^:(2~:9!:42'') tmp NB. set random initial random seed
+)
+
+NB. =========================================================
+NB.*range v range from a to b [in steps of c]
+NB. range a,b[,c] = range from a to b [in steps of c]
+range=: 3 : 0
+'x y n'=. 3{.y,1
+s=. _1^y<x
+x+s*n*i.>:<.n%~|y-x
+)
+
+NB. =========================================================
+NB.*recur v solves recurrence r(i)=a(i)+r(i-1)*m(i-1)
+NB. form: r = m recur a
+NB. r(0) = a(0)
+NB. r(i) = a(i)+r(i-1)*m(i-1)
+NB. e.g 1.05 1.10 recur 100 100 100
+NB. 100 205 325.5
+recur=: 4 : 'r*+/\y%r=.*/\1,x$~<:#y'
+
+NB. =========================================================
+NB.*roundbanker v round y to nearest x with bankers rounding
+NB.
+NB. round y to nearest x
+NB.
+NB. if y is a mid point, it is rounded up if even, down if odd
+NB.
+NB. 0.1 roundbanker 1.23 2.15 2.25 2.35 2.45
+NB. 1.2 2.2 2.2 2.4 2.4
+roundbanker=: 4 : 0
+rd=. <. d=. 0.5 + y % x
+x * rd - (rd = d) > 0 = 2 | d
+)
+
+NB. =========================================================
+NB.*rounddist v round y to nearest x preserving total
+NB. distributive rounding
+NB.
+NB. round y to nearest x preserving total to nearest x
+NB.
+NB. e.g.
+NB. 0.1 rounddist 6$0.45
+NB. 0.5 0.4 0.5 0.4 0.5 0.4
+rounddist=: 4 : 0
+($y) $ x * (- 0 , }:) <. 0.5 + +/\ y % x
+)
+
+NB. =========================================================
+NB.*steps v steps from a to b in c steps
+NB. form: steps a,b,c
+steps=: {. + (1&{ - {.) * (i.@>: % ])@{:
View
95 assets/addons/general/misc/pack.ijs
@@ -0,0 +1,95 @@
+NB. general/misc/pack.ijs
+NB. Package utilities
+NB. version: 1.0.0
+NB.
+NB. a package is a 2-column matrix of: name, value
+NB. that can be used to store nouns, or otherwise
+NB. associate names and values.
+NB.
+NB. A name is any character vector. pack and pdef work
+NB. only when the names are proper J names.
+NB.
+NB. definitions for nouns only:
+NB. pk=. pack nl create package from namelist
+NB. nl=. pdef pk define package
+NB.
+NB. definitions for any names:
+NB. text=. pk1 pcompare pk2 compare packages
+NB. val=. name pget pk get value of name in package
+NB. pk=. new pset old merge new and old packages
+NB. pk=. nl pex pk remove namelist from package
+NB. pk=. nl psel pk select namelist from package
+NB. res=. packlocale locs package all nouns in locales
+
+cocurrent 'z'
+
+NB. =========================================================
+NB.*pack v package namelist
+NB.
+NB. form: pack 'one two three'
+NB. pack 'one';'two';'three'
+pack=: [: (, ,&< ".) &> [: /:~ ;: ::]
+
+NB. =========================================================
+NB.*packlocale v package locales
+NB.
+NB. form: packlocale locales
+NB.
+NB. example: packlocale 'base';'z';'j'
+NB.
+NB. each locale is packaged and forms one row of the result
+packlocale=: 3 : 0
+ids=. , ,each boxxopen y
+res=. ''
+for_i. ids do.
+ cocurrent i
+ res=. res,< 3 : '(, ,&< ".) &> (4!:1 [ 0) -. ;:''y y.''' ''
+end.
+ids,.res
+)
+
+NB. =========================================================
+NB.*pdef v package define
+NB. form: pdef pk
+pdef=: 3 : 0
+if. 0 e. $y do. empty'' return. end.
+names=. {."1 y
+(names)=: {:"1 y
+names
+)
+
+NB. =========================================================
+NB.*pcompare v compare two packages
+NB. form: pk1 pcompare pk2
+pcompare=: 4 : 0
+n0=. {."1 x -. y
+n1=. {."1 x
+n2=. {."1 y
+list=. ;:^:_1
+r=. ''
+r=. r,(*#d)#LF,'not in 1: ',list d=. n2 -. n1
+r=. r,(*#d)#LF,'not in 2: ',list d=. n1 -. n2
+r=. r,(*#n)#LF,'not same in both: ',list n=. n0 -. d
+}.r,(0=#r)#LF,'no difference'
+)
+
+NB. =========================================================
+NB.*pex v remove namelist from package
+NB. form: namelist pex pk
+pex=: ] -. psel
+
+NB. =========================================================
+NB.*pget v return value of name in package
+NB. form: name pget pk - return value of name in package
+pget=: 13 : '> {: y {~ ({."1 y) i. {. boxopen,x'
+
+NB. =========================================================
+NB.*psel v select namelist from package
+NB. form: namelist psel pk
+psel=: 13 : 'y {~ ({."1 y) i. ;: ::] x'
+
+NB. =========================================================
+NB.*pset v merge new into old
+NB. form: new pset old
+NB. result has values in new, plus remaining values in old
+pset=: (#~ [: ~: {."1) @ ,
View
90 assets/addons/general/misc/parts.ijs
@@ -0,0 +1,90 @@
+NB. general/misc/part.ijs
+NB. Partition functions
+NB. version: 1.0.0
+NB.
+NB. partition functions
+NB.
+NB. Partitions are typically given by a boolean with 1's marking
+NB. the beginning or end of each partition. Partitions are also
+NB. sometimes given in terms of the lengths of each partition.
+NB.
+NB. Verbs defined here assume that boolean 1's mark the beginning
+NB. of each partition - see comments at the end for examples of
+NB. end-partition verbs.
+NB.
+NB. The verbs psum and psumscan illustrate definitions appropriate
+NB. for verbs that return scalar or non-scalar results, respectively.
+NB. utility used to build non-scalar partition functions:
+NB.
+NB. Examples:
+NB.
+NB. 1 0 0 1 0 0 0 = firstones 1 1 0 1 1 1 0
+NB. 0 0 1 0 1 = lastones 1 1 1 0 1
+NB. 2 3 1 = lfp 1 0 1 0 0 1
+NB. 1 1 0 1 0 0 1 = partition 1 9 9 4 4 4 9
+NB. 0 0 0 1 2 2 3 = runindices 3 1 2 1
+NB. 1 2 3 1 = runlengths 1 9 9 4 4 4 9
+NB.
+NB. x=. 1 0 1 0 0 [ y=. 5 3 2 2 7
+NB.
+NB. 3 5 7 2 2 = x preverse y
+NB. 3 5 2 2 7 = x psort y
+NB. 8 11 = x psum y
+NB. 5 8 2 4 11 = x psumscan y
+
+cocurrent 'z'
+
+NB. =========================================================
+NB. verb cp cut where cut is 1=beginning, 2=end.
+cp=. 2 : '; @ (<@u ;. n)'
+
+NB. =========================================================
+NB.*firstones v first 1's in partition
+NB. form: firstones part
+firstones=: > |.!.0
+
+NB.*lastones v last 1's in partition
+NB. form: lastones part
+lastones=: > 1&(|.!.0)
+
+NB.*lfp v lengths from partition
+NB. form: lfp part
+lfp=: #;.1
+
+NB.*partition v partition items (1 marks new item)
+NB. form: partition dat
+partition=: }:@(1 , -.)@((-:"_1) 1&|.)
+
+NB.*pfl v partition from lengths
+NB. form: pfl len
+pfl=: [: ; {.&1&.>
+
+NB.*runindices v indices from run lengths
+NB. form: runindices
+runindices=: I.
+
+NB.*runlengths v lengths of each run
+NB. form: runlengths dat
+runlengths=: lfp@partition f.
+
+NB. =========================================================
+NB.*preverse v partioned reverse
+NB. form: part preverse dat
+preverse=: |. cp 1
+
+NB.*psort v partioned sort
+NB. form: part psort dat
+psort=: /:~ cp 1
+
+NB.*psum v partioned sum
+NB. form: part psum dat
+psum=: +/;.1
+
+NB.*psumscan v partioned sumscan
+NB. form: part psumscan dat
+psumscan=: +/\ cp 1
+
+NB. =========================================================
+NB. example end-partition verbs (use 2 instead of 1):
+NB. preverse=: |. cp 2
+NB. psum=: +/;.2
View
26 assets/addons/general/misc/test_bigfiles.ijs
@@ -0,0 +1,26 @@
+NB. bytes written=.data bappend f append to end
+NB. data=.bixread f;start0,start1[,len[,dirflag]] indexed read
+NB. bytes written=.data bixwrite f;start0,start1[,dirflag] indexed write
+NB. free space=.bdiskfreespaceex dir get disk free space
+NB. free space=.bdiskfreespace drive root get disk free space (device units)
+NB. size=.bfsize f get file size
+NB. fh=.[mode] bopen filename open file input or inout
+NB. success=.bclose fh close open file
+
+load '~/addons/general/misc/bigfiles.ijs'
+
+foo=: 3 : 0
+smoutput ' ',y
+smoutput ". y
+)
+
+F=: jpath '~temp/t1.dat'
+'abc ' fwrite F
+foo '''hello'' bappend_jbf_ F'
+foo 'fread F'
+foo 'H=: bopen_jbf_ ''c:/jmisc/extern/wagon/w228.ijs'''
+foo 'bixread_jbf_ H;0 3 3'
+foo 'bclose_jbf_ H'
+foo 'bdiskfreespace_jbf_ ''d:'''
+foo 'bdiskfreespaceex_jbf_ ''d:'''
+foo 'bfsize_jbf_ ''jpath '~bin/j.exe'''
View
49 assets/addons/general/misc/test_clippaste.ijs
@@ -0,0 +1,49 @@
+NB. ========================================================
+NB. Test script for clippaste.ijs
+
+load '~addons/general/misc/clippaste.ijs'
+
+t0=:''
+t1=:'a'
+t1u=: 1 1$<,t1
+tv=:'This is a test.'
+tvu=: 1 1$<,tv
+tm=:3# ,:tv
+tmu=:3 1$<"1 tm
+tem=:<"1 tm
+temu=:1 3$tem
+tfu=: ,<7 u: 68 58 92 82 92 230 178 146 230 156 137 229 149 143 233 161 140{a.
+tf4=:'c:\this';'c:\is';'c:\a';'c:\tst'
+
+test=: 3 : 0
+assert 0~:setcliptext t0
+assert t0-:getclip''
+assert t0-:getcliptext''
+assert 0-:getclipfiles''
+assert 0~: setcliptext t1
+assert t1u-:clipunfmt getclip''
+assert t1u-:clipunfmt getcliptext''
+assert 0-:getclipfiles''
+assert 0~:setcliptext tv
+assert tvu-:clipunfmt getclip''
+assert tvu-:clipunfmt getcliptext''
+assert 0-:getclipfiles''
+assert 0~:setcliptext tm
+assert tmu-:clipunfmt getclip''
+assert tmu-:clipunfmt getcliptext''
+assert 0-:getclipfiles''
+assert 0~:setcliptext tem
+assert temu-:clipunfmt getclip''
+assert temu-:clipunfmt getcliptext''
+assert 0-:getclipfiles''
+assert 0~:setclipfiles tfu
+assert tfu-:getclipfiles''
+assert tfu-:getclip''
+assert 0=getcliptext''
+assert 0~:setclipfiles tf4
+assert tf4-:getclipfiles''
+assert tf4-:getclip''
+assert 0=getcliptext''
+)
+
+
View
217 assets/addons/general/misc/trace.ijs
@@ -0,0 +1,217 @@
+NB. general/misc/trace.ijs
+NB. Execution trace utilities
+NB. version: 1.0.0
+
+cocurrent 'jtrace'
+
+Note 0
+The main functions are "trace" and "paren".
+
+x trace y trace sentence y to x levels of function calls
+trace y same as _ trace y
+
+For example:
+ trace '3+i.4'
+ --------------- 1 Monad ------
+ i.
+ 4
+ 0 1 2 3
+ --------------- 2 Dyad -------
+ 3
+ +
+ 0 1 2 3
+ 3 4 5 6
+ ==============================
+3 4 5 6
+
+Tracing provides information on results within a line;
+the action labels 0 monad, 1 monad, 9 paren, etc.,
+are from the parse table in Section II.E of the J dictionary.
+
+
+paren y fully parenthesize sentence y
+
+For example:
+ paren '+/i.4'
+((+/)(i.4))
+ paren '(3 4$i.12)+/ .**:i.4'
+((3 4$(i.12))((+/) .*)(*:(i.4)))
+
+)
+
+
+(x)=: 2^i.#x=. ;:'noun verb adv conj lpar rpar asgn name mark'
+any =: _1
+avn =: adv + verb + noun
+cavn=: conj + adv + verb + noun
+edge=: mark + asgn + lpar
+
+x=. ,: (edge, verb, noun, any ); 0 1 1 0; '0 Monad'
+x=. x, ((edge+avn), verb, verb, noun ); 0 0 1 1; '1 Monad'
+x=. x, ((edge+avn), noun, verb, noun ); 0 1 1 1; '2 Dyad'
+x=. x, ((edge+avn), (verb+noun),adv, any ); 0 1 1 0; '3 Adverb'
+x=. x, ((edge+avn), (verb+noun),conj, verb+noun); 0 1 1 1; '4 Conj'
+x=. x, ((edge+avn), (verb+noun),verb, verb ); 0 1 1 1; '5 Trident'
+x=. x, (edge, cavn, cavn, any ); 0 1 1 0; '6 Bident'
+x=. x, ((name+noun),asgn, cavn, any ); 1 1 1 0; '7 Is'
+x=. x, (lpar, cavn, rpar, any ); 1 1 1 0; '8 Paren'
+
+PTpatterns=: >0{"1 x NB. parse table - patterns
+PTsubj =: >1{"1 x NB. "subject to" masks
+PTactions =: 2{"1 x NB. actions
+
+bwand =: 17 b. NB. bitwise and
+
+prespace=: ,~ e.&'.:'@{. $ ' '"_
+ NB. preface a space to a word beginning with . or :
+
+isname=: ({: e. '.:'"_) < {. e. (a.{~,(i.26)+/65 97)"_
+ NB. 1 iff a string y from the result of ;: is is