unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* How to convert from Emacs Lisp to Guile
@ 2010-06-18  8:48 Cecil Westerhof
  2010-06-18 15:07 ` Ludovic Courtès
  0 siblings, 1 reply; 7+ messages in thread
From: Cecil Westerhof @ 2010-06-18  8:48 UTC (permalink / raw)
  To: guile-user

At the moment I have the following code in Emacs Lisp:
      (defun substitute-expression(input-file output-file reg-exp substitute-str)
        (let ((match-length))
          (switch-to-buffer (find-file-noselect input-file t t))
          (buffer-disable-undo)
          (while (re-search-forward reg-exp nil t)
            (setq match-length (- (point) (match-beginning 0)))
            (while (> match-length (length substitute-str))
              (setq substitute-str (concat substitute-str substitute-str)))
            (replace-match (substring substitute-str 0 match-length))
          )
          (write-region (point-min) (point-max) output-file)))

To get my first taste of writing in Guile (and evaluating if changing to
Guile is worthwhile) I was wondering how to do the same in Guile.

Also I use:
      (byte-compile '"'"'substitute-expression)

This compiles the function before it is executed, which speeds things
considerable up. Is this also possible with Guile?

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof



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

* Re: How to convert from Emacs Lisp to Guile
  2010-06-18  8:48 How to convert from Emacs Lisp to Guile Cecil Westerhof
@ 2010-06-18 15:07 ` Ludovic Courtès
  2010-06-18 17:19   ` Thien-Thi Nguyen
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2010-06-18 15:07 UTC (permalink / raw)
  To: guile-user

Hi,

Cecil Westerhof <Cecil@decebal.nl> writes:

> At the moment I have the following code in Emacs Lisp:
>       (defun substitute-expression(input-file output-file reg-exp substitute-str)
>         (let ((match-length))
>           (switch-to-buffer (find-file-noselect input-file t t))
>           (buffer-disable-undo)
>           (while (re-search-forward reg-exp nil t)
>             (setq match-length (- (point) (match-beginning 0)))
>             (while (> match-length (length substitute-str))
>               (setq substitute-str (concat substitute-str substitute-str)))
>             (replace-match (substring substitute-str 0 match-length))
>           )
>           (write-region (point-min) (point-max) output-file)))

There’s no such thing as a ‘buffer’ or ‘point’ in Guile so that would
need to be expressed, e.g., as a procedure that opens a file, reads it
line by line, writes modified lines to the output file, etc.

See the (ice-9 regex) and (ice-9 rdelim) modules for useful tools.

Thanks,
Ludo’.




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

* Re: How to convert from Emacs Lisp to Guile
  2010-06-18 15:07 ` Ludovic Courtès
@ 2010-06-18 17:19   ` Thien-Thi Nguyen
  2010-06-20 14:03     ` Ludovic Courtès
  0 siblings, 1 reply; 7+ messages in thread
From: Thien-Thi Nguyen @ 2010-06-18 17:19 UTC (permalink / raw)
  To: guile-user

() ludo@gnu.org (Ludovic Courtès)
() Fri, 18 Jun 2010 17:07:03 +0200

   There’s no such thing as a ‘buffer’ or ‘point’ in Guile so that would
   need to be expressed, e.g., as a procedure that opens a file, reads it
   line by line, writes modified lines to the output file, etc.

   See the (ice-9 regex) and (ice-9 rdelim) modules for useful tools.

Guile has module (ice-9 gap-buffer), which implements ‘buffer’ and ‘point’.
Guile 1.4.x has a more recent version, with more features.  Despite this,
it is still unibyte, and so could use an internals redesign.

Guile 1.4.x also has module (ice-9 editing-buffer), which wants to be
forward-ported (a good chance to redesign the internals, too).  

If anyone wants to tackle this syntax-oriented hack opportunity, feel free.
In particular, i (not being a syntax ninja) would love to learn from the
(ice-9 editing-buffer) internals redesign...

thi



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

