# Accentuated function names

**URL:** <https://www.ruby-forum.com/t/accentuated-function-names/155652>\
**Category:** Ruby\
**Created:** [December 15, 2008, 10:27am UTC](https://www.ruby-forum.com/t/accentuated-function-names/155652 "2008-12-15T10:27:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![djib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@djib](https://www.ruby-forum.com/u/djib)\
**Post date:** [December 15, 2008, 10:27am UTC](https://www.ruby-forum.com/t/accentuated-function-names/155652/1 "2008-12-15T10:27:55Z")

</div>

Hello,

I’ve started a new project in Ruby. For once, my sourcecode is not in  
English, but in French, and I’d like to know if its possible to have  
accentuated letters for function names in the sourcecode.

I have encoded my file in UTF-8 and it is parsed fine on Linux, but on  
Windows, I get warnings and errors:  
main.rb:16: Invalid char `\303’ in expression

Also, the accents do not display properly in the error messages:  
main.rb:34: syntax error, unexpected tFID, expecting ‘\n’ or ‘;’  
def apprâ”œÂ®cie?(voisin)  
(instead of “apprÃ©cie?(voisin)”)

Is there a way to specify sourcefile encoding? I could drop the accents  
in the source, but they make the code much more readable!

Thanks.

---

<div class="post-metadata">

**Author:** ![djib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@djib](https://www.ruby-forum.com/u/djib)\
**Post date:** [December 15, 2008, 11:54am UTC](https://www.ruby-forum.com/t/accentuated-function-names/155652/2 "2008-12-15T11:54:31Z")

</div>

2008/12/15 Jean-baptiste H¨¦tier [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> def appr©À(R)cie?(voisin)  
> (instead of “appr¨¦cie?(voisin)”)
> 
> Is there a way to specify sourcefile encoding? I could drop the accents  
> in the source, but they make the code much more readable!

IMHO it is generally a good idea to stick with 7 bit ASCII in source  
code. Also, I would never use my mother tongue for source code,  
partly because keywords are English anyway (even though Matz is  
Japanese) and partly because English is the lingua franca of IT. I  
know, this is not what you wanted to hear. 🙂

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![djib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@djib](https://www.ruby-forum.com/u/djib)\
**Post date:** [December 15, 2008, 12:03pm UTC](https://www.ruby-forum.com/t/accentuated-function-names/155652/3 "2008-12-15T12:03:40Z")

</div>

Robert K. wrote:

> IMHO it is generally a good idea to stick with 7 bit ASCII in source  
> code. Also, I would never use my mother tongue for source code,  
> partly because keywords are English anyway (even though Matz is  
> Japanese) and partly because English is the lingua franca of IT. I  
> know, this is not what you wanted to hear. 🙂

Thanks for your answer!

Yeah, I’ll probably switch back to English… but I’m still interested  
in a solution. In Python you can define the file encoding in some kind  
of file header:  
#!/usr/bin/python  
# -_- coding: -_-  
I’m sure there’s a way to do that in Ruby as well, but couldn’t find it  
anywhere ☹

---

<div class="post-metadata">

**Author:** ![djib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@djib](https://www.ruby-forum.com/u/djib)\
**Post date:** [December 15, 2008, 12:15pm UTC](https://www.ruby-forum.com/t/accentuated-function-names/155652/4 "2008-12-15T12:15:57Z")

</div>

Jean-baptiste HÃ©tier wrote:

> I’m sure there’s a way to do that in Ruby as well, but couldn’t find it  
> anywhere ☹

Mmmh, I just found the following link:  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/35569](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/35569)

It probably hasn’t been implemented yet… Oh well…

---

<div class="post-metadata">

**Author:** ![djib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@djib](https://www.ruby-forum.com/u/djib)\
**Post date:** [December 15, 2008, 12:21pm UTC](https://www.ruby-forum.com/t/accentuated-function-names/155652/5 "2008-12-15T12:21:28Z")

</div>

Le 15 décembre 2008 à 12:08, Jean-baptiste Hétier a écrit :

> Jean-baptiste Hétier wrote:
> 
> > I’m sure there’s a way to do that in Ruby as well, but couldn’t find it  
> > anywhere ☹
> 
> Mmmh, I just found the following link:  
> [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/35569](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/35569)
> 
> It probably hasn’t been implemented yet… Oh well…

It has. In Ruby 1.9.

Fred

---

<div class="post-metadata">

**Author:** ![djib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@djib](https://www.ruby-forum.com/u/djib)\
**Post date:** [December 15, 2008, 2:41pm UTC](https://www.ruby-forum.com/t/accentuated-function-names/155652/6 "2008-12-15T14:41:46Z")

</div>

Jean-baptiste Hétier [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> in a solution.  
> Ne te laisse pas dominer par le langage ! La solution c’est de passer  
> de MatzacredLisp à Common Lisp (par exemple: [http://clisp.cons.org](http://clisp.cons.org)) :

```
C/USER[4]> (defun décrémenter (x) (1- x))
DÉCRÉMENTER
C/USER[5]> (décrémenter 42)
41
C/USER[6]>

```

> In Python you can define the file encoding in some kind  
> of file header:  
> #!/usr/bin/python  
> # -_- coding: -_-  
> I’m sure there’s a way to do that in Ruby as well, but couldn’t find it  
> anywhere ☹

AFAIK, python doesn’t use that line.  
It’s emacs that uses to store buffer local variables.

All my scripts start with:

```
#!/usr/bin/clisp -ansi -q
;; -*- mode:lisp; coding:utf-8; -*-

```

---

<div class="post-metadata">

**Author:** ![djib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@djib](https://www.ruby-forum.com/u/djib)\
**Post date:** [December 15, 2008, 1:44pm UTC](https://www.ruby-forum.com/t/accentuated-function-names/155652/7 "2008-12-15T13:44:48Z")

</div>

F. Senault wrote:

> It has. In Ruby 1.9.

Excellent !  
Thanks Fred.

---

<div class="post-metadata">

**Author:** ![djib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3e96dc/32.png) [@djib](https://www.ruby-forum.com/u/djib)\
**Post date:** [December 15, 2008, 2:50pm UTC](https://www.ruby-forum.com/t/accentuated-function-names/155652/8 "2008-12-15T14:50:37Z")

</div>

In article [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid),  
Jean-baptiste HÃ©tier [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Yeah, I’ll probably switch back to English… but I’m still interested  
> in a solution. In Python you can define the file encoding in some kind  
> of file header:  
> #!/usr/bin/python  
> # -_- coding: -_-

As it was already said, 1.9 does support the Encoding string but for  
1.8, you may want to try adding “-Ku” to your Ruby invocation.

395 [14:46] roberto@roberto-al:/tmp\> ruby -Ku foo.rb  
Bonjour  
396 [14:46] roberto@roberto-al:/tmp\> cat foo.rb  
#! /opt/local/bin/ruby -Ku

# 

def Ã©tÃ©(foo)  
puts(foo)  
end

Ã©tÃ©(“Bonjour”)

With foo.rb written with utf-8 encoding.
