From rff.rff at gmail.com Wed Oct 17 09:00:58 2007 From: rff.rff at gmail.com (gabriele renzi) Date: Wed, 17 Oct 2007 15:00:58 +0200 Subject: [gecoder-users] syntax idea Message-ID: <828083e70710170600x3efea407mf9b2d62adbe2e832@mail.gmail.com> Hi everyone, I just started to play with gecoder few hours ago, and it looks great, thanks to all the developers for it. But I was wondering if an alternate syntax had been thought, or maybe refused before. Basically, I was thinking of expressing constraint withouth the .must and using a subsequent Model#must or (#holds or #post) to post them to the constraint store. Kind of more functional and less OO if someone believes that OO just means .foo :) So the SENDMOREMONEY example would be: def initialize s,e,n,d,m,o,r,y = @letters = int_var_array(8, 0..9) holds equation_row(s, e, n, d) + equation_row(m, o, r, e) == equation_row(m, o, n, e, y) holds s > 0 holds m > 0 distinct @letters branch_on @letters, :variable => :smallest_size, :value => :min end it has the usual problem that != can't be overloaded in ruby 1.8, but it seems cleaner to me. I could work out a patch if wanted, but mostly, I was just curious about others' opinions on this. From rubyforge at lokorin.org Wed Oct 17 10:26:00 2007 From: rubyforge at lokorin.org (Andreas Launila) Date: Wed, 17 Oct 2007 16:26:00 +0200 Subject: [gecoder-users] syntax idea In-Reply-To: <828083e70710170600x3efea407mf9b2d62adbe2e832@mail.gmail.com> References: <828083e70710170600x3efea407mf9b2d62adbe2e832@mail.gmail.com> Message-ID: <47161B78.6010105@lokorin.org> gabriele renzi wrote: > But I was wondering if an alternate syntax had been thought, or maybe > refused before. > Basically, I was thinking of expressing constraint withouth the .must > and using a subsequent Model#must or (#holds or #post) to post them to > the constraint store. > > [...] > > it has the usual problem that != can't be overloaded in ruby 1.8, but > it seems cleaner to me. > Such a syntax was considered in the initial syntax discussion over at ruby-talk[1]. In the end the decision was mainly based on that must/must_not reads naturally for most constraints. One of the downsides is that the line must be read to understand what is being done, i.e. it's harder to quickly scan the lines with must/must_not than with holds. The syntax is however not nailed down yet and I do encourage a discussion about it. [1] http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/254467 -- Andreas Launila