[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Mutable strings (Was: Hash Table Collisions (n.runs-SA-2011.004)
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 10 Jan 2012 12:28:10 +0200
2012/1/10 Xavier Wang <weasley.wx@gmail.com>:
>
> I really think that a programming language should have two kinds of
> string: One for Symbol and One for really string.
>
> Symbol is used as hash-table key, flags, etc.
...
>
> String is a real byte array, It can be changed, It doesn't need using
> as hash-table key (but it could), It may be very long and has doesn't
> need to pre-calculate a hash, compare two really string is expensive,
> long String can use Copy-On-Write but it's not matter.
>
Is there going to be syntax for constructing "really string" literals?
If not, it can be implemented as a library operating on userdata,
rather like the `file:` functions.
Which metamethods should it have?
len, concat: like string
eq, le, lt: actual comparisons
add: bitwise `or`
sub: bitwise `nor`
mul: bitwise `and`
div: bitwise `nand`
unm: bitwise `not`
index: access to a byte
newindex: changing a byte
What about `xor`? `pow` and `mod` are so far unused, but have the
wrong precedence. This may require a language extension, e.g. binary
`not` using the tilde.
Hard to believe nobody has done something of the kind yet.