Re: [Jprogramming] Applying a cyclic gerund

2023-02-25 Thread neitzel
> I want to convert the second one into numerical data
> Can you simplify the above expression?

Applying a gerund cyclically, as asked for in the subject:

  ] list =. ;: 'foo 1 bar 2.17 baz 3.14'
+---+-+---++---++
|foo|1|bar|2.17|baz|3.14|
+---+-+---++---++

   , ]`(".each)/.  list
+---+-+---++---++
|foo|1|bar|2.17|baz|3.14|
+---+-+---++---++

   (,: datatype each)  , ]`(".each)/.  list
+---+---+---++---++
|foo|1  |bar|2.17|baz|3.14|
+---+---+---++---++
|literal|boolean|literal|floating|literal|floating|
+---+---+---++---++


Obliquing over a vector is often overlooked.  It picks up every item
as a singleton "diagonal".  The final "," is required to compensate
for that.

        Martin Neitzel
--
For information about J forums see http://www.jsoftware.com/forums.htm


[Jprogramming] J Leaderboard for Advent-of-Code 2022

2022-12-01 Thread neitzel
The

https://adventofcode.com/2022

fun started today.  The shared leaderboard for J enthusiasts
is the same as every year.  If you are new:

Log into your AOC account, go to

https://adventofcode.com/2022/leaderboard/private

and join with the code:  50810-78161bf8

As always:  we live in wildly different timezones and the board's
role is more for keeping up your morale rather than to rank {.

Martin

(You don't lose any previous stars when you join this board later.
Everything get's accordingly re-ranked.  You can even do assignments
from earlier years and move up in that year's private board.)


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Plot a Squircle in J

2022-08-16 Thread neitzel
RD> I want to construct and plot a Squircle in J.   [...]
RD> 
RD> Has anyone a good idea for performing that calculation? Could the J
RD> function plot then draw the Squircle?

It is easy to "plot" parametric functions in the complex plane.

Here are three parametric functions, to be computed over parameter
inputs for a full circle, say, -pi to pi in 200 tiny steps:

circle =. cos  j.  sin
square =. cos j.&* sin

squircle =. (square + circle) % 2:  NB. your "mean" of the functions.

NB. Show time!

plot (circle , square ,: squircle)  i: 1p1 j. 200

        Martin Neitzel

PS:

That * in  cos j.&* sin  is Sign, bulging out the circle to the full
1 _1 (square) borders.

Have some thoughts on what actually happens when the Sign * acts on and
returns a 0, and how that shows up.
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] calling linux command and dealing with streams

2022-06-24 Thread neitzel
Pawel Jakubas asked:
>
> What is your recommended way to call linux command/invoke program
> from J and capture result? Let's say I want to invoke
> *dd if=/dev/urandom bs=100 count=1*

   
NB. 2!:0 returns stdout, stderr goes to the console
s =. 2!:0 'dd if=/dev/urandom bs=100 count=1'
1+0 records in
1+0 records out
100 bytes copied, 3.686e-05 s, 2.7 MB/s
   $s
100
   60 list a. i. s
147 199 188 11  245 166 129 112 202 129 68  223 155 220 49  
246 215 76  27  156 172 0   145 231 91  42  33  72  68  163 
57  125 225 209 236 200 157 8   39  216 212 210 88  64  3   
48  13  55  209 142 177 188 124 93  253 114 89  51  7   213 
198 226 153 13  38  102 130 135 201 85  154 238 32  237 143 
88  184 127 165 153 57  33  128 188 232 34  177 254 27  131 
243 66  198 56  79  160 81  163 7   250 


   ' (' taketo 2!:0 'uname -a'
Linux hubert 5.15.35-1-pve #1 SMP PVE 5.15.35-3

   9!:14''
j901/j64/linux/release-c/commercial/www.jsoftware.com/2020-01-11T10:39:00

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] How to convert list of phrases to list of boxed phrases?

2020-05-17 Thread neitzel
;/
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Help, please, understanding request for x 0!:n y (Pascal or others)

2019-08-23 Thread neitzel
Henry Rich wrote:
>
> There is a request outstanding for a change to 0!:n, giving an optional 
> left argument.  The justification is to allow a verb to find the name of 
> the script it was loaded in. I don't see why the current 4!:3 and 4!:4 
> aren't adequate.  Can someone explain why
>
> (4!:3'') {~ 4!:4 <'name_of_my_verb'
>
> doesn't suffice?

Well, Jasmin Pascal as the author should probably speak for his own
proposal and what he meant, but I understood the request as follows:

Currently, if you "load" a series of definitions not from a file
but a noun script, for example:

   s =: 0 : 0
plus =: +
)

   0!:101 s
   plus =: +

   17 plus 4
21

   4!:4 <'plus'
_1

   NB. not really meaningful in this case:
   (4!:3'') {~ 4!:4 <'plus'
+--+
|/usr/local/j64-802/system/util/jadetag.ijs|
+--+

I take it the proposal is asking for a way to provide a pseudo filename
which could be specific for loading from a noun

   '/some/arbitrary/string' 0!:101 s

which would be then used as the alledged script source.  It also
assume that Jasmin was thinking of deriving a source noun from
a "not-quite-J-script" file.  Imagine...

- a mail-file with a mail header and a J script body,
- a J script digitally signed by its author,
- a J script containing additional "WEB"-style documentation
- a J script containing extra code for instrumentation which
  should be stripped off,
- a J script NOT containing instrumention code which should
  be added.

In all these cases, the files could be preprocessed by some special
J loader code into noun scripts and "executed from noun" but, in case
of errors, with a helpful hint from which file the code originated.

Personally, I would prefer cpp-style #file/#line directives in
scripts.   At any rate, the above is how I understood the proposal.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Adding leading zeros

2019-02-03 Thread neitzel
SC> What's the best way to add leading zeros to a set of integers.

The compatible way, going back to J Version 5, 1992:

Over-take from the end with {. and Fit !. it to specify the fill
element:

   _4 {.!.'0'   'ab'
00ab

Apply the usual extra stuff to have that work on your numeric list:

   _4&({.!.'0')@":"0 a
0001
0002
0003
0004
0005
0010
0020
0030
[...]

The new way, avalailable since J Release 6.01, 2006:

   'r<0>4.0'  8!:2  ,. a

    Martin Neitzel
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Tacit form: How to handle intermediate result..?

2018-09-04 Thread neitzel
Martin Kreuzer wrote:
>
> To calculate the area of a flat triangle, using Heron's formula,
> A(a,b,c)= sqrt( s2*(s2-a)*(s2-b)*(s2-c) )
>
> Q: Is there a way to reference the intermediate result of ([: -: +/) 
> the half perimeter s2 within the tacit expression, as has been done in
> the explicit..?

Nothing easier than that.   You just need to think in functional style.
Define s2 as the function you already suggested:

   s2 =. [: -: +/

and use this function in the tacit form just like you would use
"its intermediate result":

   A =. %: @ (s2 * */@(s2 - ]))

If you'd rather use pseudo-forks, this would be

   A =. [: %: s2 * [: */ s2 - ]

What you use is a matter of taste / personal preference.

What *does* matter is that using such auxiliary functions is *good*.
Eugene McDonnell was a great teacher demonstrating elegant, readable
code composed out of useful little parts.

    Martin Neitzel

PS:

There's little reason not to use auxiliary functions.  One objection
could be:

"In  A =. %: @ (s2 * */@(s2 - ])),
the half perimeter is needlessly
computed twice."

If this bugs you, too, you can hunt for a tacit expression which
factors the s2 out into a single instance.

B =. %: @ (s2 ([ * */@:-) ])

The (dyad)fork-within-in-a-(monadic)fork here makes me wondering
if it could be rewritten into some equivalent, nicer form.  This
is how I tackle these things:

The  (f g ])  there is an anti-pattern to me crying out for a hook
instead.  We can get there by commuting the fork's tines into
the equivalent  (] g~ f),  i.e.

B =. %: @ (] ([ * */@:-)~ s2)

which we can now simplify into a hook because "(] f g) y <--> (f g) y":

B =. %: @ (([ * */@:-)~ s2)

The ~ Reflection can be pulled into the tines of the fork, and then
directly applied to the [ yielding ].  Since the inner * Times is
commutative, swapping the tines is possible and makes it a teensy little
bit easier to see that it will pick up the s2 result:

B =. %: @ (([ * */@:-)~ s2)
B =. %: @ (([~ * */@:-~) s2)
B =. %: @ ((]  * */@:-~) s2)
B =. %: @ ((*/@:-~ * ]) s2)
B =. %:@((*/@:-~ * ]) s2)   NB. canonical spacing

(Again, we have the "(f g ]) anti-pattern"; but this time it is used
dyadically and cannot be turned into a hook.  At least I think so :-)

Is the final B more readable than the initial B?
Is any of the Bs more readable than any of the As?

You decide.
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Tacit form: Where to put the start value..?

2018-08-07 Thread neitzel
Hi Martin!

>(+:^:(]`(%~))) 5
>32
>(+:^:(]`*)) 5
>32

The good old Constant function 1: will give you the benefits of
less circumlocution, better results for non-positive arguments,
and coverage of array arguments:

   +:^:(]`1:)  (,: -) 0 1 2 5
1   24  32
1 0.5 0.25 0.03125

A nice puzzle, BTW.  I was only capable to get to

   (+:@]^:[ 1:) 5
32

on my own, ignorant of the gerund option.

Martin (the other one)
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] What's happening here?

2018-07-31 Thread neitzel
>  I am running a much older J and the output is the same :
>  #(#~ ((-:~.)*(-:\:~))"1)":,.p:1200+i.10
>1

I am running a much older J and the output is not the same:

   #(#~ ((-:~.)*(-:\:~))"1)":,.p:1200+i.10
value error

Here, p: is not a primitive but a "given name", a user-(un)defined
name which would be immutable once defined.


We are in twisty little maze of J versions, all alike.  It would really
help me if people would always state the exact J version, OS used,
and platform used.  Remember:  "not *all* the world is a DEC VAX",
although, in the case above, it is close.  It's a DECsystem 5000/240,
running Ultrix-4.4.  The J is J Version 5.1 (1992).


The earliest J I can come up with to confirm the results 0 3 1:

J 2.06.04 Copyright (c) 1990-1995, Iverson Software Inc.

on a i386 linux system of a 1994ish slackwarish persuasion with
libm.so.5 => /lib/libm.so.5.0.6
libc.so.5 => /lib/libc.so.5.3.12

FWIW, same results on all J Releases 3.02, 3.03, 4.01c, 4.01d, 4.02a,
4.05d+, j5.01b, j5.04 on that same i386 linux, and on j602a_linux64,
and  j806/j32/raspberry from 2017-09-18 on a non-raspberry ARM
evaluation board running Debian 7.11.

I guess that accumulated enough Nerd Points for today.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Tacit equivalent of t=: 1 : '%:@:(u/) y'

2018-07-31 Thread neitzel
Piet Google wrote:
>  t=: 1 : '%:@:(u/) y'

Note that u/ has unbounded rank anyway, so you can reduce the colonitis
a little bit:

   t =: / (%:@)

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Does anyone use negative level? (change proposal)

2018-07-27 Thread neitzel
HHR> I think negative level is wrongly defined.

Just a few weeks ago, i dug down into L./L:/S:/{:: level counting
myself, incl. negative levels specs.  (Raul's wonderful "convert/json"
add-on made me do it.  I blogged a few notes in
https://www.gaertner.de/~neitzel/nb/archives/2018/06/16/martin_groks_the_l_level_at/index.html
)

I'm interested in reading your proposed changes but it will
take me at least a week to get to it.  More likely two weeks.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Catalogue

2018-07-22 Thread neitzel
Henry Rich wrote:
> As I read Ye Dic, ({ i. 2 4) should give the same result as
> ({ <"1 i. 2 3).

I never thought I'd have to say this to *you* but:
note that Catalogue { has rank 1.

Hence there should not be any interaction between the colors in

   { 'black' ,: 'green'

nor in the low / high vectors in

   { i. 2 4


To me, Catalogue { works just fine as-is.  In particular, the DoJ
also covers the "open argument" case as it stands.

   { 'black'NB. the same as:   { 'b' ; 'l' ; 'a' ; 'c' ; 'k'
+-+
|black|
+-+

Quote:

{y forms a catalogue from the atoms of its argument, its shape
being the chain of the shapes of the opened items of y . The
common shape of the boxed results is $y .

Martin


[PS 1:  the empty shape of the resulting box

   $ { 'black'


happens to be a concatenation ("chain") of the five empty letter shapes
here.

PS 2:  Those reading down to here may also be interested in this
short exercise:

What's the result of
{ 'ht' ; 'ao' ; ,. 'gtw'
?

(Just follow the instructions above :-)
]
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Fwd: Convention to stop loading a script

2018-05-09 Thread neitzel
Ian Clark wrote:
>
>Can I propose we agree to alter the stdlib verb: (load) to provide a way to
>stop loading a given script?
>
>   @@NB. stop loading at this line
>
>certainly does that, but generates an unwelcome "syntax error". This can
>interfere with calling processes.

I'd be wary of establishing a meta-language/notation controlling script
loading.   Enough tools exist to deal with your stop line, for example:

0!:101 ({.~ I.@('@@')) 1!:1   <'yourscript.ijs'
0!:101 [ 2!:0 'sed "/^@@/{s///;q}" yourscript.ijs'

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] trivial value passing issue

2018-03-03 Thread neitzel
raoul schorer wrote:
> 
> 
> NB. Column index of data y by name x
> colIdxByName =: 4 : 'I. (0 { y) =  
> NB. Select a column in data y by index x
> colByIdx =: 4 : '}.x{|:y'
> 
> But if I try:
> 
> colByName =: 4 : 0
>  idx =. x colIdxByName y
>  res =. idx colByIdx y
> )

Your approach is very sound but has some hideous inside detail wrong.
You just need some advice how to debug things at this point.

> 'Valeur' colByName data   NB. nothing happens...

Every expression either yields a very visible error message or returns
*something*.  Have a look at at its shape:

$ 'Valeur' colByName data

You'll find that you got a matrix with 0 rows but some columns here.

> idx =: 'Valeur' colIdxByName data
> idx colByIdx data   NB. this doesn't work
> 
> 2 colByIdx data  NB. but this does...

Then there must be some difference between idx and 2 even though
not immediately obvious.  Again,

$ idx

will tell you that you have not your expected scalar 2 here but a
singleton vector.

You'll be certainly able to further track the down, where in your
colByName utility this singleton-instead-of-scalar originates.
Then you can fix that.

Martin

Some extra remarks:

- idx -: 2
- datatype idxNB. when strings disguise as numbers
- most J'ers would have build colIdxByName upon i. instead of I.
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] self documentation

2018-02-28 Thread neitzel
David Lambert:
>
> Dyad=: [: :
> add=: +&:([ 'x add y yields the sum x + y'"_) Dyad

Unlike +, the "add" has ranks _ _ which will be noticable with enough
context:

   1 <@add i. 4
+---+
|1 2 3 4|
+---+
   1 <@+   i. 4
+-+-+-+-+
|1|2|3|4|
+-+-+-+-+

Given that that you are ditching the monadic case anyway here,
it's simpler (and rank-preserving) to use u:v here:

   add =. 'x add y yields the sum x + y'"_ : +

or, with your Dyad-style protection against misuse:

   add =. [:&'x add y yields the sum x + y' : +

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Strange behavior of 0x1

2017-12-16 Thread neitzel
   0x1
2.71828
   9!:14''
j806/j32/raspberry/beta/commercial/www.jsoftware.com/2017-09-18T01:24:43
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Call for Wiki work: standard library

2017-10-31 Thread neitzel
We have had "scriptdoc" for ages.  It provides for both individual
verb/whatnot documentation and for overall script/bundle documentation.

Make its use mandatory for all add-on contributors.  Extract the
initial script comment as "add-on abstract" automatically.

Make that abstract viewable Both for the web and, IMHO more important,
the "pacman"/jpkg utility, prior to an actual package install.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Jx 1.1 Release

2017-10-13 Thread neitzel
BL> The printed book documentation for J. The company was still called ISI at
BL> that time, early 90's.
BL> https://i.imgur.com/cvzzJNk.jpg

Yepp, those "green ones" were J Rel. 2 (the first commercial release,
introducing the Windows IDE und "WD" gui programming), 1994.

The Rel. 3 documents (1996) were red-white instead of green-white,
the Rel. 4 ones (1998) tinted blue with different border colours:

https://ia800608.us.archive.org/zipview.php?zip=/30/items/olcovers94/olcovers94-L.zip=944309-L.jpg

I am not aware of any DoJ / User Manual / etc. printed after that.
If there was any, please let me know.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Jx 1.1 Release

2017-10-13 Thread neitzel
bill lam wrote:

BL> Please note that some of rules for bident and trident are specific to the
BL> ancient J. Current J only supports verb trains (fork and hook) and NVV as a
BL> fork,

That's not entirely correct.  We still have the

V0 C1
N0 C1
C0 V1
C0 N1

A0 A1

bident trains, all creating adverbs.  Their description just
switched to a more textual form.

BL>  please see current version J dictionary.

Yes.  http://www.jsoftware.com/help/dictionary/dictf.htm

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Jx 1.1 Release

2017-10-13 Thread neitzel
bill lam wrote:
>
> As mentioned earlier, ancient J had a more complete set of
> rules for tridents and bidents. This is what availbale in
> J circa 1994 (23 years ago)
>
> https://i.imgur.com/OtBZZq1.jpg

No need for scans and jpegs:

http://juggle.gaertner.de/ref/dictionary/dictf.htm

That's the entire documentation set as of J Rel. 4  [around the year
2000].  I still have to refer to it every then and now.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Newbie frustration

2017-04-02 Thread neitzel
Michael Goodrich wrote:
> Was going fine until I wrote the first control loop:  always get
> 'spelling error' even if i copy one from the books.

Many of "the books" are old and have not been updated to current
language rules.  Most prominently, you'll find dotted placeholders
x. y. u. v. m. n. in old literature which must be plain x y u v m n
now.

Your only safe-to-be-current ressource is the Dictionary of J.
See http://www.jsoftware.com/help/dictionary/contents.htm
and, for control structures in particular, its section
http://www.jsoftware.com/help/dictionary/ctrl.htm

>Can anyone advise?

Not any better as this as long as you keep the troublesome J code
you used as a secret.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Displaying boxed tables

2016-03-31 Thread neitzel
> If you are working on a different OS (linux? mac?) or a different kind
> of terminal emulator, then the details will be different.

Yes, depending on the terminal / terminal emulation you are using,
you'll get wrapped lines or a horizontal bar for the long lines.

Wrapping can only wrap what's there.  I find the 'max line length'
default of 256 characters too restricting:  I don't like to have

i. 100

nicely wrapped but ellipsed after the 88.  So I put a

9!:37 ] 0 _ _ _

into some startup file quite quickly.

Martin Neitzel
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Remove trailing zeros

2016-03-30 Thread neitzel
KM> How do you remove trailing zeros from a vector?

I was reminded of the "delete trailing blanks" standard utility:

   dtb
#~ ([: +./\. ' '&~:)

and Roger's "remove trailing zeroes" mirrors that pretty closely:

   rtz=: #~ +./\.@(0&~:)


This might suggest a bit of refactoring:

   fill =: 3 : '{. 1 {. 0 {. y'
   delete_padding =:  ($:~ fill) : (+./\.@:~: # ])

   delete_padding 1 2 0 0
1 2
   '!' ,~ delete_padding 'foo bar   '
foo bar!
   '.' delete_padding 'foo bar...' 
foo bar

    Martin Neitzel
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Unbox request for requests

2016-03-19 Thread neitzel
[For historical issues, it helps to spell out "Version" and "Release"
with the numbers:

J Version 1 was rather known as "APL\?" or "APL90 J" as
presented in http://www.jsoftware.com/papers/J1990a.htm#intro

J Version 2 - 7:  = 1990-1993

J Version 7 (open source) was then followed by the polished,
commercial, non-source "J Release 2".  The never was something
called "J Release 1".  (You are free to view the preceeding
versions as the "Release 1s", but it is in no way an official
designation.)

J Release 2 ...:  = 1994 and later
]

Henry Rich asked:
> How far back do you have to go to find an old system that allows an 
> adverb as an operand to an adverb?

The AA bident is still working, and the question should rather be:

"How far do you have to go back to find an old system
which does *not* allow the AA bi-dent?"

> 7 didn't allow it, did it?

J Version 7 allowed it:

  neitzel 422 > j7
  J7 Copyright (c) 1990-1993, Iverson Software Inc.  All Rights Reserved.

 0!:0 'uname -a'
  ULTRIX ips 4.4 0 RISC

 APLscan =. /\
 + APLscan 1 2 3 4 5
  1 3 6 10 15

as did

  neitzel 426 > j
  J5.1   Copyright (c) 1990-1992, Iverson Software Inc.  All Rights Reserved.

which is the oldest version I have still running and which supports AA.


The AA bident was first introduced with J Version 3.3:

Changes in Version 3.3, 1991 06 25
  [...]
  a-trains   implemented
  c-trains   implemented

(I cannot find the AA bident yet in the blue "Tangl.Math + DoJ" booklet
which must be Version 2.9ish or even 3.  It is listed in the J Version 4
DoJ.)

While I saved the CS department's decsystem from being scrapped and still
operate it 24/7, my even earlier J Versions were binary-only (DOS), and
almost vanished along with the my office's PC-XT which mainly served
as terminal hooking into our Unix systems.

But I found a "floppies.tgz" from that time with J Version 2.9,
fired up "dosemu", and so here is a "pre-AA J:"

https://www.gaertner.de/~neitzel/img/no-aa-j29.jpg


The list of possible trains was the same for J Version 5.1 - J Version
7.  J Release 2 added further ones, such as A0 V1 V2.

J Release 5.1 [2002] did away with the more complex bi/tridents:

 * All tridents (dictionary Section II F) other than the
   verb-verb-verb case no longer work.  
 * All bidents (dictionary Section II F) other than the verb-verb,  
   adverb-adverb, and conjunction with an argument cases no longer  
   work.

IIRC, the reason stated for the removals was "are in the way for improved
debugging".  Did it improve?

(I am asking because I didn't bother to do anything with J Release 5.x/6.x
myself for licensing and src reasons.  I remained a happy camper with
J Rel. 4, and still run it on more obscure systems such as the Sharp
Zaurus.)

Martin Neitzel
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Adverbial Tacit Jym

2016-03-14 Thread neitzel
Pascal Jasmin wrote:
> a0 =:
> a1 =:

You are confusing the Jym with the Spoilarium, I'm afraid.

Martin Neitzel
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Feedback on beginner's code

2016-03-14 Thread neitzel
> As a fellow beginner (learning for well over a year, on and off), I'll
> show a way I would do it:
> isAnagramOf =: -:&:(-.&' '@:/:~@:tolower)

I'd like to add some advice for J newbies:

During the first two months (perhaps even two years, or two
decades), resist any urge to put more than five things to
the right of an =:

Factor out every small sub-unit you can.  That simplifies debugging A LOT.

Taking the above:

normalize_string =: -.&' '@:/:~@:tolower
isAnagramOf =: -:&:normalize_string

You certainly get the idea.  As you can see, the  -.&' '@:/:~@:tolower
has still way more than five words (namely 8) and I'm not really sure
that its author is aware that the ~ refers to not just the /: but
to the whole  -.&' '@:/:  pipeline to its left.

Again, smaller sub-units help to avoid such accidents:

sort =: /:~
de_space =: -.&' '
normalize =: de_space@sort@tolower
isAnagramOf =: -:

Almost every time, these tiny sub-units provide something useful even
beyond of the current context ("anagrams").  They are certainly easier
to test/verify.

It also makes reasoning about the ranks of the components easier.
In consequence, it becomes easier to make an educated selection
between  @ vs @:  or & vs &:  -- much better than to stick blindly
to some mysterious rule of thumb.

    Martin Neitzel
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Am I understanding m/y ?

2016-02-22 Thread neitzel
DoJ>m/y inserts successive verbs from the gerund m between items of y,
DoJ>extending m cyclically as required. Thus, +`*/i.6 is 0+1*2+3*4+5

RM> From the description, I would expect +`*/3 4 5 to give the result 3*4+5

I certainly read "successive verbs from the gerund", as "starting at
index 0", and I think we both agree that the example doesn't allow
it the other way around.

While I agree that "between items" is not 100% unambigously, the most
natural interpretation for me appears to be "from front to back of y",
as well.  So, for me, everything figures, and I don't see any bug.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] Nested structures. Idioms? Combinators?

2016-02-12 Thread neitzel
Matthew Baulch wrote:
>
> You're probably right that an ASCII name of its own would be better.
> Not many primitive names available, it seems. Oh well.

Infinitely many J primitive names are available.
From , [emphasis mine]: 

A primitive or primary may be denoted by a single graphic
(such as + for plus) or by a graphic modified by ONE OR MORE
following inflections (a period or colon), as in +. and +:
for or and nor. A primary may also be an inflected name, as in
e. and o. for membership and pi times.

This was a concious design decision.  There are already primitives with
more than one inflections [exercise: find them], which were added in
later times to the language.  The Words ;: scanner tokenizes according
to this rule, too.

So: it would be no problem to place new primitives at, say,

".:.:.

"::.

and call them CamelDo and PoodleDo, most easily to remember.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] "Gluing" rows together

2016-01-05 Thread neitzel
>z=. (((a0 ,: a1) , a2) , a3) , a4NB. "glue" rows together

 z=.a0 ,  a1  , a2  , a3 ,: a4NB. effects the same
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] 'Tis the Season...

2015-12-11 Thread neitzel
LAA>   S=: ')()))('
LAA>   f=: 13 :'(+/''(''=y)-+/'')''=y'
LAA>   f S
LAA>_6

This is coming near the solution I like best:

   +/ ('('&= - =&')')  S
_6

Why do like this?

(a) It is robust against any additional dirt characters, say, linebreaks
in S.  (Unlike the ').(' -based solutions.)

(b) It clearly states what makes Santa go up and down.

(c) It's so close to Roger's "Amuse-Bouche 0 of i. 16", namely
(x>0) - (x<0)

(d) It gives rise to further variations of the initial idea both
in the inside:

+/  -/ '()' =/  S,'still robust against noise'

and the outside (for Part B):

>: _1 i.~  +/\ ('('&= - =&')')  S

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] jconsole linux platform: delete / insert keys

2015-09-19 Thread neitzel
MK> On my Debian box in JConsole v7.01a (32-bit)
MK> when I press the [Delete] or [Insert] key on my keyboard
MK> I get a tilde [~] as output []

The ~ you are seeing is most likely what remains after the initial part
of the emitted character sequences ("\e[3~", "\e[2~") got interpreted
in some different way.  Both the readline library itself and terminal
emulators (such as xterm) can be made to treat the initial "\e["
special and that would need to be stopped.

MK> I found (under /etc/) a file called 'inputrc' which
MK> contains these lines:
MK> ...
MK> "\e[3~": delete-char
MK> "\e[2~": quoted-insert
MK> ...
MK> which according to what I've read up should do the job.

Instead of "quoted-insert", you want "overwrite-mode".

MK> Could somebody pse give some directions how to solve this..?

Just mail me your phone number to neit...@marshlabs.gaertner.de
(Ich spreche sogar ein bisschen Deutsch :-)

(Until then, you can use Ctrl-D to delete a single character.)

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] jconsole linux platform: delete / insert keys

2015-09-19 Thread neitzel
BL>  Did you mean ctrl-h?

No, meant ctrl-d.  ctrl-h = "backspace" deletes the character
to the left of the cursor.  Martin wants the Delete key to nuke
the character to the right of ("under" the cursor, in particular
if you are using a "block" cursor).  Ctrl-d will do that.

BL>  ctrl-d is for exit jconsole session.

Only if the ctrl-d is the very first character after a return,
i.e. when nothing is there yet you could delete.   As soon as
you enter some characters or use Cursor-Up / Ctrl-P to recall
earlier lines from the history, Ctrl-d will delete characters.

Martin

[This Ctrl-D "end-of-input" behaviour actually originates to the
earliest days of the unix tty driver.  A first ctrl-d "inside" of
a line will flush the partial line to the progam, you'd need a
second ctrl-d immediately following the first one to signal end
of input, without any newline at the end.]
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] jconsole linux platform: delete / insert keys

2015-09-19 Thread neitzel
BL>  Yes, ctrl-d only terminates a session at the begining of a line.
BL>  But ctrl-d in the middle of a line does not delete any
BL>  character in debian.

It certainly does that for me (debian, too).

Of course ctrl-d will do nothing if the cursor is at the end of the
line and there is no character to the right of the cursor.  Did you
move the the cursor back (Cursor-Left, ctrl-a, meta-b, whatever) after
entering your characters?

RETURN f o o b a r ctrl-b ctrl-b ctrl-b ctrl-d

should delete the "b".

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] linear boxed representation : A new representation format for mixed type words

2015-03-09 Thread neitzel
Pascal Jasmin wrote:
PJ
PJ if you want to pass a gerund (or boxed noun) to a function, it must
PJ either be all verbs (with single adverbs as strings permitted), or all
PJ nouns.  So this is possible.
PJ   '`a b c' =. '/';+`- 
PJ but it fails for an adverb phrase.
PJ   '`a b c' =. '/\';+`- 
PJ |spelling error

You are missing out on the more general notion of Atomic Representations.

Gerunds are arrays of verb ARs.  ARs are uniquely defined for *any* syntactic
class, though, and you are free to mix them:

   a =. +
   b =. -
   c =. /\
   d =. 42

   (ar =. 5!:1) ;:'a b c d'
+-+-+-+--+
|+|-|+-+-+|+-+--+|
| | ||5|+-+-+|||0|42||
| | || ||/|\|||+-+--+|
| | || |+-+-+||  |
| | |+-+-+|  |
+-+-+-+--+

   '`aa bb cc dd' =. ar ;:'a b c d'

   aa
+
   bb
-
   cc
/ \
   dd
42

   nameclass ;:'aa bb cc dd'
3 3 1 0

   (aa cc ,: bb cc) 1 2 3
1  3 6
1 _1 2

Further reading:  http://jsoftware.com/help/dictionary/dx005.htm
for 5!:1 (and, if you like, its reverse 5!:0);  then re-read
http://jsoftware.com/help/dictionary/d001.htm  to re-check
how the back-tick in '`a b c' is defined.

Further further reading:
Bernecky, Robert, and R.K.W. Hui, Gerunds and Representations, APL91, ACM.

Martin

PS:  Apropos reading:  I cannot read your (or anybody else's) message
parts with unicode box characters on the machine which receives the
newsified forum messages.  If you want me to be able to read those
message parts, please adhere to the Forum rules as stated in
http://www.jsoftware.com/jwiki/System/Forums:

**Formats**

The mailing lists send out emails in plain text format. For
best results, please send messages to the forum in this
format.

When copying J session output to an email, first set
box-drawing characters to Ascii. The IDEs have a menu item
for this, e.g. in J8 Qt, select View|Toggle Ascii Box
Drawing.

Having said that, and *not* having been able to read your code, just
guessing from your Subject:  I'm afraid you are re-inventing a wheel.


--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] speaking of amend...

2014-07-16 Thread neitzel
'Pascal Jasmin' asked:
what verb v (or I guess adverb is ok) could I use to get

    i.2 3 2 
 0  1 
 2  3 
 4  5 

 6  7 
 8  9 
10 11

0 1 1 v i. 2 3 2
0  1
8  9
10 11

So you want some bastard item merged out from the original ones.
This is exactly what monadic } will do, the difficult part is
moving from the rank-1 items in the DoJ example to your rank-2 items.

Instead of 0 1 1,  your merge selector has to be rank-2, too:

  0 0
  1 1
  1 1

Altogether:

   (,.~0 1 1)}  i. 2 3 2
 0  1
 8  9
10 11

For a single v encapsulation and general rank/shape case, things
become a bit ugly.  As adverb:

   v =. 1 : '((2}.$y) $1 0 m)} y'

   0 1 1 v  i. 2 3 5
 0  1  2  3  4
20 21 22 23 24
25 26 27 28 29

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm

Re: [Jprogramming] J as a calculator

2014-03-19 Thread neitzel
   1- %~/ +/ (100 5) * _2[\ (10 3 7.5 2)

1 - y  anti-truism/probability/fraction is   -. y

Martin

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Rank Nesting

2013-06-20 Thread neitzel
Ric Sherlock wrote:

 Explicitly defined verbs and verbs that include trains have default rank of
 _ _ _ , but that can be altered as part of the verb definition.

Rick and everybody else still doing this: please stop this misleading
wording!

A verb's rank CANNOT be altered.  Its rank is a fixed,
intrinsic property.

As the original poster correctly pointed out (and had to find out
the hard way), applying a rank conjunction creates a new verb with
the new, requested rank, wrapping around the original verb (with
its unaltered own rank still effective).  Any babbling of changing
ranks is too much of a simplification, and will give J newbies a
hard time in the long run.

Martin

[Is there something as a Frequently Given Complaint?  I seem to
be sending this message out every five years or so.]

--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] calling jj.dll

2013-06-20 Thread neitzel
Hi Raul,

The underlying mechanism only makes sense when mixing structure
elements which have different sizes.

I fail to understand this, probably because I lost track of the
original context.  (I.e., what is Greg trying to do?)

Still, if you can find any examples, it would be great to hear about them.

In response to Greg's question header size?, you pointed to

 https://github.com/openj/core/blob/master/jtype.h#L41 says:
 typedef struct {I k,flag,m,t,c,n,r,s[1];}* A;

Since Greg is somehow trying to cull J data from memory, I thought
it prudent to point out that the actual array data after the header
is not necessarily starting out directly after those SZ*I(7+r) bytes.
The relevant source is 30 lines down from the place you gave:

https://github.com/openj/core/blob/master/jtype.h#L70-77  says:

#if SY_64
#define AKX(x)  (SZI*(AH+AR(x)))
#define WP(t,n,r)   (AH+ r
+(1tLAST0)+((tNAME?sizeof(NM):0)+(n)*bp(t)+SZI-1)/SZI)
#else
#define AKX(x)  (SZI*(AH+AR(x)+!(1AR(x
#define WP(t,n,r)   
(AH+(r+!(1r))+(1tLAST0)+((tNAME?sizeof(NM):0)+(n)*bp(t)+SZI-1)/SZI)
#endif
/* make sure array values are double-word aligned */

This could be translated into:

On 32bit systems, some extra padding after odd-length shape vectors,
pretty please.

Showing an example is not that easy:

3!:1 and 3!:3 won't dump these bytes.  Anyhow, Greg should aware that
they *are* there.  (Or, when assembling arrays: is must be put there.)

(On earlier J systems, the jtype.h did not discriminate on SY_64 but
on SY_DOUBLE.  You could always set that just to be on the safe side.)

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] tcp/ip communication

