Some beginner's questions

22 views
Skip to first unread message

Nat

unread,
Feb 16, 2009, 11:11:31 AM2/16/09
to Bertrand Constraint Programming Language
Hi. I have a couple of newbie questions.

1) What's the difference between "is" and "=". I know equals is more
general -- it can be used to constrain two expressions to be equal.
But for variables, what is the difference between "v is x + y" and "v
= x + y".

2) How do I represent the empty list in Bertrand?

Thanks for any help.

--Nat

Wm Leler

unread,
Feb 16, 2009, 1:13:03 PM2/16/09
to bertrand-...@googlegroups.com
You should never use the "is" operator in a constraint. The "is"
operator is what actually does binding.
When you say v is x + y, what happens is that all instances of v in
the subject expression are changed to x + y.
The "is" operator should be used only by the equation solver.

On the other hand, when you say "v = x + y" that expresses a
relationship between v, x, and y, and that constraint can be solved
for any of those variables. So it is just as likely that this gets
rewritten (by the equation solver) into "x = v - y" and then into "x
is v - y". Or it could be solved for y as well. The equals sign only
expresses a relationship, not assignment.

You can create any rules you want to express the empty list. You
could create a nullary operator called "nil" if you want, or something
else. It isn't built-in to Bertrand. A reasonable thing to do would
be to create a library for dealing with lists. For example, a list
could just be a comma-separated list of other things, i.e., "1, 2, 3".
Often, when you write rules for this kind of thing, you don't need a
representation for the empty list, since you have one rule that
matches a (comma separated) list and another rule that matches a
single element of the list. See the factorial rule for an example.

--wm

Nat

unread,
Feb 16, 2009, 2:01:24 PM2/16/09
to Bertrand Constraint Programming Language
Thanks. That explains a lot.

I am writing a list processing library, actually, inspired by the list
processing functions of Haskell, ML and Miranda.

--Nat

Wm Leler

unread,
Feb 16, 2009, 4:55:42 PM2/16/09
to bertrand-...@googlegroups.com
Cool!

The bops library defines the outfix operator [ ] to be "don't
evaluate", which I've never used. If you want to use [ ] as an
operator (like, for lists), just remove the definition in bops, or
change it to a prefix operator "noeval" or something like that.

--wm

Reply all
Reply to author
Forward
0 new messages