unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* escaping characters
@ 2012-10-31 16:47 Kejia柯嘉
  2012-10-31 21:34 ` Ludovic Courtès
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Kejia柯嘉 @ 2012-10-31 16:47 UTC (permalink / raw)
  To: guile-user

hi,

is there a function that can escape of a string every character which
is an escape character?

thanks a lot.

-----------
kejia

☵☯☲



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

* Re: escaping characters
  2012-10-31 16:47 escaping characters Kejia柯嘉
@ 2012-10-31 21:34 ` Ludovic Courtès
  2012-11-01 14:24   ` Kejia柯嘉
  2012-11-01  2:12 ` nalaginrut
  2012-11-02 17:05 ` Ian Price
  2 siblings, 1 reply; 9+ messages in thread
From: Ludovic Courtès @ 2012-10-31 21:34 UTC (permalink / raw)
  To: guile-user

Hi,

Kejia柯嘉 <w.kejia@gmail.com> skribis:

> is there a function that can escape of a string every character which
> is an escape character?

What do you mean by “escape character”?

Ludo’.




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

* Re: escaping characters
  2012-10-31 16:47 escaping characters Kejia柯嘉
  2012-10-31 21:34 ` Ludovic Courtès
@ 2012-11-01  2:12 ` nalaginrut
  2012-11-02 17:05 ` Ian Price
  2 siblings, 0 replies; 9+ messages in thread
From: nalaginrut @ 2012-11-01  2:12 UTC (permalink / raw)
  To: Kejia柯嘉; +Cc: guile-user

I'm not sure what you mean, any example would be better.

Maybe you need 'read-delimited' in the (ice-9 rdelim)?
(call-with-input-string "abcd@efg"
  (lambda (port)
    (read-delimited "@,/ " port)))
==> abcd

Maybe it's not you need, as I said, some example to explain your thought
would be better.

On Wed, 2012-10-31 at 12:47 -0400, Kejia柯嘉 wrote:
> hi,
> 
> is there a function that can escape of a string every character which
> is an escape character?
> 
> thanks a lot.
> 
> -----------
> kejia
> 
> ☵☯☲
> 





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

* Re: escaping characters
  2012-10-31 21:34 ` Ludovic Courtès
@ 2012-11-01 14:24   ` Kejia柯嘉
  2012-11-01 18:14     ` Thien-Thi Nguyen
  2012-11-02 21:57     ` Ludovic Courtès
  0 siblings, 2 replies; 9+ messages in thread
From: Kejia柯嘉 @ 2012-11-01 14:24 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-user

hi all,

for an example, when a program reads in a latex source, is there an
escape function that can rewrite all `\' to `\\', `"' to `\"', and so
on?

thank you.

kejia

☵☯☲


2012/10/31 Ludovic Courtès <ludo@gnu.org>:
> Hi,
>
> Kejia柯嘉 <w.kejia@gmail.com> skribis:
>
>> is there a function that can escape of a string every character which
>> is an escape character?
>
> What do you mean by “escape character”?
>
> Ludo’.
>
>



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

* Re: escaping characters
  2012-11-01 14:24   ` Kejia柯嘉
@ 2012-11-01 18:14     ` Thien-Thi Nguyen
  2012-11-01 18:41       ` Noah Lavine
  2012-11-02 21:57     ` Ludovic Courtès
  1 sibling, 1 reply; 9+ messages in thread
From: Thien-Thi Nguyen @ 2012-11-01 18:14 UTC (permalink / raw)
  To: Kejia柯嘉; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1840 bytes --]


() Kejia柯嘉 <w.kejia@gmail.com>
() Thu, 1 Nov 2012 10:24:52 -0400

   for an example, when a program reads in a latex source, is there an
   escape function that can rewrite all `\' to `\\', `"' to `\"', and so
   on?

This kind of escaping for backslash and double-quote (and other chars,
depending on Guile flavor) is built-in for ‘(object->string STRING)’,
but anything else (the "and so on" bit) you have to define for yourself,
or find something already defined.