2013-04-12 Thread neitzel
Greg Borota wrote:
 In q/k language you can start the interpreter like this:
 $ q -p 5001

Think Unix and combine jconsole with a tool that knows how
to interconnect stdin/stdout with TCP/IP.

For example, use netcat:

$ nc -l -p 5001 -c jconsole

To connect interactively to the interpreter, you can use netcat (nc),
too.

socket(1) is an older, netcat-like tool (I actually prefer this).

For an interactive client, telnet(1) will do, too.  You'll have to
adopt for the line endings, though.  This can be done either at the
nc/socket server side or by toggle outbinary at the telnet client.


For auto-running a J as a service, just use inetd(8):

On miles.marshlabs.gaertner.de (OLD FreeBSD 4.7, dual-stacked IPv4  IPv6):

neitzel 107  grep -w ^j /etc/services
j   5001/tcp   #j language.

neitzel 108  grep -w ^j /etc/inetd.conf
j   stream  tcp nowait  nobody  /usr/local/bin/jconsole jconsole
j   stream  tcp6nowait  nobody  /usr/local/bin/jconsole jconsole


On another host:

$ telnet miles.marshlabs.gaertner.de 5001
Trying 2a00:1030:1004:1000::166...
Connected to miles.marshlabs.gaertner.de.
Escape character is '^]'.
   i. 3 2 4
i. 3 2 4
 0  1  2  3
 4  5  6  7

 8  9 10 11
12 13 14 15

16 17 18 19
20 21 22 23

   exit 0
exit 0
Connection closed by foreign host.
$

Note that different releases of J handle I/O differently.  This
refers to if your input is echoed back (as above, J Rel. 4),
when your output is flushed, or how line-ends are treated.
(And don't get me started about the J startup scripts)

miles.marshlabs.gaertner.de is not running 24/7, but feel free to
probe it with a ping and, if it answered, connect to port 5001.
I'll disable the service again in May.

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm


Re: [Jprogramming] Matrix Transformations based on local submatrices

2012-11-14 Thread neitzel
I wrote:

 Solve the torus first:

   use |.to wiggle m up  down (and center),
   use |.1  to wiggle those matrices left  right (and center)

 ending up with 9 matrices, the original one and eight shifted ones [...]

|. will also accept a two element vector on the left side, specifing
both the up/down and left/right rotations in one go.  This extends
as usual to a 9x2 (or 3x3x2) wiggle table on the left, producing all
nine (or 3x3) plane shifts directly.

wiggles =. ,0/~  _1 0 1
+/+/ wiggles |. m

Martin
--
For information about J forums see http://www.jsoftware.com/forums.htm