On Fri, Nov 2, 2012 at 1:01 AM, Michal D. <michal.dobrog...@gmail.com> wrote: > 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:
Personally, I use "mostly" coding guidelines. I recognize that there will need to be cases where I do not comply with my own guidelines, but I use these guidelines when I have no reason to do something different: No space between name and copula. This makes it easy to search for assignments to a name. Case of name represents type assigned to name. NOUNS, verbs, Adverbs/Conjunctions Feel free to ignore these... > 1) how do I avoid @ especially once we remove explicit arguments? @ is function composition. It looks ugly because J limits itself to ASCII sequences for its language. What we would ideally want is a character that looks like a small circle (but elevated slightly, to avoid confusion with the letter o) But ASCII itself is ugly -- ASCII's value is not its beauty but its ubiquity. That said, here are some equivalent cases: f@g f@:g"g ([: f g)"g f&g@(]"g) f&:g@(]"g) Depending on your context, you may be able to remove @(]"g) or "g and still retain equivalence, and additional equivalences may also be valid. For example: f@g y f&g y f&> <&g y > 2) how do I avoid constant boxing/unboxing due to fill (see arcsX)? Here are some alternative arcsX definitions: arcsX1=: [: ; [ ,.&.> { arcsX2=: [ ((#~ #@>) ,. ;@]) { > 3) Is a boxed value always a pointer? One could imagine implementing > 'ragged' arrays without pointers. That is how they are currently implemented, yes. > 4) Is there a good way to have named variables (ie. avoid getx, gety)? Define "good"... One option is to use explicit code -- the definition of "explicit code" is essentially "named variables". > 5) Why is a hook the default and not composition? It's historical: http://www.jsoftware.com/pipermail/general/2006-January/026271.html http://www.jsoftware.com/pipermail/general/2006-January/026274.html > Code at: http://pastebin.com/k4XuKfFi I have not taken the time to fully digest what you are doing there, but it's possible that by characterizing the data differently the expressions could be made more direct. I cannot guarantee this (because I have not taken the time to understand the purpose of what you are doing), but that has been my experience in many other contexts. FYI, -- Raul ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm