On 13/02/2014 16:07, Daniele Varrazzo wrote:
On 2014-02-13 13:01, Carlos Catucci wrote:
1. Il tipo *string* si comporta come un *array di byte*, una volta
settati
sono immutabili. Cioè è illegale assegnare un valore a *&s[i]*.
A me sembra una cosa complicata, in C posso cambiare un carattere di un
array di caratteri (una stringa in pratica), e qui mi sembra sia vietato.
In C non esistono stringe. Quello che tu credi di fare ad una stringa lo
stai facendo ad un array di caratteri. Considerare una stringa un array
di cose comporta una serie di svantaggi, a cui forse siamo abituati, ma
svantaggi restano:
- sei legato all'implementazione del carattere (char, utf16, utf32)
Direi che lo stesso problema è presente, in parte, con Go:
http://golang.org/ref/spec#String_types
String types
A string type represents the set of string values. A string value is a
(possibly empty) sequence of bytes. Strings are immutable: once created,
it is impossible to change the contents of a string. The predeclared
string type is string.
The length of a string s (its size in bytes) can be discovered using the
built-in function len. The length is a compile-time constant if the
string is a constant. A string's bytes can be accessed by integer
indices 0 through len(s)-1. It is illegal to take the address of such an
element; if s[i] is the i'th byte of a string, &s[i] is invalid.
Quindi direi che le stringhe in Go non sono "vere" stringhe, come in Python:
http://play.golang.org/p/6Q7KoyuEA1
Il programma stampa 6, non 2 come mi sarei aspettato da un linguaggio
che supporta un tipo builtin per le stringhe.
Ciao Manlio
_______________________________________________
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python