* Re: How to convert from Emacs Lisp to Guile
  2010-06-18 17:19   ` Thien-Thi Nguyen
@ 2010-06-20 14:03     ` Ludovic Courtès
  2010-06-20 17:51       ` Thien-Thi Nguyen
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2010-06-20 14:03 UTC (permalink / raw)
  To: guile-user

Hi,

Thien-Thi Nguyen <ttn@gnuvola.org> writes:

> () ludo@gnu.org (Ludovic Courtès)
> () Fri, 18 Jun 2010 17:07:03 +0200
>
>    There’s no such thing as a ‘buffer’ or ‘point’ in Guile so that would
>    need to be expressed, e.g., as a procedure that opens a file, reads it
>    line by line, writes modified lines to the output file, etc.
>
>    See the (ice-9 regex) and (ice-9 rdelim) modules for useful tools.
>
> Guile has module (ice-9 gap-buffer), which implements ‘buffer’ and ‘point’.

Oh, nice.

Would you feel like documenting it in the manual and adding test cases?
:-)

Thanks,
Ludo’.




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

* Re: How to convert from Emacs Lisp to Guile
  2010-06-20 14:03     ` Ludovic Courtès
@ 2010-06-20 17:51       ` Thien-Thi Nguyen
  2010-06-20 19:06         ` Ludovic Courtès
  0 siblings, 1 reply; 7+ messages in thread
From: Thien-Thi Nguyen @ 2010-06-20 17:51 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-user

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

() ludo@gnu.org (Ludovic Courtès)
() Sun, 20 Jun 2010 16:03:02 +0200

   Would you feel like documenting it in the manual and adding test cases?

For Guile 1.4.x, there is already (online) documentation:
http://www.gnuvola.org/software/guile/doc/Module-Index.html

Where do you suggest this be placed in the Guile 2.x manual?

Please find attached the (simple) test cases file.
Tips on how/where to integrate it into Guile 2.x welcome.

For the record, i am willing to relax licensing from GPLv3+ to LGPL
for all changes relating to porting forward Guile 1.4.x stuff, so
you don't need to worry about that aspect.

thi

_____________________________________________________________

