unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* displaying UTF8 characters in and out of a script (guile 2.0.5)
@ 2012-12-16 19:22 msematman
  2012-12-16 20:04 ` David Pirotte
  0 siblings, 1 reply; 7+ messages in thread
From: msematman @ 2012-12-16 19:22 UTC (permalink / raw)
  To: guile-user

Dear all,

(display "Ćićolina") from the interactive session with the guile
interpreter correctly writes
Ćićolina to the standard output.

However, the same command in a script:

#!/usr/bin/guile \
-s
#!
(display "Ćićolina")

writes this out: ?i?olina

Obviously, there is something wrong with the output of UTF8 characters
in the case of the guile script.

In contrast, a similar bash script on my system (Debian Wheezy
GNU\Linux):

#!/bin/sh
echo "Ćićolina"

writes out the correct output. 

This indicates that there is probably nothing wrong with my locale
setting.

If anybody has any clue what actually went wrong , please let me know.

Cheers





-- 
  
  msematman@myopera.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: displaying UTF8 characters in and out of a script (guile 2.0.5)
  2012-12-16 19:22 displaying UTF8 characters in and out of a script (guile 2.0.5) msematman
@ 2012-12-16 20:04 ` David Pirotte
  2012-12-16 20:31   ` Mark H Weaver
  0 siblings, 1 reply; 7+ messages in thread
From: David Pirotte @ 2012-12-16 20:04 UTC (permalink / raw)
  To: msematman; +Cc: guile-user

Hello,

> However, the same command in a script:
> 
> #!/usr/bin/guile \
> -s
> #!
> (display "Ćićolina")
> 
> writes this out: ?i?olina

you need to set the port encoding first [for further info see section '6.14.1 Ports'
of the manual]:


	#!/bin/sh
	# -*- mode: scheme; coding: utf-8 -*-
	exec guile -e main -s $0 "$@"
	!#

	(define (main args)
	  (let ((port (current-output-port)))
	    (set-port-encoding! port "utf-8")
	    (display "Ćićolina\n" port)))

Cheers,
David



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: displaying UTF8 characters in and out of a script (guile 2.0.5)
  2012-12-16 20:04 ` David Pirotte
@ 2012-12-16 20:31   ` Mark H Weaver
  2012-12-17 12:18     ` msematman
  2013-01-13 11:02     ` Andy Wingo
  0 siblings, 2 replies; 7+ messages in thread
From: Mark H Weaver @ 2012-12-16 20:31 UTC (permalink / raw)
  To: msematman; +Cc: guile-user, David Pirotte

David Pirotte <david@altosw.be> writes:

>> However, the same command in a script:
>> 
>> #!/usr/bin/guile \
>> -s
>> #!
>> (display "Ćićolina")
>> 
>> writes this out: ?i?olina
>
> you need to set the port encoding first [for further info see section '6.14.1 Ports'
> of the manual]:

Unfortunately that is only a partial solution (it changes the encoding
of the current-output-port only, not for anything else), and it assumes
that the user wants UTF-8 output.

A more comprehensive solution is to put this:

  (setlocale LC_ALL "")

at the beginning of the script, which will set the locale according to
the user's settings (as specified by the environment variables).  This
is what Guile does when starting an interactive session, and what most
other interactive programs and scripting languages do as well.

Also, since your script contains non-ASCII characters, you should place
a coding declaration in the file so that Guile will know what encoding
to use when reading it.  If your script is in UTF-8, then put this in
the first 500 characters of the file:

  ;;; coding: utf-8

For more details, see:

  http://www.gnu.org/software/guile/manual/html_node/Character-Encoding-of-Source-Files.html

If you do these things, then your script should work properly even when
run by a user who has configured a non-UTF-8 locale.

   Regards,
     Mark



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: displaying UTF8 characters in and out of a script (guile 2.0.5)
  2012-12-16 20:31   ` Mark H Weaver
@ 2012-12-17 12:18     ` msematman
  2013-01-13 11:02     ` Andy Wingo
  1 sibling, 0 replies; 7+ messages in thread
From: msematman @ 2012-12-17 12:18 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user, David Pirotte



