Hi all!

The &&(And) in many languages is a control statement. If the left argument evaluates to false, the whole statement to the right is omitted.
As Raul says, ^: contains the corresponding logic.
This is how I think J works, without actually knowing all of it. I welcome all corrections. I wrote a similar interpreter. The verbs are passed only noun arguments. There is no functional left argument to *. which the verb could omit to execute. The parser curries the program. The interpreter does not see any brackets which it could omit executing. The parser works from left to right, the interpreter from right to left. The parse result is list of pointers to nouns and verbs that is interpreted/executed from right to left. The parser reads the statement until the first bracket start, the bracket contents are then parsed and interpreted/executed, the resulting noun is packed for later interpretation. All brackets are handled this way recursively until the end of the statement. Then the statement is interpreted/executed. The difference in the tacit case is that the execution is delayed. The bracket contents are packed in a composition, a new verb, a "single verb", which is executed by the nearest explicit parent statement. The pointer to this new verb is included in the list to be parsed, instead of it's noun result. *. in J is a scalar verb. All it receives is its scalar arguments. It could in theory omit executing the And if the right argument is zero, however, you would need an if statement and a comparison to do that and doing the And immediately is cheaper. Then there is a "hidden" rank-like program handling all scalar verbs. This program takes noun arguments and references to the scalar verb. What it executes is the C/C++ code corresponding to the scalar verb. The scalar verb does not actually exist as an entity. There are several corresponding entities - C/C++ programs. One for each type combination. This "hidden" rank-like program is highly optimized and it is very important to keep special cases out of it. You can read about this 'hidden' program here: https://github.com/andrimne/JWithATwist.DocBook/raw/master/target/en/JWithATwistReferenceManual.pdf
I call it the Dyadic Scalar Operation Helper program.
You could add new control structures, but it would be hard to combine a control structure with the present scalar And in J.

Cheers,
Erling Hellenäs

Den 2017-11-06 kl. 19:46, skrev Don Guinn:
Just curious. How much code would it take to determine that the left
argument need not be computed? If the probability is that the right
argument would be zero is very low, then the test would be wasting more
time than it saved for the improbable case. It makes sense to skip the left
argument evaluation if this evaluation were very complicated and took a lot
of time. But a good programmer would be aware of this case and would not
depend on the interpreter/compiler to take care of it for him.

On Mon, Nov 6, 2017 at 11:19 AM, Raul Miller <rauldmil...@gmail.com> wrote:

^: is J's short circuit operator.

we do not need to overload verbs for this. (Though I understand peer
pressure makes us want to incorporate features of other programming
languages which would cripple J.)

Thanks,

--
Raul


On Mon, Nov 6, 2017 at 12:41 PM, Moon S <moon.aka....@gmail.com> wrote:
It could be great to have and.  and or. in if. and while. conditions,
like
if. a~:0 and. b<x%a do. ... NB. or right to left? also a question
but I understand the rules for their combination would be difficult
and out of the language discipline.
A pity anyway.

On Mon, Nov 6, 2017 at 6:42 PM, 'Mike Day' via Programming
<programm...@jsoftware.com> wrote:
...not forgetting that *.  is least common multiple for integer
arguments.
eg

    12 *. 16
48

Mike

Please reply to mike_liz....@tiscali.co.uk.
Sent from my iPad

On 6 Nov 2017, at 11:35, Rudolf Sykora <rudolf.syk...@gmail.com>
wrote:
On 6 November 2017 at 12:21, Linda Alvord <lindaalvor...@outlook.com>
wrote:
Wasn't sure so I guess the answer is it gets evaluated:

Well, sometimes it doesn't:

(>:a) *. (0<a=.1)
2
(>:a) *. (0<a=.0)
0
(>:a) *. (0<a=._5)
0

Ruda
----------------------------------------------------------------------
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
----------------------------------------------------------------------
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

Reply via email to