[erlang-questions] Why can't you have a variable before a string with pattern matching?

Fri Jun 1 05:25:21 CEST 2007

On 1 Jun 2007, at 10:58 am, Jordan Wilberding wrote:
> That [
	fcn(A ++ "x" ++ B)
> ] is actually what I was hoping to do. I guess it probably just isn't
> a good hope to have though in regards to efficiency. But it would make
> some code look nicer.

When I started learning Prolog, I knew some Interlisp, and Interlisp
has just such a feature.  (See chaper 23 of the 1983 edition of the
Interlisp manual.)  For example,
	X:(A:=$ 'x B:=$)
asks "does X match the pattern any list segment (save that in A)
followed by a literal x followed by any list segment (save that in B)."
One exercise I went through was trying to figure out how to express all
this in Prolog, with the intention of asking for Prolog to be  
extended. (This was back in 1979.)  By the time I finished the  
exercise, I didn't
want it any more, because I had learned how to do things better in  

The problem in Erlang really has nothing to do with efficiency.
Any Erlang pattern either matches a data structure ONE way, or it
doesn't match at all.  But consider
	"fax six faxes to sick foxes!"
The pattern (A++"x"++B) matches that in four different ways.  The code
that you think looks nicer, I think is confusing, because I don't know
which of those four you want or on what grounds.

Yet another reason for wanting a regular expression interface other
than text is that regular expressions make sense applied to things
other than strings.

More information about the erlang-questions mailing list