how to alias keywords?

S

Sonja Kisa

It's easy to alias method names. Is there a way I can alias keywords
like if or end? I want to localize Ruby code to another human language
for learning/educational purposes.

Any way I can get ruby or to understand new synonyms for keywords?
 
I

Iñaki Baz Castillo

El Viernes, 18 de Diciembre de 2009, Sonja Kisa escribi=C3=B3:
It's easy to alias method names. Is there a way I can alias keywords
like if or end? I want to localize Ruby code to another human language
for learning/educational purposes.
=20
Any way I can get ruby or to understand new synonyms for keywords?

IMHO this is not possible at all.=20


=2D-=20
I=C3=B1aki Baz Castillo <[email protected]>
 
H

Haoqi Haoqi

you can do it like this:
def IF(condition)
if condition
yield
end
end

IF(true){
puts "yes"
}
 
S

Sonja Elen Kisa

From #ruby-lang on Freenode IRC tonight:

[21:44] <manveru> Sonja:
http://github.com/shyouhei/ruby/blob/trunk/parse.y#L10106-10154
[21:44] <argv[0]> right. you either get "if" or you get "somethingelse",
but not both
[21:45] <zenspider> if you want both, you'll have to declare both
english and otherlanguage as keywords and then modify the grammar
productions to accept both
[21:46] <argv[0]> yea, that.
[21:46] <argv[0]> which is not quite as easy
[21:46] <zenspider> essentially: if expr then? expr => (if|fi) expr
(then|neht)?
[21:46] <zenspider> just a bit tedious considering how f'd up the yacc
file is
[21:47] <zenspider> but start with something that isn't replicated in C
like class or module
[21:47] <zenspider> experiment with that one change
[21:47] <zenspider> and then expand
[21:48] <zenspider> should all just be algebraic changes, substitute A|B
for all A
[21:50] <zenspider> looks like the 1.9 (trunk) version is very cleaned
up... keyword_elsif... very easy to track down all versions then
[21:51] <zenspider> yacc kinda sucks... but we're stuck with it
(*cough*for now*cough*)
[21:52] <zenspider> my algebraic statement above isn't quite that easy
since yacc doesn't support EBNF productions cleanly... but you'll get it
[22:06] <argv[0]> Sonja this is about as good as it gets without messing
with parse.y http://gist.github.com/259256
 
F

Florian Gilcher

Maybe I need to edit parse.y or something.

Most definitely. But I don't see much of a point in it:

1. You will have to distribute the changed version of
Ruby by yourself. If the users have to run it on their
own computer, this can be a hassle.

2. The users will have a mismatch between their stuff
and every piece of ruby code out there, especially
tutorials and books, basically making self-tutoring
a pain.

3. You will have to make sure that "normal" Ruby code
still runs.

I don't know whether thats worth the hassle if your
course is not very "special interest".

Regards,
Florian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top