For example, Guile-BAUX provides module ‘(guile-baux write-string)’
which exports proc ‘write-string’ that handles twelve additional
characters:

http://www.gnuvola.org/software/guile-baux/guile-baux.html.gz#write_002dstring 

Another example is Guile-PG module ‘(database postgres-qcons)’, which
has all manner of procs to DTRT for various "and so on" cases:

http://www.nongnu.org/guile-pg/doc/qcons-quoting.html#qcons-quoting       

I think it would be nice for these procs (and perhaps your LaTeX
oriented one, once defined) to be rebased onto a general one, hosted
apart from any particular Guile version (perhaps Guile-Lib -- is that
project still viable?).

Or maybe i'm missing something already out there by now.  I remember
fruitlessly searching a number of years back, but things may have
changed since then.  Here's some related discussion:

http://lists.gnu.org/archive/html/guile-user/2012-01/msg00114.html

[cc trimmed]

-- 
Thien-Thi Nguyen ..................................... GPG key: 4C807502
.                  NB: ttn at glug dot org is not me                   .
.                 (and has not been since 2007 or so)                  .
.                        ACCEPT NO SUBSTITUTES                         .
........... please send technical questions to mailing lists ...........


[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: escaping characters
  2012-11-01 18:14     ` Thien-Thi Nguyen
@ 2012-11-01 18:41       ` Noah Lavine
  0 siblings, 0 replies; 9+ messages in thread
From: Noah Lavine @ 2012-11-01 18:41 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: Guile Mailing List

[-- Attachment #1: Type: text/plain, Size: 2523 bytes --]

This is related to what ttn said, but I am a bit confused by the request.
Normally when you read *in* something like LaTeX source, you convert \\ to
\, and similar things. Then when you write *out* LaTeX source, you might
convert \ to \\. This is useful if, for instance, you want Guile to
automatically generate some LaTeX and then write it in a form that TeX will
read. Kejia seems to be asking for the opposite.

I certainly agree that it would be useful to have a general function for
this (and the reverse).

Noah


On Thu, Nov 1, 2012 at 2:14 PM, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:

>
> () Kejia柯嘉 <w.kejia@gmail.com>
> () Thu, 1 Nov 2012 10:24:52 -0400
>
>    for an example, when a program reads in a latex source, is there an
>    escape function that can rewrite all `\' to `\\', `"' to `\"', and so
>    on?
>
> This kind of escaping for backslash and double-quote (and other chars,
> depending on Guile flavor) is built-in for ‘(object->string STRING)’,
> but anything else (the "and so on" bit) you have to define for yourself,
> or find something already defined.
>
> For example, Guile-BAUX provides module ‘(guile-baux write-string)’
> which exports proc ‘write-string’ that handles twelve additional
> characters:
>
>
> http://www.gnuvola.org/software/guile-baux/guile-baux.html.gz#write_002dstring
>
> Another example is Guile-PG module ‘(database postgres-qcons)’, which
> has all manner of procs to DTRT for various "and so on" cases:
>
> http://www.nongnu.org/guile-pg/doc/qcons-quoting.html#qcons-quoting
>
> I think it would be nice for these procs (and perhaps your LaTeX
> oriented one, once defined) to be rebased onto a general one, hosted
> apart from any particular Guile version (perhaps Guile-Lib -- is that
> project still viable?).
>
> Or maybe i'm missing something already out there by now.  I remember
> fruitlessly searching a number of years back, but things may have
> changed since then.  Here's some related discussion:
>
> http://lists.gnu.org/archive/html/guile-user/2012-01/msg00114.html
>
> [cc trimmed]
>
> --
> Thien-Thi Nguyen ..................................... GPG key: 4C807502
> .                  NB: ttn at glug dot org is not me                   .
> .                 (and has not been since 2007 or so)                  .
> .                        ACCEPT NO SUBSTITUTES                         .
> ........... please send technical questions to mailing lists ...........
>
>

[-- Attachment #2: Type: text/html, Size: 3479 bytes --]

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

* Re: escaping characters
  2012-10-31 16:47 escaping characters Kejia柯嘉
  2012-10-31 21:34 ` Ludovic Courtès
  2012-11-01  2:12 ` nalaginrut
@ 2012-11-02 17:05 ` Ian Price
  2012-11-02 22:06   ` Ludovic Courtès
  2 siblings, 1 reply; 9+ messages in thread
From: Ian Price @ 2012-11-02 17:05 UTC (permalink / raw)
  To: Kejia柯嘉; +Cc: guile-user

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=iso-2022-jp-2, Size: 1407 bytes --]

Kejia^[$B[I2E^[(B <w.kejia@gmail.com> writes:

> hi,
>
> is there a function that can escape of a string every character which
> is an escape character?
>
> thanks a lot.

Oleg Kiselyov has a function called 'make-char-quotator' which, I think,
does what you want. Guile does not technically export it, but you can
access it through (@@ (sxml simple) make-char-quotator)

(define make-char-quotator (@@ (sxml simple) make-char-quotator))

;; make-char-quotator takes an alist of character + string pairs
;; the character is the one to escape, and the string its replacement
;; it returns a function of two arguments, a string to escape, and a
;; port to write to.

(define my-weird-escaper
  (make-char-quotator
   '((#\' . "''")
     (#\~ . "\\~")
     (#\& . "{ampersand}"))))

(call-with-output-string
 (lambda (p)
   (my-weird-escaper
    "this is an example of how to use 'make-char-quotator' ~ it is not representative of any particular escaping mechanism I know of & I certainly hope none similar to it exists" p)))

outputs
    
"this is an example of how to use ''make^[$B!]^[(Bchar^[$B!]^[(Bquotator'' \\^[$(C!-^[(B it is not representative of any particular escaping mechanism I know of {ampersand} I certainly hope none similar to it exists"

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



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

* Re: escaping characters
  2012-11-01 14:24   ` Kejia柯嘉
  2012-11-01 18:14     ` Thien-Thi Nguyen
@ 2012-11-02 21:57     ` Ludovic Courtès
  1 sibling, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2012-11-02 21:57 UTC (permalink / raw)
  To: Kejia柯嘉; +Cc: guile-user

Hi,

Kejia柯嘉 <w.kejia@gmail.com> skribis:

> for an example, when a program reads in a latex source, is there an
> escape function that can rewrite all `\' to `\\', `"' to `\"', and so
> on?

So no, Guile doesn’t have any function related to TeX/LaTeX escaping.

Ludo’.



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

* Re: escaping characters
  2012-11-02 17:05 ` Ian Price
@ 2012-11-02 22:06   ` Ludovic Courtès
  0 siblings, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2012-11-02 22:06 UTC (permalink / raw)
  To: guile-user

Ian Price <ianprice90@googlemail.com> skribis:

> ;; make-char-quotator takes an alist of character + string pairs
> ;; the character is the one to escape, and the string its replacement
> ;; it returns a function of two arguments, a string to escape, and a
> ;; port to write to.
>
> (define my-weird-escaper
>   (make-char-quotator
>    '((#\' . "''")
>      (#\~ . "\\~")
>      (#\& . "{ampersand}"))))

Oh, there’s actually something similar in Skribilo (inherited from
Skribe) called ‘make-string-replace’:

  http://git.savannah.gnu.org/cgit/skribilo.git/tree/src/guile/skribilo/utils/strings.scm#n129
  http://git.savannah.gnu.org/cgit/skribilo.git/tree/src/guile/skribilo/engine/latex.scm#n52

Thanks,
Ludo’.




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

end of thread, other threads:[~2012-11-02 22:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-31 16:47 escaping characters Kejia柯嘉
2012-10-31 21:34 ` Ludovic Courtès
2012-11-01 14:24   ` Kejia柯嘉
2012-11-01 18:14     ` Thien-Thi Nguyen
2012-11-01 18:41       ` Noah Lavine
2012-11-02 21:57     ` Ludovic Courtès
2012-11-01  2:12 ` nalaginrut
2012-11-02 17:05 ` Ian Price
2012-11-02 22:06   ` 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).