Here's a rough breakdown of how J handles this code. Henry had already outlined most of this, but I'm thinking a bit more detail might help.
Step 1) extd =: 4 : 0 1A) J breaks this sentence into a sequence of 5 words extd is a name =: is a copula 4 is an integer : is a conjunction 0 is an integer 1B) J evaluates the sentence. This happens in two stages. The first stage is 4 : 0 which results in a dyad (more on this, below). The second stage is extd =: dyad (where dyad here is a placeholder for the result of 4 : 0). When J evaluates 4 : 0, it starts reading lines of script from the current session, and it preprocesses them (the details of this preprocessing is not documented anywhere that I'm familair with, though I've seen hints that it does happen). This continues until it encounters a right parenthesis on a line containing nothing other than whitespace. Step 2) 30 extd 180548043269214561950911457875657 2A) J breaks this sentence into a sequence of 3 words 30 is an integer extd is a name (which now refers to the dyad we had previously defined) 180548043269214561950911457875657 becomes a floating point number which would typically be displayed as 1.80548e32 but is actually 1.80548043269214573e32 2B) J executes the dyadic definition of extd. Here, x takes on the value 30 and y takes on that 1.80548e32 value (which is ignored, because the definition never refers to y). 3) and 2C) In the first line of extd, it reads a line of text from the current session and returns that line as a character string. '180548043269214561950911457875657' 4) and 2D) That character string has an x appended and it's then evaluated. Here, we have a sentence containing one word (180548043269214561950911457875657x), and that word is the result of extd. I hope this helps, -- Raul On Wed, Aug 16, 2023 at 9:00 AM Ak O <akin...@gmail.com> wrote: > > Hi guys, > > I hope you are all well. Thank you for continuing to look at this. > > Can you please explain through each step how this function is > parsed/processed? > Please run it. Give attention to your behavior through each step. > > > Step1. Function definition. Input the function > and hit crtl-Enter on the first line. > extd =: 4 : 0 > n=. ((1!:1) 1) > ((".@,&'x' n)) A. i. x > ) > > Step 2. Function execution with inputs. Input the value and hit ctrl-Enter. > 30 extd 180548043269214561950911457875657 > > Step 3. The function escapes for an input. Keyboard input. Input the > characters and hit Enter. > 180548043269214561950911457875657 > > Step 4. Result returned. > > > Thank you. > > > Ak > > > On Tue., Aug. 15, 2023, 08:02 Henry Rich, <henryhr...@gmail.com> wrote: > > > Yes, maybe that's where the wrongthink is. > > > > In J terminology, the sentence is first converted to /words/ (most > > languages call these 'tokens'), with the words /evaluated/ as far as > > they can be in isolation. Anything that would be called a > > /self-defining term/ is given a type at this stage. For example, > > > > * is evaluated to be a primitive verb > > & is evaluated to be a primitive conjunction > > ( is evaluated to ( > > 'abc' is evaluated to a noun > > 123x is evaluated to an extended integer > > 5 12345678901234567890 (a single word) is evaluated to a list of 2 > > floating-point integers > > > > non-self-defining words are given a special type: > > > > foo is evaluated to a name > > > > After the words have been given types and maybe values, they are > > processed right to left according to the parsing rules. During the > > parsing, a name is looked up and replaced by its stored type/value > > (except when it is followed by an assignment copula =. or =:). > > > > On 8/15/2023 9:51 AM, Raul Miller wr > > > > Henry Rich > > ote: > > > I think the inconsistency here is that you're thinking of a rather > > > elaborate parsing system used by some other language. > > > > > > Brief overview of J's parser: A sentence is parsed first by tokenizing > > > it (left to right), then the resulting array of tokens is passed to a > > > shift/reduce parser (right to left). Conversion of numbers from > > > "sequence of characters" to "1 or more numbers" happens during > > > tokenization. Verbs execute during the shift/reduce stage. > > > > > > See also https://www.jsoftware.com/help/dictionary/dicte.htm > > > > > > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm