wouldn’t it be cool if you could define custom literal representations for your
classes?
Proposition:
have a method return a regex container/context that ruby would match against
garble that doesnt fall under any other category. the regular expression would
of
course yeild to a few constraints, a set of valid encapsilation/delimiting
characters, a sub-syntax, and have the groups passed (in order) to a custom
initializer:
class foo
def literal_exp
/^*(.?)*/ #or whatever
end
def literal_init(s1) @value = s1
end
def to_s @value
end
end
blah = rawwww
I haven’t really thought it out, but it could work, might be slugish, or
impractical, but it would be cool!#&(*@&#@!~!!!
Using ruby to solve domain specific issues. For example, 3D stuff need a
lot of matrices and vecotrs. It would be nice to have literal for those,
now I need to do
Vector.new(3,5,6)
This can get rather verbose in the long run, defining a literal would allow
me to do
<3,5,6>
or whatever.
Yes, this would definitely be cool. And useful. I am thinking this is
somehing that should have a file based scope: you would explicitly have to
enable the syntax in each file you want to use it in.
Perhaps the simples option would be to define ‘<’ … ‘>’ and some others
as used bindable lietarals. It would be artificially resticted, but much
more implementable then a totally general case.
– Nikodemus
···
On Wed, 30 Oct 2002, Peter Hickman wrote:
wouldn’t it be cool if you could define custom literal representations for your
classes?
What problem is this meant to solve as i cant see a use for such a thing.
wouldn’t it be cool if you could define custom literal representations for
your
classes?
What problem is this meant to solve as i cant see a use for such a thing.
well it could ‘solve’ a few problems, or rather simplify a few tasks.
one being persistence, if eval()'ing a database entry in your custom literal
format, returns a new object of your its classes type. it could get really
ugly, if you have 10,000, or even 10 classes with a coresponding literal
expression in one program, but in my mind that would be the developers fault,
not the fact that literal expressions are possible. I don’t have any idea ATM
how that would really even be implemented, just an idea.
And how would custom literals be scoped? Suppose one Ruby module
defines <x,y,z> to denote a 3D vector and another defines <r,g,b> to
denote an RGB colour, how would the programmer define which literal is
used? With classes you can explicitly name a fully qualified class,
import a class by name, or import under a different name by assigning a
class reference to a constant in the local module. But that cannot be
done at the syntax level.
Cheers,
Nat.
···
On Wed, 2002-10-30 at 11:41, Nikodemus Siivola wrote:
Using ruby to solve domain specific issues. For example, 3D stuff need a
lot of matrices and vecotrs. It would be nice to have literal for those,
now I need to do
Vector.new(3,5,6)
This can get rather verbose in the long run, defining a literal would allow
me to do
<3,5,6>
or whatever.
–
Dr. Nathaniel Pryce, Technical Director, B13media Ltd.
Studio 3a, 22-24 Highbury Grove, London N5 2EA, UK http://www.b13media.com
I think things like this can be implemented by individuals and not forced
into the standard Ruby. For example, I write my own SRuby so that I can
"preprocess" a file written in Python style with the output of a valid
Ruby code. In the same way, if we like “<3, 5, 6>” to be the notation for
a vector, we can simply preprocess it to be “Vector.new(3, 5, 6)”. It is
true that the algorithm/grammar/parser can get very complicated, but the
individual can control how complex he/she wants it to be.
Using ruby to solve domain specific issues. For example, 3D stuff need a
lot of matrices and vecotrs. It would be nice to have literal for those,
now I need to do
Vector.new(3,5,6)
This can get rather verbose in the long run, defining a literal would allow
me to do
<3,5,6>
or whatever.
Yes, this would definitely be cool. And useful. I am thinking this is
somehing that should have a file based scope: you would explicitly have to
enable the syntax in each file you want to use it in.
Perhaps the simples option would be to define ‘<’ … ‘>’ and some others
as used bindable lietarals. It would be artificially resticted, but much
more implementable then a totally general case.
Using ruby to solve domain specific issues. For example, 3D stuff need a
lot of matrices and vecotrs. It would be nice to have literal for those,
now I need to do
Vector.new(3,5,6)
This can get rather verbose in the long run, defining a literal would allow
me to do
<3,5,6>
or whatever.
But the former is far more readable.
Cheers,
Nat.
Another thing to remember is that you can always use
Vector[3,5,6]
which is even better. (This probably isn’t defined, of course, I don’t even
know what librrary we’re talking about, but you could define it yourself, and
ask your friendly library author to include it.)
Using ruby to solve domain specific issues. For example, 3D stuff need a
lot of matrices and vecotrs. It would be nice to have literal for those,
now I need to do
Vector.new(3,5,6)
This can get rather verbose in the long run, defining a literal would allow
me to do
<3,5,6>
or whatever.
Yes, this would definitely be cool. And useful. I am thinking this is
somehing that should have a file based scope: you would explicitly have to
enable the syntax in each file you want to use it in.
Perhaps the simples option would be to define ‘<’ … ‘>’ and some others
as used bindable lietarals. It would be artificially resticted, but much
more implementable then a totally general case.
Hi,
I think things like this can be implemented by individuals and not forced
into the standard Ruby. For example, I write my own SRuby so that I can
"preprocess" a file written in Python style with the output of a valid
Ruby code. In the same way, if we like “<3, 5, 6>” to be the notation for
a vector, we can simply preprocess it to be “Vector.new(3, 5, 6)”. It is
true that the algorithm/grammar/parser can get very complicated, but the
individual can control how complex he/she wants it to be.
If you really think this is a good idea, then you will really
like Perl6. IMHO, it’s the path to madness and the big reason
that I’ve decided that I need to learn a new language. To me
there is a significant value in restraint, language design need
to strike a balance between flexibility and expression. If you
create “per application or per programmer” languages and there
is a whole school of CS theory/practice about doing this, I
think you destroy much of the open community that developes
around a language.
There is a fundemental difference in philosophy that can’t be
resolved. IMHO, in the long run computer languages are just as
much about communicating with other programmers as about
communicating with the machine. One of the reasons we all
love Ruby is that it is very readable. While this proposal
is well intentioned, anything that compromises the readablity
of Ruby has to be looked at very carefully.