unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Interpreter Sessions (Newbie)
@ 2003-02-22 17:03 Pedro Ortega
  2003-02-22 17:53 ` Clinton Ebadi
  2003-02-22 22:26 ` dskr
  0 siblings, 2 replies; 7+ messages in thread
From: Pedro Ortega @ 2003-02-22 17:03 UTC (permalink / raw)


This has problably been asked before many times. Sorry,
but I didn't find anything in the Guile user manual about
this.

I'm currently programming a Chatbot, wich does execute
Scheme code to produce the answer, triggered by an input
string (something like A.L.I.C.E.). The Chatbot is server
based, so what I need is:

1. Given an user id, create (if it doesn't exist) or
   restore the environment (using a database or another
   persistent storage media).

2. Execute the Scheme code with the environment, in order
   to get the response string.

3. Respond to the user.

4. Save the updated environment.

This hasn't to be accomplished in parallel, querys can be
put in a queue and be responded serially.

Thanks for your help.

Pedro Ortega
IA Department,
University of Chile




_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: Interpreter Sessions (Newbie)
  2003-02-22 17:03 Interpreter Sessions (Newbie) Pedro Ortega
@ 2003-02-22 17:53 ` Clinton Ebadi
  2003-02-24 16:39   ` Paul Jarc
  2003-02-22 22:26 ` dskr
  1 sibling, 1 reply; 7+ messages in thread
From: Clinton Ebadi @ 2003-02-22 17:53 UTC (permalink / raw)


On Saturday 22 February 2003 12:03, Pedro Ortega wrote:
> 1. Given an user id, create (if it doesn't exist) or
>    restore the environment (using a database or another
>    persistent storage media).

You can do this with modules:

;;; (make-module size uses-list)
(define userid-module (make-module 1021 (list (resolve-module 
'(guile-user)))))

Now you have a module that has access to all the symbols from guile-user (you 
can add other modules to the uses-list, just use resolve-module to resolve 
the module from the name).

You can then pass userid-module as the second argument to eval or you can do 
things like:

(module-define! userid-module 'foo 5) ; foo now has the value 5 in 
userid-module

> 2. Execute the Scheme code with the environment, in order
>    to get the response string.

(eval "expression" userid-module)

Or I think you may be able to have different module set for each thread so you 
could give each user their own thread and do (set-current-module 
userid-module) in that thread (I'm not entirely sure because I don't use 
threads).

> 4. Save the updated environment.

You can't do this right now, although I could add support for serializing 
modules to my hacked together object serializer 
(http://unknownlamer.org/files/temp/serialize.scm) which I will be merging 
back into Guile-Web soon.

-- 
http://unknownlamer.org


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: Interpreter Sessions (Newbie)
  2003-02-22 17:03 Interpreter Sessions (Newbie) Pedro Ortega
  2003-02-22 17:53 ` Clinton Ebadi
@ 2003-02-22 22:26 ` dskr
  1 sibling, 0 replies; 7+ messages in thread
From: dskr @ 2003-02-22 22:26 UTC (permalink / raw)
  Cc: guile-user


Pedro,

I do a similar thing.

The easy part -- seperate domains for each user:
   (define interpreter-module (make-module))
   (define result (eval (+ 1 2 3) interpreter-module))

The hard part -- storing and loading that environment.
   Guile will let you get the symbols defined in a module (which you 
could then save)
     example:

(define module-get-matching-symbol-list (lambda (m r)
   "accept a module <m> and regexp <r> and return a list of symbols 
which match"
   (define cr (make-regexp r))
   (define little-helper (lambda (l acc)
     (if (eq? l '())
       acc
       (if (regexp-exec cr (object->string (car (car l))))
         ; the symbol name matched
         (little-helper (cdr l) (cons (car l) acc))
         ; the symbol name didn't match
         (little-helper (cdr l) acc)
       )
     )
   ))
   (define mgms-helper (lambda (l acc)
     (if (eq? l '())
       acc
       (if (eq? (car l) '())
         (mgms-helper (cdr l) acc)
         (mgms-helper (cdr l) (little-helper (car l) acc))
       )
     )
   ))

   (mgms-helper (array->list (module-obarray m)) '())
))

Regards,
	Dan Ridge

On Saturday, Feb 22, 2003, at 12:03 US/Eastern, Pedro Ortega wrote:

> This has problably been asked before many times. Sorry,
> but I didn't find anything in the Guile user manual about
> this.
>
> I'm currently programming a Chatbot, wich does execute
> Scheme code to produce the answer, triggered by an input
> string (something like A.L.I.C.E.). The Chatbot is server
> based, so what I need is:
>
> 1. Given an user id, create (if it doesn't exist) or
>    restore the environment (using a database or another
>    persistent storage media).
>
> 2. Execute the Scheme code with the environment, in order
>    to get the response string.
>
> 3. Respond to the user.
>
> 4. Save the updated environment.
>
> This hasn't to be accomplished in parallel, querys can be
> put in a queue and be responded serially.
>
> Thanks for your help.
>
> Pedro Ortega
> IA Department,
> University of Chile
>
>
>
>
> _______________________________________________
> Guile-user mailing list
> Guile-user@gnu.org
> http://mail.gnu.org/mailman/listinfo/guile-user
>



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: Interpreter Sessions (Newbie)
  2003-02-22 17:53 ` Clinton Ebadi
@ 2003-02-24 16:39   ` Paul Jarc
  2003-02-24 21:50     ` Clinton Ebadi
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Jarc @ 2003-02-24 16:39 UTC (permalink / raw)


Clinton Ebadi <clinton@unknownlamer.org> wrote:
> ;;; (make-module size uses-list)
> (define userid-module (make-module 1021 (list (resolve-module
> '(guile-user)))))

Hm... I've been using resolve-interface here, not resolve-module.
Does it make a difference?


paul


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: Interpreter Sessions (Newbie)
  2003-02-24 16:39   ` Paul Jarc
@ 2003-02-24 21:50     ` Clinton Ebadi
  2003-02-28 17:56       ` Paul Jarc
  0 siblings, 1 reply; 7+ messages in thread
From: Clinton Ebadi @ 2003-02-24 21:50 UTC (permalink / raw)


On Monday 24 February 2003 11:39, Paul Jarc wrote:
> Clinton Ebadi <clinton@unknownlamer.org> wrote:
> > ;;; (make-module size uses-list)
> > (define userid-module (make-module 1021 (list (resolve-module
> > '(guile-user)))))
>
> Hm... I've been using resolve-interface here, not resolve-module.
> Does it make a difference?

They do different things:

;; `resolve-interface' takes two keyword arguments:
;;
;;   #:select SELECTION
;;
;; SELECTION is a list of binding-specs to be imported; A binding-spec
;; is either a symbol or a pair of symbols (ORIG . SEEN), where ORIG
;; is the name in the used module and SEEN is the name in the using
;; module.  Note that SEEN is also passed through RENAMER, below.  The
;; default is to select all bindings.  If you specify no selection but
;; a renamer, only the bindings that already exist in the used module
;; are made available in the interface.  Bindings that are added later
;; are not picked up.
;;
;;   #:renamer RENAMER
;;
;; RENAMER is a procedure that takes a symbol and returns its new
;; name.  The default is to not perform any renaming.
;;
;; Signal "no code for module" error if module name is not resolvable
;; or its public interface is not available.  Signal "no binding"
;; error if selected binding does not exist in the used module.

resolve-module is used by resolve-interface to find the module and then load 
it.

-- 
http://unknownlamer.org


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: Interpreter Sessions (Newbie)
  2003-02-24 21:50     ` Clinton Ebadi
@ 2003-02-28 17:56       ` Paul Jarc
  2003-02-28 19:54         ` Clinton Ebadi
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Jarc @ 2003-02-28 17:56 UTC (permalink / raw)


Clinton Ebadi <clinton@unknownlamer.org> wrote:
> On Monday 24 February 2003 11:39, Paul Jarc wrote:
>> Clinton Ebadi <clinton@unknownlamer.org> wrote:
>>> ;;; (make-module size uses-list)
>>> (define userid-module (make-module 1021 (list (resolve-module
>>> '(guile-user)))))
>>
>> Hm... I've been using resolve-interface here, not resolve-module.
>> Does it make a difference?
>
> They do different things:

I know that.  What I'm not sure of is which one should be used with
make-module.  resolve-interface was suggested by Marius Vollmer:
<URL:http://article.gmane.org/gmane.lisp.guile.user/1222>
But I wonder if resolve-module would work equally well.  I suspect
that when the #:select and #:renamer areguments are not given,
resolve-interface is equivalent to resolve-module.


paul


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

* Re: Interpreter Sessions (Newbie)
  2003-02-28 17:56       ` Paul Jarc
@ 2003-02-28 19:54         ` Clinton Ebadi
  0 siblings, 0 replies; 7+ messages in thread
From: Clinton Ebadi @ 2003-02-28 19:54 UTC (permalink / raw)


On Friday 28 February 2003 12:56, Paul Jarc wrote:
> >> Hm... I've been using resolve-interface here, not resolve-module.
> >> Does it make a difference?
> >
> > They do different things:
>
> I know that.  What I'm not sure of is which one should be used with
> make-module.  resolve-interface was suggested by Marius Vollmer:
> <URL:http://article.gmane.org/gmane.lisp.guile.user/1222>
> But I wonder if resolve-module would work equally well.  I suspect
> that when the #:select and #:renamer areguments are not given,
> resolve-interface is equivalent to resolve-module.

They are equivalent when you don't use #:select or #:renamer (as far as I can 
tell from the source in ice-9/boot-9.scm)

-- 
http://unknownlamer.org


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


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

end of thread, other threads:[~2003-02-28 19:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-22 17:03 Interpreter Sessions (Newbie) Pedro Ortega
2003-02-22 17:53 ` Clinton Ebadi
2003-02-24 16:39   ` Paul Jarc
2003-02-24 21:50     ` Clinton Ebadi
2003-02-28 17:56       ` Paul Jarc
2003-02-28 19:54         ` Clinton Ebadi
2003-02-22 22:26 ` dskr

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