I'm trying to make a function mod3 that returns the input modulo three, but
my syntax is wrong. I don't see why the syntax would be any different from
the double example in the docs.
$ jconsole
double =: * 2
double 1
2
double 2
4
double 3
6
mod3 =: 3 |
|syntax error
| mod3=:
mod3=: 3 | ]
mod3 11 5 3 2
2 2 0 2
2011/10/28 Andrew Pennebaker andrew.penneba...@gmail.com
I'm trying to make a function mod3 that returns the input modulo three, but
my syntax is wrong. I don't see why the syntax would be any different from
the double example in the docs.
$
mod3=: 3|
On Fri, Oct 28, 2011 at 10:54 AM, Andrew Pennebaker
andrew.penneba...@gmail.com wrote:
I'm trying to make a function mod3 that returns the input modulo three, but
my syntax is wrong. I don't see why the syntax would be any different from
the double example in the docs.
$ jconsole
You should post this in jprogramming.
In any case, it looks like you just juxtaposed a few characters.
mod3=: 3|
mod3 i.10
0 1 2 0 1 2 0 1 2 0
-Original Message-
From: beta-boun...@jsoftware.com [mailto:beta-boun...@jsoftware.com] On
Behalf Of Andrew Pennebaker
Sent: Friday,
Thanks Björn, Roger, and Lettow.
The docs imply that J and its predecessor APL use prefix/right-to-left
syntax. So I expected all J code to have the form:
operator operands
And therefore defining functions to be similar to stack languages, but in
reverse order.
myfunc =: operator
Infix is good if you have dyadic functions/operators. For example:
* +x y - x y
(x+y)*(x-y)
On Fri, Oct 28, 2011 at 12:50 PM, Andrew Pennebaker
andrew.penneba...@gmail.com wrote:
Thanks Björn, Roger, and Lettow.
The docs imply that J and its predecessor APL use prefix/right-to-left
On Fri, Oct 28, 2011 at 3:50 PM, Andrew Pennebaker
andrew.penneba...@gmail.com wrote:
Thanks Björn, Roger, and Lettow.
The docs imply that J and its predecessor APL use prefix/right-to-left
syntax. So I expected all J code to have the form:
operator operands
Which docs?
Anyways, my initial
Try
mod3=: 3|
-Original Message-
From: beta-boun...@jsoftware.com [mailto:beta-boun...@jsoftware.com] On
Behalf Of Andrew Pennebaker
Sent: Friday, October 28, 2011 12:54
To: J
Subject: [Jbeta] syntax for functions and modulo
I'm trying to make a function mod3 that returns the input
To get a feel for J, I'm implementing FizzBuzz, but I keep getting a control
error.
#!/usr/bin/env jconsole
div3 =: 0 = 3 |
div5 =: 0 = 5 |
div35 =: div3 *. div5
fizzy =: 3 : 0
if. div35 do.
'FizzBuzz'
elseif. div3 do.
'Fizz'
elseif. div5 do.
'Buzz'
Explicit definitions like fizzy require you to refer to the arguments
explicitly. The right argument is assigned to y locally within the
verb (right argument is assigned to x)
fizzy =: 3 : 0
if. div35 y do.
'FizzBuzz'
elseif. div3 y do.
'Fizz'
elseif. div5 y do.
Sorry just noticed that this is in the beta forum. Questions like this
would be better asked and answered in the programming forum.
On Sat, Oct 29, 2011 at 2:37 PM, Ric Sherlock tikk...@gmail.com wrote:
Explicit definitions like fizzy require you to refer to the arguments
explicitly. The right
11 matches
Mail list logo