i am replying to this in both the programming forum (where it belongs) and the beta forum (where the original message appeared). Please respond only in the programming forum. (To make this easier, I am Bcc-ing the beta forum, but I do not know how forum software will change my mail headers.)
On Fri, Oct 28, 2011 at 9:15 PM, Andrew Pennebaker <[email protected]> wrote: > 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' > elseif. 1 do. > > 'd' (8!:0) & > end. > ) > fizzy 1 > exit '' control error is a syntax error which is unique to a control structure in an explicit definition. In this case, you are asking if. and elseif. to decide based on something that is not a noun. As Ric pointed out, you need to replace & with y in your definition of fizzy. I am going to suggest a couple other minor changes: div3 =: 0 = 3 & | div5 =: 0 = 5 & | div35 =: div3 *. div5 fizzy =: 3 : 0 if. div35 y do. 'FizzBuzz' elseif. div3 y do. 'Fizz' elseif. div5 y do. 'Buzz' elseif. do. ": y end. ) First, I encountered some strange characters in your code -- I replaced them with spaces. I do not know if they were in your original code or if they were in the mailer, but I suspect the mailer (perhaps even my mailer) based on the error message you reported. Second, there is no need for an explicit 1 in your elseif. clause, when you want unconditional execution. Also, if you just want a formatted number, ": y is easier to use than > 'd' 8!:0 y I hope this helps. -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