On Sun, Dec 16, 2012, at 09:31 PM, Mark H Weaver wrote:
> David Pirotte <david@altosw.be> writes:
> 
> >> However, the same command in a script:
> >> 
> >> #!/usr/bin/guile \
> >> -s
> >> #!
> >> (display "Ćićolina")
> >> 
> >> writes this out: ?i?olina
> >
> > you need to set the port encoding first [for further info see section '6.14.1 Ports'
> > of the manual]:
> 
> Unfortunately that is only a partial solution (it changes the encoding
> of the current-output-port only, not for anything else), and it assumes
> that the user wants UTF-8 output.
> 
> A more comprehensive solution is to put this:
> 
>   (setlocale LC_ALL "")
> 
> at the beginning of the script, which will set the locale according to
> the user's settings (as specified by the environment variables).  This
> is what Guile does when starting an interactive session, and what most
> other interactive programs and scripting languages do as well.
> 
> Also, since your script contains non-ASCII characters, you should place
> a coding declaration in the file so that Guile will know what encoding
> to use when reading it.  If your script is in UTF-8, then put this in
> the first 500 characters of the file:
> 
>   ;;; coding: utf-8
> 
> For more details, see:
> 
>   http://www.gnu.org/software/guile/manual/html_node/Character-Encoding-of-Source-Files.html
> 
> If you do these things, then your script should work properly even when
> run by a user who has configured a non-UTF-8 locale.
> 
>    Regards,
>      Mark

David, Mark,

Thanks for the detailed explanation, it works now.

Cheers

-- 
  
  msematman@myopera.com



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: displaying UTF8 characters in and out of a script (guile 2.0.5)
  2012-12-16 20:31   ` Mark H Weaver
  2012-12-17 12:18     ` msematman
@ 2013-01-13 11:02     ` Andy Wingo
  2013-01-13 18:12       ` Mark H Weaver
  2013-01-13 22:09       ` Ludovic Courtès
  1 sibling, 2 replies; 7+ messages in thread
From: Andy Wingo @ 2013-01-13 11:02 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guile-user, David Pirotte

On Sun 16 Dec 2012 21:31, Mark H Weaver <mhw@netris.org> writes:

> Also, since your script contains non-ASCII characters, you should place
> a coding declaration in the file so that Guile will know what encoding
> to use when reading it.  If your script is in UTF-8, then put this in
> the first 500 characters of the file:
>
>   ;;; coding: utf-8

I think the default is utf-8 now, correct?

Cheers,

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: displaying UTF8 characters in and out of a script (guile 2.0.5)
  2013-01-13 11:02     ` Andy Wingo
@ 2013-01-13 18:12       ` Mark H Weaver
  2013-01-13 22:09       ` Ludovic Courtès
  1 sibling, 0 replies; 7+ messages in thread
From: Mark H Weaver @ 2013-01-13 18:12 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-user, David Pirotte

Andy Wingo <wingo@pobox.com> writes:

> On Sun 16 Dec 2012 21:31, Mark H Weaver <mhw@netris.org> writes:
>
>> Also, since your script contains non-ASCII characters, you should place
>> a coding declaration in the file so that Guile will know what encoding
>> to use when reading it.  If your script is in UTF-8, then put this in
>> the first 500 characters of the file:
>>
>>   ;;; coding: utf-8
>
> I think the default is utf-8 now, correct?

Indeed, you are correct.  I did not know that!

    Thanks,
      Mark



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: displaying UTF8 characters in and out of a script (guile 2.0.5)
  2013-01-13 11:02     ` Andy Wingo
  2013-01-13 18:12       ` Mark H Weaver
@ 2013-01-13 22:09       ` Ludovic Courtès
  1 sibling, 0 replies; 7+ messages in thread
From: Ludovic Courtès @ 2013-01-13 22:09 UTC (permalink / raw)
  To: guile-user

Andy Wingo <wingo@pobox.com> skribis:

> On Sun 16 Dec 2012 21:31, Mark H Weaver <mhw@netris.org> writes:
>
>> Also, since your script contains non-ASCII characters, you should place
>> a coding declaration in the file so that Guile will know what encoding
>> to use when reading it.  If your script is in UTF-8, then put this in
>> the first 500 characters of the file:
>>
>>   ;;; coding: utf-8
>
> I think the default is utf-8 now, correct?

Yes.  I just noticed that it’s only stealthily mentioned under
“Compilation”:

     Each FILE is assumed to be UTF-8-encoded, unless it contains a
     coding declaration as recognized by `file-encoding' (*note
     Character Encoding of Source Files::).

Ludo’.




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-01-13 22:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-16 19:22 displaying UTF8 characters in and out of a script (guile 2.0.5) msematman
2012-12-16 20:04 ` David Pirotte
2012-12-16 20:31   ` Mark H Weaver
2012-12-17 12:18     ` msematman
2013-01-13 11:02     ` Andy Wingo
2013-01-13 18:12       ` Mark H Weaver
2013-01-13 22:09       ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).