Why does python not have a mechanism for data hiding?

Luis Zarrabeitia kyrie at uh.cu
Sun Jun 8 12:00:15 EDT 2008


I don't know about Erlang (though I'd think it's behaviour sould be similar to
prolog), but at least in Prolog, yes, _ and _ are different variables. The whole
idea of "_" is that it is a placeholder that can bind to anything, but will be
immediately discarded. It's just syntactic sugar so you don't have to create new
names for things you don't care about, which could be a problem in prolog (once
bound, cannot be bound again on the same branch) or erlang (once bound, bound
forever).

I just tried on erlang:

f(0,_) -> 1+_;
f(X,_) -> X*f(X-1,_).

produces an error:

./t.erl:4: variable '_' is unbound
./t.erl:5: variable '_' is unbound

(referring to the right side uses of the _ symbol)

while the definition:

f(0,Y)->1+Y;
f(X,Y)->X*f(X-1,Y).

produces a [very weird, just for testing purposes, don't use it at home] version
of 'factorial'.

So, you understood well.

As I haven't been following this thread, I won't go offtopic talking about
functional languages. But yes, on functional (and declarative?) languages, it
makes a lot of sense to have a 'symbol' that represents a new variable any time
you use it.

Cheers,

-- 
Luis Zarrabeitia
Facultad de Matemática y Computación, UH
http://profesores.matcom.uh.cu/~kyrie


Quoting Roy Smith <roy at panix.com>:

> In article <slrng4nkq5.ihm.mdw at metalzone.distorted.org.uk>,
>  Mark Wooding <mdw at distorted.org.uk> wrote:
> 
> >   * Prolog and Erlang distinguish atoms from variables by the case of
> >     the first letter; also `_' is magical and is equivalent to a new
> >     variable name every time you use it.
> 
> Can you explain that in more detail?  A literal reading of what you wrote 
> would mean that if you did (assuming this is even legal syntax):
> 
>    _ = 1;
>    y = _;
> 
> the _'s are different variables, which is absurd enough to make me believe 
> I just misunderstood you.
> --
> http://mail.python.org/mailman/listinfo/python-list
> 




More information about the Python-list mailing list