[-- Attachment #2: gap-buffer.test --]
[-- Type: application/octet-stream, Size: 3726 bytes --]

;;; gap-buffer.test                                     -*- scheme -*-

;; Copyright (C) 2004, 2007, 2009 Thien-Thi Nguyen
;;
;; This file is part of GUILE
;;
;; GUILE is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; GUILE is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this software; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

(use-modules (ice-9 gap-buffer))

(define gb:test:number 0)

(defmacro check-gb (point point-min point-max buffer-string)
  `(begin
     (set! gb:test:number (1+ gb:test:number))
     (pass-if (fs "~A gb->string" gb:test:number)
       (string=? (gb->string gb) ,buffer-string))
     (pass-if (fs "~A gb-point" gb:test:number)
       (= (gb-point gb) ,point))
     (pass-if (fs "~A gb-point-min" gb:test:number)
       (= (gb-point-min gb) ,point-min))
     (pass-if (fs "~A gb-point-max" gb:test:number)
       (= (gb-point-max gb) ,point-max))))

(let ((gb (make-gap-buffer)))
  (check-gb 1 1 1 "")
  (gb-insert-string! gb "nothing is real")
  (check-gb 16 1 16 "nothing is real")
  (gb-insert-char! gb #\space)
  (gb-insert-char! gb #\newline)
  (check-gb 18 1 18 "nothing is real \n")
  (gb-delete-char! gb 0)                ; does nothing
  (check-gb 18 1 18 "nothing is real \n")
  (gb-delete-char! gb 5)                ; does nothing
  (check-gb 18 1 18 "nothing is real \n")
  (gb-delete-char! gb -5)
  (check-gb 13 1 13 "nothing is r")
  (pass-if "goto-char 0" (zero? (gb-goto-char gb 0)))
  (check-gb 1 1 13 "nothing is r")
  (pass-if "goto-char 14" (= (gb-goto-char gb 14) 14))
  (check-gb 13 1 13 "nothing is r")
  (let ()
    (define (check-port-output beg end exp)
      (do ((pos (gb-point-min gb) (1+ pos)))
          ((= pos (gb-point-max gb)))
        (pass-if (fs "port-output(~A) ~A ~A" pos beg end)
          (string=? exp (call-with-tmpfile
                         (lambda (p) (gb->port! gb p beg end)))))))
    (check-port-output 1 13 "nothing is r")
    (check-port-output 3 11 "thing is")
    (check-port-output 1 10 "nothing i")
    (check-port-output 7 13 "g is r")
    (pass-if "port-output"
      (string=? "nothing is r" (call-with-tmpfile
                                (lambda (p) (gb->port! gb p))))))
  (gb-goto-char gb 1)
  (gb-insert-char! gb #\Z)
  (check-gb 2 1 14 "Znothing is r")
  (gb-delete-char! gb 1)
  (gb-goto-char gb 4)
  (gb-insert-char! gb #\t)
  (gb-delete-char! gb 1)
  (gb-goto-char gb (gb-point-max gb))
  (gb-insert-string! gb "adical!")
  (check-gb 20 1 20 "Zotting is radical!")
  (gb-goto-char gb 8)
  (with-output-to-port (make-gap-buffer-port gb)
    (lambda ()
      (display #\space) (display "hello world!")
      (newline) (display "Hacking")))
  (check-gb 29 1 41 "Zotting hello world!\nHacking is radical!")
  (gb-filter-lines! gb cdr)
  (check-gb 20 1 20 "Hacking is radical!")
  (gb-goto-char gb (gb-point-max gb))
  (gb-insert-char! gb #\newline)
  (check-gb 21 1 21 "Hacking is radical!\n")
  (gb-filter-lines! gb (lambda (lines)
                         (map (lambda (ln)
                                (number->string (string-length ln)))
                              lines)))
  (check-gb 5 1 5 "19\n0")
  (gb-erase! gb)
  (check-gb 1 1 1 ""))

;;; gap-buffer.test ends here

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

* Re: How to convert from Emacs Lisp to Guile
  2010-06-20 17:51       ` Thien-Thi Nguyen
@ 2010-06-20 19:06         ` Ludovic Courtès
  2010-06-20 19:33           ` Thien-Thi Nguyen
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2010-06-20 19:06 UTC (permalink / raw)
  To: Thien-Thi Nguyen; +Cc: guile-user

Hi!

Thien-Thi Nguyen <ttn@gnuvola.org> writes:

> For Guile 1.4.x, there is already (online) documentation:
> http://www.gnuvola.org/software/guile/doc/Module-Index.html

FWIW I’d prefer to avoid auto-extracted documentation.  Presumably it
would take a little bit of writing to provide more introductory text and
transitions between the different parts of the API.

> Where do you suggest this be placed in the Guile 2.x manual?

Perhaps under “Simple Generic Data Types”, after “Strings”.  What do you
think?

> Please find attached the (simple) test cases file.
> Tips on how/where to integrate it into Guile 2.x welcome.

Just drop it under ‘test-suite/tests’, with a ‘define-module’.  A few
comments on what the tests do would be welcome too as it looks a bit
dense at first sight.  :-)

> For the record, i am willing to relax licensing from GPLv3+ to LGPL
> for all changes relating to porting forward Guile 1.4.x stuff, so
> you don't need to worry about that aspect.

Excellent, thanks!

Ludo’.



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

* Re: How to convert from Emacs Lisp to Guile
  2010-06-20 19:06         ` Ludovic Courtès
@ 2010-06-20 19:33           ` Thien-Thi Nguyen
  0 siblings, 0 replies; 7+ messages in thread
From: Thien-Thi Nguyen @ 2010-06-20 19:33 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guile-user

() ludo@gnu.org (Ludovic Courtès)
() Sun, 20 Jun 2010 21:06:42 +0200

   FWIW I’d prefer to avoid auto-extracted documentation.  Presumably it
   would take a little bit of writing to provide more introductory text and
   transitions between the different parts of the API.

I understand.  It won't be difficult to fill things out this way.

   [placement]

   Perhaps under “Simple Generic Data Types”, after “Strings”.
   What do you think?

That doesn't seem right.  A gap-buffer is (conceptually) simple, but this
particular implementation is not generic in the sense that the only supported
fundamental type at the moment is the single ubyte (not even the character).

   [(simple) test cases file]

   Just drop it under ‘test-suite/tests’, with a ‘define-module’.  A few
   comments on what the tests do would be welcome too as it looks a bit
   dense at first sight.  :-)

OK.  I'll post a patch to guile-devel in the next few days.

thi



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

end of thread, other threads:[~2010-06-20 19:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-18  8:48 How to convert from Emacs Lisp to Guile Cecil Westerhof
2010-06-18 15:07 ` Ludovic Courtès
2010-06-18 17:19   ` Thien-Thi Nguyen
2010-06-20 14:03     ` Ludovic Courtès
2010-06-20 17:51       ` Thien-Thi Nguyen
2010-06-20 19:06         ` Ludovic Courtès
2010-06-20 19:33           ` Thien-Thi Nguyen

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).