H.]ere are Raul's two definitions,  f  and  g  and an explicit definition  h
which is turned  to tacit.
   n=:2
   d=:3
   n(f=:4 : 'x>+:(?]) x#y')d
1 0 0
0 1 0
   5!:4 <'f'
      -- 4               
-- : -+- ,:'x>+:(?]) x#y'
   n(g=:[>[:+:[:(?])#)d
0 1 0
1 0 0
   5!:4 <'g'
  -- [              
  +- >              
--+   -- [:         
  │   +- +:         
  L---+    -- [:    
      │    │    -- ?
      L----+----+- ]
           L- #     
   n(h=: 13 :'(-:x)>(]?])x#y')d
1 0 0
0 1 0
   5!:4 <'h'
      -- [:    
  ----+- -:    
  │   L- [     
  +- >         
--+   -- [:    
  │   │    -- ]
  L---+----+- ?
      │    L- ]
      L- #     
   f 
4 : 'x>+:(?]) x#y'
   g
[ > [: +: [: (? ]) #
   h
([: -: [) > [: (] ? ]) #


 I don't know why it took so long to notice I could do that. You might find
it helpful.

Linda


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Bo Jacoby
Sent: Friday, November 02, 2012 7:16 AM
To: [email protected]
Subject: Re: [Jprogramming] Arc consistency in J

Hi Mike
You request comments regarding style. Style is a matter of taste, so don't
take my comments as criticism. 
Your very first expression 

   (n%2)>(]?]) n$d
can be written without division:

   n>+:(?])n#dThe value depends on two variable, n and d, and so you may
create a dyadic verb, focusing attention on functions rather than on
variables.
   n( 4 : 'x>+:(?]) x#y')d

or, using tacit code:
   n([>[:+:[:(?])#)d


Your questions:

1) how do I avoid @ especially once we remove explicit arguments?
- by using cap. ([:)


4) Is there a good way to have named variables (ie. avoid getx, gety)?
replace
   getx   =: 0{ ]
   gety   =: 1{ ]
   revDom =: getx *. +./ @ (gety # [)
with
   revDom =: (0{ ]) *. +./ @ ((1{ ]) # [)


5) Why is a hook the default and not composition?
- Because J'ers love hooks! For composition use the capped fork ([: f g)

-Bo



>________________________________
> Fra: Michal D. <[email protected]>
>Til: [email protected]
>Sendt: 6:01 fredag den 2. november 2012
>Emne: [Jprogramming] Arc consistency in J
> 
>Hi All,
>
>I've managed to write my first not-completely-trivial program in J.  It 
>implements an arc consistency algorithm ( 
>http://en.wikipedia.org/wiki/Local_consistency#Arc_consistency).  I 
>would appreciate any comments regarding style, what I'm doing wrong in 
>J or how to improve the code.  I also have a couple of questions of my own:
>
>1) how do I avoid @ especially once we remove explicit arguments?
>2) how do I avoid constant boxing/unboxing due to fill (see arcsX)?
>3) Is a boxed value always a pointer? One could imagine implementing 
>'ragged' arrays without pointers.
>4) Is there a good way to have named variables (ie. avoid getx, gety)?
>5) Why is a hook the default and not composition?
>
>Code at: http://pastebin.com/k4XuKfFi
>
>Cheers!
>
>Mike
>----------------------------------------------------------------------
>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