Kevin J. Fletcher | 24 May 21:11
Picon
Gravatar

Extending a GTK+ Application with Guile

Hello Guilers.

I'm currently writing some prototype code before starting a project and
have a few questions that I hope some of you may be able to answer.

My intent is to add guile as a method of [optionally, at build time]
extending a GTK+ application. With the addition of being able to run
guile scripts I hope to provide a guile-shell to give real-time
interactive power. First a question of program architecture;

As the guile extensions are optional I run GTK on a main thread and the
shell on a second pthread. I connect the shell through a PTY to the
virtual terminal widget.

I apologise to those with mail clients not using monospace fonts.

  THREAD1            THREAD2
 ---------           -------
| GTK     |   pty   | guile |
|     VTE |<------->| shell |
|  -----  |          -------
| guile   |
|  scripts|
 ---------

0) Is there anything wrong with this architecture?

   a) Is it valid to use both scm_shell and other guile code at the same
   time or is scm_shell designed to run in isolation?

(Continue reading)

nrichard | 22 May 16:26
Picon

letter occurence in a text


hello my problem is to count occurence of letter in a text and come out with
an assoc-list like
'((a.16) (b.10) ... (z.5))
i started a fee function but they don't work so please help me

;; an alist
(define lettre '((""."") ) )
(define lettre2 '(("a". 1) ("b". 1) ("c". 1) ) )

;; this function take a key and an alist
;; add the key to the alist if it is not a space,a newline,and does not
already exist
;; update the value of the given key
(define (lettre-test x alist)
	(cond ((and 
          	( and (not (char=?  x #\space))(not (char=?  x #\newline)))   
          			(eq? (assoc (make-string 1 x) alist) #f))  
          	(set! alist
          		(assoc-set! alist (make-string 1 x) 0 )))
          	((char=?  x #\space) '())
          	((char=?  x #\newline) '())		 
           	(else
           	(set! alist   
       			(assoc-set! alist (make-string 1 x) (+ (assoc-ref alist
(make-string 1 x)) 1))))))
	
;; this function open a file
;; read the caracter and count the occurence of each character	
(define (compte-char source alist)	
(Continue reading)

Germán A. Arias | 20 May 14:31
Favicon

guile-lib test failed

With guile 2.0.5 installing guile-lib 0.2.1 ./configure and make
run without problems. But "make check" say one test failed. See
attached file. There are some spanish messages. I don't know how
configure it to display all in english. Regards.
Making check in src
make[1]: se ingresa al directorio `/home/german/Instalados/desde-codigo/guile-lib-0.2.1/src'
make[1]: No se hace nada para `check'.
make[1]: se sale del directorio `/home/german/Instalados/desde-codigo/guile-lib-0.2.1/src'
Making check in doc
make[1]: se ingresa al directorio `/home/german/Instalados/desde-codigo/guile-lib-0.2.1/doc'
make[1]: No se hace nada para `check'.
make[1]: se sale del directorio `/home/german/Instalados/desde-codigo/guile-lib-0.2.1/doc'
Making check in examples
make[1]: se ingresa al directorio `/home/german/Instalados/desde-codigo/guile-lib-0.2.1/examples'
make[1]: No se hace nada para `check'.
make[1]: se sale del directorio `/home/german/Instalados/desde-codigo/guile-lib-0.2.1/examples'
Making check in unit-tests
make[1]: se ingresa al directorio `/home/german/Instalados/desde-codigo/guile-lib-0.2.1/unit-tests'
make  check-TESTS
make[2]: se ingresa al directorio `/home/german/Instalados/desde-codigo/guile-lib-0.2.1/unit-tests'

Running test suite: main-suite ----------------------------------------

Running test suite: <test-api>-suite ----------------------------------
Running test case: test-api

;;; WARNING (New API, update your API form ((<test-api>)))

1 run, 0 failed
(Continue reading)

cong gu | 19 May 13:32
Picon

dynamic ffi and C struct

Hello,

Is it possible to use the current dynamic ffi to call a C function
whose parameter is a C struct (not a pointer to a C struct) ?

I cannot find much about it in the documentation.  After a brief look
at the source of foreign.c of guile, I found guile actually does some
parsing of nested argument list for `pointer->procedure' and generates
compound ffi types.  But I don't know the right data structure to give
when actually calling the foreign function.

For example, what should I do for the following function?

typedef struct {
  int dat[2];
} foo_t;

int func ( foo_t arg );

--

-- 
Cong Gu

Sunjoong Lee | 10 May 01:57
Picon
Gravatar

RE: guile-gnome-platform 2.16.2 released

Hello,


I'm glad to hear guile-gnome-platform works with Guile 2.0. To celebrate it, I've attatched my ebuild files for Gentoo Linux users. You know, Gentoo's last stable guile ebuild file is guile-1.8.8-r1.ebuild for Guile 1.8.8 but the last stable version of Guile itself is 2.0.5. There are guile-2.0.5.ebuild, g-wrap-1.9.14.ebuild and guile-gnome-platform-2.16.2.ebuild in my attatched file. You need a ebuild file for guile-lib 0.1.9 but it is in your default portage tree. If not so, sync your portage tree; "emerge --sync".

0. Update your system:
    # emerge --sync
    # emerge -uND world
    # emerge --depclean
    # revdep-rebuild

1. Put new ebuild files in your local portage overlay tree:
    # cp guile-gnome-platform-ebuild.tar.gz /usr/local
    # cd /usr/local
    # tar xvjf guile-gnome-platform-ebuild.tar.gz
    # rm guile-gnome-platform-ebuild.tar.gz

2. Check your PORTDIR_OVERLAY environment variable in /etc/make.conf file. I assume that:
    $ grep PORTDIR_OVERLAY /etc/make.conf
    PORTDIR_OVERLAY="/usr/local/portage"

3. Use ~x86 keyword in your Gentoo keyword file:
    # vi /etc/portage/package.keywords
    The contents of keyword file is:
    dev-libs/g-wrap ~x86
    dev-scheme/guile ~x86
    dev-scheme/guile-gnome-platform ~x86
    dev-scheme/guile-lib ~x86

4. Uninstall guile 1.8.8 if you had installed it:
    # emerge -C guile

5. Install guile-gnome-platform; emerge script will install guile, guile-lib and g-wrap for guile-gnome-platform:
    # emerge guile-gnome-platform
    # emerge --depclean
    # revdep-rebuild

2012/5/9 Andy Wingo <wingo <at> pobox.com>
Hello all,

I am pleased and embarrassed to announce the release of
guile-gnome-platform version 2.16.2.

Get it here:


Attachment (guile-gnome-platform-ebuild.tar.gz): application/x-gzip, 2878 bytes
Ludovic Courtès | 8 May 23:06
Picon

[ANN] Guile-Reader 0.6

Version 0.6 of Guile-Reader for Guile 2.0.x and 1.8.x is now available.
This release adds new features, most notably Guile 2.0 and Unicode support.

  http://dl.sv.nongnu.org/releases/guile-reader/guile-reader-0.6.tar.gz
  http://dl.sv.nongnu.org/releases/guile-reader/guile-reader-0.6.tar.gz.sig

SHA1 sums:

  aaedfe0c656775ba895b02293481a7d7c36b1f7e  guile-reader-0.6.tar.gz
  284404e6403d396819ff4e060d4a496f66727d8f  guile-reader-0.6.tar.gz.sig

Documentation is available from:

  http://www.nongnu.org/guile-reader/

Guile-Reader is a reader creation framework for Guile.  It can be
thought of as an alternative to Guile's built-in reader.  The purpose of
Guile-Reader is to allow for the creation of readers for different
variants of the Scheme/Lisp syntax.  Its design allows the re-use and
composition of various parts of a lexer called “token readers”.  It
comes with a library of re-usable token readers that can be used to
build a Scheme reader with various extensions.  For instance, syntax
extensions for DSSSL keywords, SRFI-30 block comments, SRFI-62 S-exp
comments, square-bracket S-exps, and brace S-exps are provided and
readily usable through the ‘make-alternate-guile-reader’ procedure.

Additionally, Guile-Reader aims to improve on Guile's reader sub-system
by allowing for the coexistence of several, potentially incompatible,
readers within a single Guile program.  In particular, it provides a
“confinement” mechanism that confines changes made via ‘read-set!’ and
‘read-hash-extend’ to the calling module.

New in Guile-Reader 0.6

  * Guile-Reader is now distributed under GPLv3 or later (instead of
    GPLv2 or later).

  * New token reader for R6RS-style syntax quotes: #', #`, and #,.

  * `make-guile-reader' returns a reader that understands SRFI-62
    s-exp comments, R6RS-style syntax quotes, and s-exps introduced by
    square brackets.  All these are supported by default by `read' in
    Guile 2.0.

  * On Guile 2.0, non-ASCII Unicode symbols, strings, characters, and
    Skribe-expressions are correctly read.

  * On Guile 2.0, Scheme source files are compiled and installed.

  * Bugs fixed

    * Add support for rationals in the number token reader.

    * Provide replacement for some `scm_i_' functions and other
      internals no longer accessible in Guile 1.9+.

    * Adjust packaging so that it works with Guile 1.9+.

Ludovic.
Sunjoong Lee | 6 May 09:39
Picon
Gravatar

http-read with cookie

Hello,


There is http-get in Guile and will be http-put, then what's the next? I think the method using cookie and handling https. I had thought that I'd be able to read contents of a web page needing login when I had read http-put of Greg Benison, http://lists.gnu.org/archive/html/guile-user/2012-04/msg00012.html . How naive am I.

I recognize we need handling https because most login process of web pages require it but have no idea of it now. During some trial, I made a very little effort and want to share it. Of course, there shold be the better way; I'm a newbie yet.

1.1 Exampe of http-get:

(receive (header body)
    (http-get (string->uri "http://code.google.com/"))
  (display header)
  (newline))
(receive (header body)
    (http-get (string->uri "http://code.google.com/"))
  (display header)
  (newline))

1.2 Output of above example:

#<<response> version: (1 . 1) code: 200 reason-phrase: "OK" headers: ((vary accept-language cookie referer) (content-type text/html (charset . "ISO-8859-1")) (etag "fe11bb5c119a4c282ecbc99fc66bc7f1" . #t) (last-modified . #<date nanosecond: 0 second: 41 minute: 20 hour: 23 day: 5 month: 5 year: 2012 zone-offset: 0>) (date . #<date nanosecond: 0 second: 9 minute: 3 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (expires . #<date nanosecond: 0 second: 9 minute: 3 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (cache-control private (max-age . 3600)) (x-content-type-options . "nosniff") (set-cookie . "PREF=ID=6d783c184a55e937:TM=1336287789:LM=1336287789:S=p7v3fPvc55hTb15k; expires=Tue, 06-May-2014 07:03:09 GMT; path=/; domain=.google.com") (server . "codesite_static_content") (x-xss-protection . "1; mode=block") (x-frame-options . "SAMEORIGIN") (connection close)) port: #<closed: file 0>>
#<<response> version: (1 . 1) code: 200 reason-phrase: "OK" headers: ((vary accept-language cookie referer) (content-type text/html (charset . "ISO-8859-1")) (etag "fe11bb5c119a4c282ecbc99fc66bc7f1" . #t) (last-modified . #<date nanosecond: 0 second: 46 minute: 32 hour: 4 day: 6 month: 5 year: 2012 zone-offset: 0>) (date . #<date nanosecond: 0 second: 10 minute: 3 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (expires . #<date nanosecond: 0 second: 10 minute: 3 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (cache-control private (max-age . 3600)) (x-content-type-options . "nosniff") (set-cookie . "PREF=ID=e7e80585317f6678:TM=1336287790:LM=1336287790:S=PQWgTbaxsZyIqeVy; expires=Tue, 06-May-2014 07:03:10 GMT; path=/; domain=.google.com") (server . "codesite_static_content") (x-xss-protection . "1; mode=block") (x-frame-options . "SAMEORIGIN") (connection close)) port: #<closed: file 0>>

1.3 Discussion about above output:
1) We need a web page using cookie. I picked http://code.google.com/ ; it set PREF cookie once unlike http://www.google.com/ twice.
2) Example displays two headers, so the output is two line. In the first line, http://code.google.com/ replied with set-cookie PREF. You may want to send cookie header when the next request. If not so, the server would re-send set-cookie PREF again as seen in second line.
3) Cookie header is essential when making a session. In above example, of course, actually no need to making a session, so no need cookie, it's just a test.

2.1 Example of http-read:

(receive (header body)
    (http-read "http://code.google.com/")
  (display header)
  (newline))
(receive (header body)
    (http-read "http://code.google.com/")
  (display header)
  (newline))

2.2 Output of above example:

#<<response> version: (1 . 1) code: 200 reason-phrase: "OK" headers: ((vary accept-language cookie referer) (content-type text/html (charset . "ISO-8859-1")) (etag "fe11bb5c119a4c282ecbc99fc66bc7f1" . #t) (last-modified . #<date nanosecond: 0 second: 46 minute: 32 hour: 4 day: 6 month: 5 year: 2012 zone-offset: 0>) (date . #<date nanosecond: 0 second: 58 minute: 23 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (expires . #<date nanosecond: 0 second: 58 minute: 23 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (cache-control private (max-age . 3600)) (x-content-type-options . "nosniff") (set-cookie . "PREF=ID=8253d36f6bcd8b99:TM=1336289038:LM=1336289038:S=xDYcthWhrVAC2asa; expires=Tue, 06-May-2014 07:23:58 GMT; path=/; domain=.google.com") (server . "codesite_static_content") (x-xss-protection . "1; mode=block") (x-frame-options . "SAMEORIGIN") (connection close)) port: #<closed: file 0>>
#<<response> version: (1 . 1) code: 200 reason-phrase: "OK" headers: ((vary accept-language cookie referer) (content-type text/html (charset . "ISO-8859-1")) (etag "fe11bb5c119a4c282ecbc99fc66bc7f1" . #t) (last-modified . #<date nanosecond: 0 second: 46 minute: 32 hour: 4 day: 6 month: 5 year: 2012 zone-offset: 0>) (date . #<date nanosecond: 0 second: 58 minute: 23 hour: 7 day: 6 month: 5 year: 2012 zone-offset: 0>) (expires . #<date nanosecond: 0 second: 58 minute: 23 hour: 8 day: 6 month: 5 year: 2012 zone-offset: 0>) (cache-control public (max-age . 3600)) (x-content-type-options . "nosniff") (server . "codesite_static_content") (x-xss-protection . "1; mode=block") (x-frame-options . "SAMEORIGIN") (connection close)) port: #<closed: file 0>>

2.3 Discussion about above output:

1) http-read can accept a string URL as it's first argument; of course, it can accept a uri object like result of string->uri.
2) In the first line, the server replied with set-cookie PREF like 1.2 but there is no second set-cookie PREF in the second line because http-read had sent cookie header when second request.

I had attatched a code of http-read.

Attachment (http-read.scm.gz): application/x-gzip, 2301 bytes
Sunjoong Lee | 3 May 17:50
Picon
Gravatar

Unbound variable: cond-expand-provide

Hello,


I thought cond-expand-provide be available in everywhere but saw a compile error, "ERROR: In procedure module-lookup: Unbound variable: cond-expand-provide". I don't know why this is happening; do you have any idea or comments? Thanks in advance.

test-load in attatched archive file is a script to load srfi-64.scm. This is very simple like this:

#!/usr/bin/guile \
-e main -s
!#
;;; Set %load-path
(eval-when
 (compile load eval)
 (let ((%current-filename (current-filename)))
   (if %current-filename
       (let ((%current-path (dirname %current-filename)))
         (if (not (memq %current-path %load-path))
             (add-to-load-path %current-path))))))
;;; Fake main for "-e main" option of Guile
(define (main . args)
  (let ((module (resolve-module '(test-load))))
    (apply (module-ref module 'main) args)))
;;; Module
(define-module (test-load)
  #:use-module (srfi srfi-64)
  #:export (main))
;;; Real main
(define (main args) #f)

In srfi-64.scm, I had used "(cond-expand-provide (current-module) '(srfi-64))" like other srfi modules.

Frist execution of above script is fine:
  $ ./test-load 
  ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
  ;;;       or pass the --no-auto-compile argument to disable.
  ;;; compiling /home/sunjoong/test-load/./test-load
  ;;; compiling /home/sunjoong/test-load/srfi/srfi-64.scm
  ;;; compiled /home/sunjoong/.cache/guile/ccache/2.0-LE-4-2.0/home/sunjoong/test-load/srfi/srfi-64.scm.go
  ;;; compiled /home/sunjoong/.cache/guile/ccache/2.0-LE-4-2.0/home/sunjoong/test-load/test-load.go

In second execution, I saw "Unbound variable: cond-expand-provide":
  $ ./test-load 
  Backtrace:
  In ice-9/boot-9.scm:
   149: 17 [catch #t #<catch-closure 96a8540> ...]
   157: 16 [#<procedure 96708c0 ()>]
  In unknown file:
     ?: 15 [catch-closure]
  In ice-9/boot-9.scm:
    63: 14 [call-with-prompt prompt0 ...]
  In ice-9/eval.scm:
   407: 13 [eval # #]
  In ice-9/boot-9.scm:
  2111: 12 [save-module-excursion #<procedure 965d040 at ice-9/boot-9.scm:3646:3 ()>]
  3653: 11 [#<procedure 965d040 at ice-9/boot-9.scm:3646:3 ()>]
  In unknown file:
     ?: 10 [load-compiled/vm "/home/sunjoong/.cache/guile/ccache/2.0-LE-4-2.0/home/sunjoong/test-load/test-load.go"]
  In /home/sunjoong/test-load/./test-load:
    20: 9 [#<procedure 96b6210 ()>]
  In ice-9/boot-9.scm:
  2667: 8 [define-module* (test-load) #:filename ...]
  2642: 7 [resolve-imports (((srfi srfi-64)))]
  2580: 6 [resolve-interface (srfi srfi-64) #:select ...]
  2505: 5 [#<procedure 966df60 at ice-9/boot-9.scm:2493:4 (name #:optional autoload version #:key ensure)> # ...]
  2772: 4 [try-module-autoload (srfi srfi-64) #f]
  2111: 3 [save-module-excursion #<procedure 96abcf0 at ice-9/boot-9.scm:2773:17 ()>]
  2783: 2 [#<procedure 96abcf0 at ice-9/boot-9.scm:2773:17 ()>]
  In unknown file:
     ?: 1 [primitive-load-path "srfi/srfi-64" #f]
  In srfi/srfi-64.scm:
    85: 0 [#<procedure 967d020 ()>]
  
  srfi/srfi-64.scm:85:2: In procedure #<procedure 967d020 ()>:
  srfi/srfi-64.scm:85:2: In procedure module-lookup: Unbound variable: cond-expand-provide

Attachment (test-load.tar.gz): application/x-gzip, 9 KiB
Sunjoong Lee | 1 May 17:20
Picon
Gravatar

Working http-get example and still unsolved problem

Hello,


It's 1st day of May, a new month; I thought it would be better to summarize some issues of http-get. This post include 3 examples; working, half working and not working because of implementation of declare-uri-header!

Example 1 - working

(use-modules (srfi srfi-8)
             ((web uri)    #:select (string->uri))
             ((web client) #:select (http-get)))

(set-port-encoding! (current-output-port) "UTF-8")
(fluid-set! %default-port-encoding "UTF-8")

(receive (res-headers res-body)
    (http-get (string->uri "http://www.gnu.org/software/guile/"))
  (display res-body)
  (newline))

1. receive is a macro to receive multi valued return of a certain procedure. http-get returns two values; headers of a web page and content of that.

2. (fluid-set! %default-port-encoding "UTF-8") is not needed in above case; codeset of http://www.gnu.org/software/guile/ is UTF-8 and above example only display it. I think it is a good habit to append this line if you want to use some other tools like html->sxml of guile-lib.

3. (set-port-encoding! (current-output-port) "UTF-8") is not needed in above case; codeset of http://www.gnu.org/software/guile/ is UTF-8 and written in plain english. I think it is a good habit to append this line if you want to display the content of web page.

Example 2 - half working

(receive (res-headers res-body)
    (http-get (string->uri "http://www.gnu.org/home.en.html"))
  (display res-body)
  (newline))

1. http-get of current stable version, 2.0.5,  of Guile does not support "Chunked Encoding."
2. You should apply patches of Ian Price's, http://lists.gnu.org/archive/html/guile-user/2011-11/msg00011.html , if this case.

Example 3 - not working

(receive (res-headers res-body)
    (http-get (string->uri "http://www.gnu.org/home.html")
              #:extra-headers
              (acons 'Accept-Language "en-US" '()))
  (display res-body)
  (newline))

2. Its Content-Location header is home.en.html, not http://www.gnu.org/home.en.html ; it is a relative URI, not absolute URI. There is no solution on current Guile if this case. Avoid this case and use a real web page like http://www.gnu.org/home.en.html .

Germán A. Arias | 1 May 07:53
Favicon

Problem with guile on Dragora

Hi, I'm testing guile 2.0.5 in a new system (www.dragora.org). The
compilation seems OK. But when I run guile I get:

bash-4.2$ guile
Backtrace:
In ice-9/boot-9.scm:
 149: 2 [catch #t #<catch-closure 830e510> ...]
 157: 1 [#<procedure 82dd8c0 ()>]
In unknown file:
   ?: 0 [catch-closure]

ERROR: In procedure catch-closure:
ERROR: Throw to key `decoding-error' with args `("scm_from_stringn"
"input locale conversion error" 22 #vu8(103 117 105 108 101))'.
bash-4.2$ 

Attached the config.log. Thanks in advance.
Attachment (log.tar.bz): application/x-bzip, 86 KiB
Sunjoong Lee | 27 Apr 23:13
Picon
Gravatar

I'm looking for a method of converting a string's character encoding

Hello,


I'm looking for a method of converting a string's character encoding from a certain codeset to utf-8. I know the string of Guile uses utf-8 and (read (open-bytevector-input-port (string->utf8 "hello"))) returns "hello" . But what if the string "hello" be encoded not utf-8 and you want to get utf-8 converted string? What I want is like iconv.

Background;
#:decode-body? keyword of http-get seems not to work properly; I should set #:decode-body? to false value and decode the contents body string manually. If a web page's charset be utf-8, there be no problem. If not, a problem occurs. decode-response-body of (web client) call decode-string with web page's charset. But real charset of bytevector is iso-8859-1, not web page's charset. If so, you should not let http-get use decode-response-body.

After getting response-body with bytevector form, you should decode it with "iso-8859-1" like decode-string's manner. Then you'll get web page's contents body string; it's charset is what you see in response header.

Now, I need to convert this contents body string to utf-8 but I don't know how. I think it would be with port i/o.

Thanks.


Gmane