[Jprogramming] IXML grammar for parse J
I'm planning to make a literate programming tool for J, and the first step is to make a parser that can tokenlize J. https://gist.github.com/LdBeth/8277950958b964d0778d70ffd3d998de Almost everything except multi line explicit definitions are supported, including multi line direct definition (except "{{)n" is not implemented). Trailing whitespaces and comment "NB." would also signify error. You can try IXML in browser using https://johnlumley.github.io/jwiXML.xhtml Let me know about your comments. --- LdBeth -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Issue with dual/under
>>>>> In >>>>> "'Viktor Grigorov' via Programming" wrote: > Why does > (|. &. ,) i.3 3 > result in a domain error (likewise with &.:), while > ($ $ (|. @ ,) ) i.3 3 > doesn't? The domain error is raised by ,^:_1 and as in J and APL the inverse of ravel is not defined in present time. This is not the first time people asking about this feature and the APL community have given this a name "structural under" https://www.dyalog.com/blog/2023/01/structural-vs-mathematical-under/ >> ... an important reason was that Roger Hui wasn’t a big fan of the >> proposed extension known as “structural under” ldbeth -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Issue with dual/under
I feel similar feature is covered by @ (At) from Dyalog APL, as I can think of the definition for monadic "structural under" using APL could roughly be r←(f sunder g)y;i i←,g⍳⍴y r←(f@i)y (⌽sunder,) 3 3⍴⍳9 9 8 7 6 5 4 3 2 1 ldbeth >>>>> In >>>>> Henry Rich wrote: Henry> This seems like a useful feature and not difficult to implement. We can Henry> discuss here what should be supported. Henry> Morten's reservations (in the cited article) are reasonable. I note that J Henry> has semiduals, and that it would make sense to support structural under for Henry> dyads using semiduals. Henry> Henry Rich Henry> On Sat, Oct 14, 2023, 6:10 AM LdBeth wrote: Viktor> Why does Viktor> (|. &. ,) i.3 3 Viktor> result in a domain error (likewise with &.:), while Viktor> ($ $ (|. @ ,) ) i.3 3 Viktor> doesn't? ldb> The domain error is raised by ,^:_1 and as in J and APL ldb> the inverse of ravel is not defined in present time. ldb> This is not the first time people asking about this feature ldb> and the APL community have given this a name "structural under" ldb> https://www.dyalog.com/blog/2023/01/structural-vs-mathematical-under/ >> ... an important reason was that Roger Hui wasn’t a big fan of the >> proposed extension known as “structural under” -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] A Dot-Graph Rotator?
The keyword you would need to looking for is "affine transformation" https://en.wikipedia.org/wiki/Affine_transformation Where image rotation is just a special case [ cos(theta) -sin(theta) 0 ] [ sin(theta) cos(theta) 0 ] [ 00 1 ] And you can combine with other linear transformations by matrix multiplication, so rotate around a different origin would work. Also see https://math.stackexchange.com/questions/2093314/rotation-matrix-of-rotation-around-a-point-other-than-the-origin > In > "'PMA' via Programming" wrote: > Dear J-Programming Forum, > I want to make a script that, given the X/Y values of a 2D > dot-graph, will rotate the graph around its designated origin, > looking for instances of 2 or more points coming into new horizontal > &/or vertical alignment, and at each such instance output the full > set of current X/Y values (integer-rounded). > Could you point me to the main needed ingredients? > Thanks in advance, > Peter Armstrong > -- > For information about J forums see http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] String replacement question
A very clever gimmick I saw from https://xpqz.github.io/AoC-day1/ is replace the following composite words: 'oneight' 'eightwo' 'nineight' 'twone' 'sevenine' 'eighthree' by '18' '82' '98' '21' '79' '83' And it totally works XD > In > David Pinchbeck wrote: > I'm trying to improve my J using Advent of Code, but am already a bit > stuck on the second part of day 1. It seems late enough in the day now to > ask this question without spoiling anything. > On the example code one needs to turn the string 'eightwothree' into '8wo3' > I tried the following, which fails because the priority of stringreplace > comes from the left argument ordering: > digs=:'0123456789' > s=:'zero';'one';'two';'three';'four';'five';'six';'seven';'eight';'nine' > substr=:(s,. <"0 digs) > g=:{{ substr stringreplace y}} > g 'eightwothree' > eigh23 > How can I get the earliest appearance on the right side to be replaced > first instead? > Thanks, > David > -- > David Pinchbeck > Associate Professor of Mathematics > St. Joseph's College > Standish, ME > -- > For information about J forums see http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm
[Jprogramming] AoC Day5 part2
While I know the most efficient way would be implement something like an interval set, I'm just too lazy so instead I trust J can be efficient enough and I can write efficient enough J program to solve by brutal force. It spent about 30 minute to get the result up to the fourth pair, that is 2714499581+i.312077252, which happens to be the final answer, and the virtual memory usage reach 67GB while used up all my 16GB physical memory on my Intel MacBook and in addition 6GB swap. And the intense computation even glitched the display out. Here is my program NB. input data seeds=:3121711159 166491471 3942191905 154855415 3423756552 210503354 2714499581 312077252 1371898531 165242002 752983293 93023991 3321707304 21275084 949929163 233055973 3626585 170407229 395618482 226312891 seed_to_soil=:". >cutopen noun define 522866878 679694818 556344137 1206934522 1236038955 57448427 2572695651 3529213882 270580892 1082547209 29063229 124387313 .. transform2 =: {{ ms=.(((+/1 2{|:x)>/])*.(1{|:x)<:/])y y+,(|:ms)#([:-/2{.])"1 x }} part2 =: {{ 'a b'=.y tmp=.(seed_to_soil&transform2) a+i.b smoutput 'ok' tmp=.(soil_to_fertilizer&transform2) tmp smoutput 'ok' tmp=.(fertilizer_to_water&transform2) tmp smoutput 'ok' tmp=.(water_to_light&transform2) tmp smoutput 'ok' tmp=.(light_to_temperature&transform2) tmp smoutput 'ok' tmp=.(temperature_to_humidity&transform2) tmp smoutput 'ok' tmp=.(humidity_to_location&transform2) tmp smoutput 'ok' tmp=.<./tmp smoutput tmp tmp }} res=:part2 " 1]10 2$seeds smoutput <./res exit 0 -- For information about J forums see http://www.jsoftware.com/forums.htm
[Jprogramming] Get all indexes of a boolean array
I've been running to too many situations that I uses 4$.$.y a lot to get indexes of all non zero elements to an array, I wonder if there are any alternative ways to do that in J, especially when y is a boolean array. Also monadic I. only works for 1D array, while ⍸ from APL works for higher dimension cases, how to implement this in J? LdBeth -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Get all indexes of a boolean array
I appreciate your effort demonstrate on how to derive reusable code in J. It is important to know how to adapt existed solutions for different needs. To me knowing that I can use the shape of the array to decode (#:) indices generated by I. is a good enough respond to my question. So I also thank to everyone who presented their answer. LdBeth >>>>> In >>>>> "'Viktor Grigorov' via Programming" wrote: Viktor> A fully tacit solution would encapsulate the predicate too, Viktor> here parenthesized for emphasis: Viktor> ($ #: [: I. [: (5&=) ,) (>:i.8)* 8 8 $ 1j2 # 1 Viktor> 4 1 Viktor> 4 4 Viktor> 4 7 -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] hello and announcement on implementation of web form server system for adding forms to Jconsole function
Very interesting framework, the install process required for source package I found from https://www.smccake.net/japla/making_basic_ver_0_1.zip seems has a deviation from the description in PDF, that is, assume the 'making/' dir in downloaded zip is unpacked to $HOME, boot Jconsole in $HOME and load 'making/begin_web_server_jconsole.ijs' begin 0 I'm a little concerned on the validity of the HTML returned from the server, for example in the first app 00_centigrade_fahrenheit_mutual_converter the HTML returned begins with: temperature converter (centigrade <-> fahrenheit) ^ < not escaped. Also I just found some typos in the PDF https://www.smccake.net/japla/web_form_server_for_J_console_ver_0_1.pdf Page 39, "4 Discussion", second paragraph, Moreover, an original J functiion can ^ Page 40, "5 Registered names for globals and functions" avoid confiction among names is to ^ I'll continue to explore the program and may send more feedbacks. LdBeth >>>>> In <9cf51392-f6c2-4726-88d1-bb22f903d...@smccake.net> >>>>> Yuji Suda wrote: YS> Hello everyone YS> I am Yuji Suda from Sendai, Miyagi, Japan. YS> Recently I have developed and implemented a web form server system in YS> J and Jsocket for adding forms to Jconsole funtion. It was presented YS> in the Workshop of JAPLA YS> http://japla.sakura.ne.jp YS> on 8 December 2023. YS> The abstract is as follows. YS> YS> A novel web form server which can work as form adding functionality YS> for J function has been implemented. The server system is written in J YS> and accompanying system tool of jsocket. Users can deploy mechanism of YS> retrieving arguments for J functions through web form controls of YS> textbox, textarea, checkbox, dropdown, checklist and radiobutton, and YS> of displaying result of J function in the same web form page as plain YS> text and one image file. Four major web browsers, i.e. Microsoft Edge, YS> Google Chrome, Apple Safari and Firefox, were tested. They were all YS> feasible in communication of plain text. As for image transmission YS> through inline frame control, only Firefox was feasible in YS> operation. With this server system, web browsers can be utilized for YS> adding basic forms to J function. YS> YS> The document pdf were registered in the record of workshop therein, YS> and the scripts for actual web form server system is set at YS> https://www.smccake.net/japla/ YS> I would like to have it evaluated by users in this forum. YS> With best regards, YS> Yuji Suda YS> -- YS> For information about J forums see http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Index of item in table
This is related to the question I asked several days ago, http://jsoftware.com/pipermail/programming/2023-December/062994.html My suggestion would be 8 (($@])#:[i.~,@]) A 1 3 Although you might want to an alternative behavior when there are multiple matches. LdBeth :) >>>>> In >>>>> David Pinchbeck wrote: > Having trouble finding this in the wiki: I know that we can select from a > table using a boxed pair > A > 0 1 2 3 4 > 5 6 7 8 9 > 10 11 12 13 14 > 15 16 17 18 19 > 20 21 22 23 24 > (<1 3){A > 8 > How do I write a verb f to do the reverse, so that > 8 f A > yields the result 1 3 ? > Thanks, > David > -- > David Pinchbeck > Associate Professor of Mathematics > St. Joseph's College > Standish, ME > -- > For information about J forums see http://www.jsoftware.com/forums.htm -- For information about J forums see http://www.jsoftware.com/forums.htm
Re: [Jprogramming] Bug in sorting?
JVERSION Engine: j9.5.1/j64avx2/darwin Build: commercial/2023-12-20T04:08:21/clang-14-0-0/SLEEF=1 Library: 9.5.5 Platform: Darwin 64 Installer: j9.5 install InstallPath: /usr/local/etc/j9.5 Contact: www.jsoftware.com And sorting by itself along would crash JEngine p =. 8 2 $ 0 0 1 1 1 0 0 0 0 1 1 0 1 0 0 0 p /: p JE has crashed, likely due to an internal bug. Please report the code which caused the crash, as well as the following printout, to the J programming forum. LdBeth >>>>> In <9d48c6be-8497-4dfd-8b17-415a135c1...@students.mimuw.edu.pl> >>>>> Marcin Żołek wrote: > I figured out that the problem is with sorting: > p =. 8 2 $ 0 0 1 1 1 0 0 0 0 1 1 0 1 0 0 0 > p > 0 0 > 1 1 > 1 0 > 0 0 > 0 1 > 1 0 > 1 0 > 0 0 > /:~ p NB. returns various and wrong results > 0 0 > 0 0 > 0 0 > 1 0 > 1 0 > 1 0 > 1 1 > 1 1 > or > 0 0 > 0 0 > 0 0 > 1 0 > 1 0 > 1 0 > 0 0 > 0 0 > ~.@:/:~ p NB. crashes jqt -- For information about J forums see http://www.jsoftware.com/forums.htm