Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 785271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:50:59+00:00 2026-05-14T20:50:59+00:00

Since I’m beginner in J I’ve decided to solve a simple task using this

  • 0

Since I’m beginner in J I’ve decided to solve a simple task using this language, in particular implementing the bubblesort algorithm. I know it’s not idiomatically to solve such kind of problem in functional languages, because it’s naturally solved using array element transposition in imperative languages like C, rather than constructing modified list in declarative languages. However this is the code I’ve written:

    (((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#)) ^: #

Here’s the structure of the statement:

┌────────────────────────────────────────────────────────────────────────────┬──┬─┐
│┌───────────────────────────────────────────────────────────────┬──┬───────┐│^:│#│
││┌───────────────────┬─┬───────────────────────────────────────┐│^:│┌─┬─┬─┐││  │ │
│││┌──────┬─┬────────┐│,│┌──┬─┬────────────────────────────────┐││  ││1│<│#│││  │ │
││││┌──┬─┐│@│┌─┬─┬──┐││ ││$:│@│┌───────────────────┬─┬────────┐│││  │└─┴─┴─┘││  │ │
│││││<.│/││ ││2│&│{.│││ ││  │ ││┌──────┬─┬────────┐│,│┌─┬─┬──┐││││  │       ││  │ │
││││└──┴─┘│ │└─┴─┴──┘││ ││  │ │││┌──┬─┐│@│┌─┬─┬──┐││ ││2│&│}.│││││  │       ││  │ │
│││└──────┴─┴────────┘│ ││  │ ││││>.│/││ ││2│&│{.│││ │└─┴─┴──┘││││  │       ││  │ │
│││                   │ ││  │ │││└──┴─┘│ │└─┴─┴──┘││ │        ││││  │       ││  │ │
│││                   │ ││  │ ││└──────┴─┴────────┘│ │        ││││  │       ││  │ │
│││                   │ ││  │ │└───────────────────┴─┴────────┘│││  │       ││  │ │
│││                   │ │└──┴─┴────────────────────────────────┘││  │       ││  │ │
││└───────────────────┴─┴───────────────────────────────────────┘│  │       ││  │ │
│└───────────────────────────────────────────────────────────────┴──┴───────┘│  │ │
└────────────────────────────────────────────────────────────────────────────┴──┴─┘

Let’s apply it to an array:

    (((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#)) ^: # 5 3 8 7 2
2 3 5 7 8

The thing that confuses me is $: referring to the statement within the outermost parentheses. Help says that:

$: denotes the longest verb that
contains it.

The other book (~ 300 KiB) says:

    3+4 
7  
    5*20  
100  

Symbols like + and * for plus and
times in the above phrases are called
verbs and represent functions. You may
have more than one verb in a J phrase,
in which case it is constructed like
a sentence in simple English by reading
from left to right
, that is
4+6%2 means 4 added to whatever follows, namely 6 divided by 2.

Let’s rewrite my code snippet omitting outermost ()s:

    ((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#) ^: # 5 3 8 7 2
2 3 5 7 8

Reuslts are the same. I couldn’t explain myself why this works, why only ((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#) is treated as the longest verb for $: but not the whole expression ((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#) ^: # and not just (<./@(2&{.)), $:@((>./@(2&{.)),2&}.), because if ((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#) is a verb, it should also form another verb after conjunction with #, i. e. one might treat the whole sentence (first snippet) as a verb. Probably there’s some limit for the verb length limited by one conjunction.

Look at the following code (from here):

    factorial =: (* factorial@<:) ^: (1&<)
    factorial 4
24

factorial within expression refers to the whole function, i. e. (* factorial@<:) ^: (1&<).

Following this example I’ve used a function name instead of $::

    bubblesort =: (((<./@(2&{.)), bubblesort@((>./@(2&{.)),2&}.)) ^: (1<#)) ^: #
    bubblesort 5 3 8 7 2
2 3 5 7 8

I expected bubblesort to refer to the whole function, but it doesn’t seem true for me since the result is correct.

Also I’d like to see other implementations if you have ones, even slightly refactored.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:51:00+00:00Added an answer on May 14, 2026 at 8:51 pm

    According to this reference (175 KiB) conjunction is:

    A part of speech that takes two
    arguments and typically results in a
    verb. For example, *:^:3 is a
    function that iterates squaring three
    times (^: is a conjunction).

    As ^: falls into above-mentioned category, applying it to the arguments results in the longer verb:

    ((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#)
    

    Because $: denotes the longest verb that contains it, it refers to the code just written above.

    Similarly, the next ^: makes a new longer verb from ((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#) and #:

    (((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#)) ^: #
    

    which in turn is referred to by $: because it’s longer than the previous one.

    Since it’s the undesirable behaviour, probably the only solution is to split the whole verb so that $: refers to the ((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#) though it’s not a oneliner:

        bubbleiter =: ((<./@(2&{.)), $:@((>./@(2&{.)),2&}.)) ^: (1<#)
        bubblesort =: bubbleiter ^: #
        bubblesort 3 1 2 9 2 9 86 5 9 6 9 6 45
    1 2 2 3 5 6 6 9 9 9 9 45 86
    

    This article has some comments as to $::

    Explaining what $: (self-reference)
    is and how it’s used turned out to be
    a rather unfortunate starting point
    for some of those completely new to
    the language as this is an advanced
    feature and is atypical of the way
    things are usually done in J. John
    mentioned that Roger has commented
    that he wouldn’t include this if he
    were designing the language now.

    Once more, to sum up:

    • ^: is a conjunction and makes a new verb from its arguments;
    • $: denotes the longest verb that contains it.

    Thanks fly out to estanford for dataset 3 1 2 9 2 9 86 5 9 6 9 6 45 in his answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 413k
  • Answers 413k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You've got two questions here: First, What's wrong with code?… May 15, 2026 at 8:26 am
  • Editorial Team
    Editorial Team added an answer Sorry to disappoint you but I did count by hand… May 15, 2026 at 8:26 am
  • Editorial Team
    Editorial Team added an answer Yeah, it is possible, I did it once. Just take… May 15, 2026 at 8:26 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.