Look at https://code.jsoftware.com/wiki/Essays/Parentheses_Matching
and run the first  5 definitions.
Then run
   paren '(, ((72#:~8#2){~3#.\0,],0:)@{:)^:y ,: 1 y} (>:+:y) $ 0 '
(, ((72#:~8#2){~3#.\0,],0:)@{:)^:y ,: 1 y} (>:+:y) $ 0
    +--------+
   +----------------------+
+-----------------------------+            +-----+

try to understand the parenthised expressions from inside out (I don’t 
understand why 0 1 0 0 1 0 0 0 is replaced by 72#:~8#2).


R.E. Boss


-----Original Message-----
From: Programming <[email protected]> On Behalf Of 
Michail L. Liarmakopoulos
Sent: dinsdag 1 februari 2022 20:10
To: [email protected]
Subject: Re: [Jprogramming] Sierpinski triangle

Hello,

Besides dissect that I really like, Art's flowtree (
https://code.jsoftware.com/wiki/User:Art_Anger/FlowTree) looks pretty 
interesting too, but I haven't used it much yet.

Best regards,

On Tue, Feb 1, 2022 at 7:59 PM Hauke Rehr 
<[email protected]<mailto:[email protected]>> wrote:

> You already understood that some kinds of brackets don’t come in
> balanced pairs. But parentheses () nearly always do, the exceptions
> being inside of strings, obviously, and closing ) on a line of its own
> (which doesn’t occur here, so I won’t explain that).
> (oh, and {{…}} introduced another possibility)
>
> So there is no (, token nor is {~3#.\0,],0:)@{:)^:y comprehensible on
> its own.
>
> Use dissect in order to find out about the structure of this
> expression. (I hardly ever use dissect but Henry recommends using it
> for figuring out this kind of things.)
>
>
>  > - I could not find the meaning of certain tokens using the
> dictionary. For  > instance, what is (,? What is \0?
>
> \0 doesn’t have a meaning of its own either \ is an adverb and the
> following 0 is just that: zero.
> you asked for tokens – in J, you get them by
>
>     ;: '(, ((72#:~8#2){~3#.\0,],0:)@{:)^:y ,: 1 y} (>:+:y) $ 0 '
>
> ┌─┬─┬─┬─┬──┬──┬─┬─┬─┬─┬─┬─┬─┬─┬──┬─┬─┬─┬─┬─┬──┬─┬─┬──┬─┬──┬─┬──┬─┬─┬─┬
> ─┬──┬──┬─┬─┬─┬─┐
>
> │(│,│(│(│72│#:│~│8│#│2│)│{│~│3│#.│\│0│,│]│,│0:│)│@│{:│)│^:│y│,:│1│y│}│
> (│>:│+:│y│)│$│0│
>
> └─┴─┴─┴─┴──┴──┴─┴─┴─┴─┴─┴─┴─┴─┴──┴─┴─┴─┴─┴─┴──┴─┴─┴──┴─┴──┴─┴──┴─┴─┴─┴
> ─┴──┴──┴─┴─┴─┴─┘
>
> all of these you either already know (numeric constants, parens) or
> you can look up in the dictionary/vocabulary the 0: is not a constant,
> but a constant function: it always returns 0
>
> maybe you want to try understanding on your own so I won’t be
> explaining more (yet) you already understood some parts – go on that
> way
>
> (or ask for a full explanation once you’re too frustrated trying to
> figure it out for yourself)
>
> there are other ways to explore a sentence, as well (try suffixes;
> plug in different values for each occurrence of y; …)
>
>
>
> Am 01.02.22 um 19:31 schrieb Andrew P:
> > I have found in a forum the following J code that generates a
> > Sierpinski triangle, and am trying to understand how it works.
> >
> > sierpinski =: {{ (, ((72#:~8#2){~3#.\0,],0:)@{:)^:y ,: 1 y} (>:+:y)
> > $ 0
> }}
> >
> > ' #'{~ sierpinski 15
> >
> > #
> >
> > # #
> >
> > # #
> >
> > # # # #
> >
> > # #
> >
> > # # # #
> >
> > # # # #
> >
> > # # # # # # # #
> >
> > # #
> >
> > # # # #
> >
> > # # # #
> >
> > # # # # # # # #
> >
> > # # # #
> >
> > # # # # # # # #
> >
> > # # # # # # # #
> >
> > # # # # # # # # # # # # # # # #
> >
> >
> > I am a J novice and what I have gathered so far is that
> >
> > - {{ }} is an inline definition of a function. In this case a
> > monadic one with argument y.
> >
> > - Calling sierpinski 15 yields a matrix with 0s and 1s making the
> > shape
> of
> > a Sierpinski triangle.
> >
> > - ' #'{~ uses the 0s and 1s in that matrix as indexes for the ' #'
> > array, thus converting zeros to spaces and 1s to #s.
> >
> > - (>:+:y) is 2*y+1 (+: being 2* and >: being +1).
> >
> > - (72#:~8#2) is a weird way of generating the first 8 digits of 72
> > in
> base
> > 2. The digits are generated using the dyadic #: verb, with the
> > arguments switching sides with the ~ adverb.
> >
> >
> > The rest of the code is incomprehensible to me. In particular:
> >
> > - I could not find the meaning of certain tokens using the dictionary.
> For
> > instance, what is (,? What is \0?
> >
> > - This part of the program is so densely packed that I cannot even
> > break
> it
> > into pieces: {~3#.\0,],0:)@{:)^:y
> >
> >
> > I would be very grateful if someone could help me understand this code.
> > --------------------------------------------------------------------
> > -- For information about J forums see
> > http://www.jsoftware.com/forums.htm
>
> --
> ----------------------
> mail written using NEO
> neo-layout.org
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>


--
Michail L. Liarmakopoulos, MSc
Linkedin <https://www.linkedin.com/in/mlliarm/>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

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

Reply via email to