Nimrod programming language
Tomasz Rola
rtomek at ceti.com.pl
Sat May 16 23:32:46 EDT 2009
On Mon, 11 May 2009, kay at fiber-space.de wrote:
> On 12 Mai, 02:10, Tomasz Rola <rto... at ceti.com.pl> wrote:
> > On Mon, 11 May 2009, rump... at web.de wrote:
> > > > One question I ask myself upon seeing a new language is if it is possible
> > > > to program amb (amb=ambiguous) operator in it. This page gives a very
> > > > nice, "code first" explanation of amb and how it is supposed to work:
> >
> > > >http://www.randomhacks.net/articles/2005/10/11/amb-operator
> >
> > > Hm. I am not sure either. To me, it looks like a constraint solver by
> > > using brute force.
> >
> > Yes, kind of. From what I understand [1], it's goal is to simulate
> > nondeterministic "get right answer in one try", only this "one try"
> > requires browsing the solution space (because we have only "classic"
> > hardware). It is easy to use amb in wrong way, but I can see some cases
> > when I would like it.
>
> In Python you can use a generator expression. Dan Piponis example can
> be stated as
>
> g = ((i,j) for i in range(2,100) for j in range(2,i) if i*j == 481)
>
> which doesn't require any call/cc hacks but is a deterministic "get
> right in one try". Once Nimrod has coroutines it's just a matter of
> sugaring them into comprehensions.
Yep, to be frank everything complicated can be achieved by means of a
"for" loop (so said one friend of mine, and this is dirty, dirty way of
thinking). Or putting generators in a row... but try to do this trick
with ten of them and things start to look messy. Or ugly. Or both - and I
don't like neither.
There is another example, below Don Piponis' one. I like the look of
simplicity. I don't like ten or seven nested loops, that would have been
used instead. Perhaps amb could be somehow simulated with recursion, but
to use recursion in a language, I need to know it is safe and doesn't
overflow on 50th call. So, either I use the language that allows me to
express things in a way appealing to my taste, or I use something else and
perhaps end up with nested loops.
Besides, having search space defined with amb-statements may allow me to
try other ideas than brute-force search. Like, say, genetic algorithm
under the hood. No change to program, just link with other library (import
amb's definition from other path etc). I cannot imagine trying such trick
with nested loops without writing new program (writing new loop(s)).
Generators don't give me nice looking alternative to amb. So, if the
problem requires two or three nested loops, ok, I can go for it. If more -
I want another way out. Just my personal opinion, not forcing anybody to
follow.
However, the question I wanted to be answered, was how far Nimrod would
allow me to go. I've got my answer and, well, for some near future I will
just sit and see what happens. So, discussing amb's usefulness or if the
same ca be done with whatever else is not very interesting, because of
course everything can be done with loops - no need for continuations,
coroutines, recursion, macros etc.
Regards
Tomasz Rola
--
** A C programmer asked whether computer had Buddha's nature. **
** As the answer, master did "rm -rif" on the programmer's home **
** directory. And then the C programmer became enlightened... **
** **
** Tomasz Rola mailto:tomasz_rola at bigfoot.com **
More information about the Python-list
mailing list