unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Interactive programming with Event Loop?
@ 2017-09-30  5:23 Christopher Howard
  2017-09-30  8:24 ` Mark H Weaver
  2017-10-06 13:01 ` Thompson, David
  0 siblings, 2 replies; 5+ messages in thread
From: Christopher Howard @ 2017-09-30  5:23 UTC (permalink / raw)
  To: Guile User Mailing List

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

Hi, I want to code a game using theChickadee framework, but I want to
do it in an interactive programming environment, where I can evaluate
things in the REPL while the Chickadee kernel is running, rather than
needing to restart the kernel after each modification. The Chickadee
kernel runs update hooks every so many milliseconds, so I think I just
need to figure out a way to communicate code to an update hook, that it
could execute. What would be the simplest and/or most sensible way to
do this? (Threads? IPC? Communicate to a network port?)

-- 
https://qlfiles.net
https://emailselfdefense.fsf.org/en/

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: Interactive programming with Event Loop?
  2017-09-30  5:23 Interactive programming with Event Loop? Christopher Howard
@ 2017-09-30  8:24 ` Mark H Weaver
  2017-10-06 13:01 ` Thompson, David
  1 sibling, 0 replies; 5+ messages in thread
From: Mark H Weaver @ 2017-09-30  8:24 UTC (permalink / raw)
  To: Christopher Howard; +Cc: Guile User Mailing List

Christopher Howard <christopher.howard@qlfiles.net> writes:

> Hi, I want to code a game using theChickadee framework, but I want to
> do it in an interactive programming environment, where I can evaluate
> things in the REPL while the Chickadee kernel is running, rather than
> needing to restart the kernel after each modification. The Chickadee
> kernel runs update hooks every so many milliseconds, so I think I just
> need to figure out a way to communicate code to an update hook, that it
> could execute. What would be the simplest and/or most sensible way to
> do this? (Threads? IPC? Communicate to a network port?)

Take a look at section 6.18.14 (Cooperative REPL Servers) of the Guile
reference manual.

      Mark



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

* Re: Interactive programming with Event Loop?
  2017-09-30  5:23 Interactive programming with Event Loop? Christopher Howard
  2017-09-30  8:24 ` Mark H Weaver
@ 2017-10-06 13:01 ` Thompson, David
  2017-10-06 15:53   ` Christopher Howard
  1 sibling, 1 reply; 5+ messages in thread
From: Thompson, David @ 2017-10-06 13:01 UTC (permalink / raw)
  To: Christopher Howard; +Cc: Guile User Mailing List

Hello Christopher,

On Sat, Sep 30, 2017 at 1:23 AM, Christopher Howard
<christopher.howard@qlfiles.net> wrote:
> Hi, I want to code a game using theChickadee framework, but I want to
> do it in an interactive programming environment, where I can evaluate
> things in the REPL while the Chickadee kernel is running, rather than
> needing to restart the kernel after each modification. The Chickadee
> kernel runs update hooks every so many milliseconds, so I think I just
> need to figure out a way to communicate code to an update hook, that it
> could execute. What would be the simplest and/or most sensible way to
> do this? (Threads? IPC? Communicate to a network port?)

Mark is right that a cooperative REPL server is the answer here.  We
both worked on that feature a few years ago for exactly this purpose.

Here is a simple example program that has a REPL server added in:

    (use-modules (chickadee)
                 (chickadee math vector)
                 (chickadee render sprite)
                 (chickadee render texture)
                 (system repl coop-server))

    (define sprite #f)
    (define repl #f)

    (define (load)
      (set! sprite (load-image "images/chickadee.png"))
      (set! repl (spawn-coop-repl-server)))

    (define (draw alpha)
      (draw-sprite sprite (vec2 256.0 176.0)))

    (define (update dt)
      (poll-coop-repl-server repl))

    (add-hook! load-hook load)
    (add-hook! update-hook update)
    (add-hook! draw-hook draw)
    (add-hook! quit-hook abort-game)

    (run-game)

Once the program is running, you can connect to the REPL server over a
tcp socket on port 37146.  If you use Geiser, which I highly
recommend, just run `M-x connect-to-guile` and use the default
connection settings.

Hope this helps,

- Dave



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

* Re: Interactive programming with Event Loop?
  2017-10-06 13:01 ` Thompson, David
@ 2017-10-06 15:53   ` Christopher Howard
  2017-10-06 16:11     ` Thompson, David
  0 siblings, 1 reply; 5+ messages in thread
From: Christopher Howard @ 2017-10-06 15:53 UTC (permalink / raw)
  To: guile-user

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

Thanks, I implemented what you described a few days ago and it has been
working well for me. Just two notes for posterity:

- I recommend starting the app inside a separate (non-emacs) terminal,
and then connecting to that from inside emacs with geiser. If you let
lots of stdout/stderr get dumped to an emacs buffer, it slows your
computer down to a crawl.
- As you mentioned to me personally, one has to use trampolines for
hooks to make this programming approach work.

On Fri, 2017-10-06 at 09:01 -0400, Thompson, David wrote:
> Hello Christopher,
> 
> On Sat, Sep 30, 2017 at 1:23 AM, Christopher Howard
> <christopher.howard@qlfiles.net> wrote:
> > Hi, I want to code a game using theChickadee framework, but I want
> > to
> > do it in an interactive programming environment, where I can
> > evaluate
> > things in the REPL while the Chickadee kernel is running, rather
> > than
> > needing to restart the kernel after each modification. The
> > Chickadee
> > kernel runs update hooks every so many milliseconds, so I think I
> > just
> > need to figure out a way to communicate code to an update hook,
> > that it
> > could execute. What would be the simplest and/or most sensible way
> > to
> > do this? (Threads? IPC? Communicate to a network port?)
> 
> Mark is right that a cooperative REPL server is the answer here.  We
> both worked on that feature a few years ago for exactly this purpose.
> 
> Here is a simple example program that has a REPL server added in:
> 
>     (use-modules (chickadee)
>                  (chickadee math vector)
>                  (chickadee render sprite)
>                  (chickadee render texture)
>                  (system repl coop-server))
> 
>     (define sprite #f)
>     (define repl #f)
> 
>     (define (load)
>       (set! sprite (load-image "images/chickadee.png"))
>       (set! repl (spawn-coop-repl-server)))
> 
>     (define (draw alpha)
>       (draw-sprite sprite (vec2 256.0 176.0)))
> 
>     (define (update dt)
>       (poll-coop-repl-server repl))
> 
>     (add-hook! load-hook load)
>     (add-hook! update-hook update)
>     (add-hook! draw-hook draw)
>     (add-hook! quit-hook abort-game)
> 
>     (run-game)
> 
> Once the program is running, you can connect to the REPL server over
> a
> tcp socket on port 37146.  If you use Geiser, which I highly
> recommend, just run `M-x connect-to-guile` and use the default
> connection settings.
> 
> Hope this helps,
> 
> - Dave
> 
-- 
Christopher Howard
Enterprise Solutions Manager
Alaska Satellite Internet
3239 La Ree Way
Fairbanks, Alaska 99709
1-888-396-5623
https://alaskasatelliteinternet.com
personal web site: https://qlfiles.net
https://emailselfdefense.fsf.org/en/



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: Interactive programming with Event Loop?
  2017-10-06 15:53   ` Christopher Howard
@ 2017-10-06 16:11     ` Thompson, David
  0 siblings, 0 replies; 5+ messages in thread
From: Thompson, David @ 2017-10-06 16:11 UTC (permalink / raw)
  To: Christopher Howard; +Cc: Guile User

On Fri, Oct 6, 2017 at 11:53 AM, Christopher Howard
<christopher@alaskasi.com> wrote:
> Thanks, I implemented what you described a few days ago and it has been
> working well for me. Just two notes for posterity:
>
> - I recommend starting the app inside a separate (non-emacs) terminal,
> and then connecting to that from inside emacs with geiser. If you let
> lots of stdout/stderr get dumped to an emacs buffer, it slows your
> computer down to a crawl.
> - As you mentioned to me personally, one has to use trampolines for
> hooks to make this programming approach work.

Right, Chickadee is low-level enough that you have to do your own
bootstrapping for this sort of thing.

Glad things are working for you!

- Dave



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

end of thread, other threads:[~2017-10-06 16:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-30  5:23 Interactive programming with Event Loop? Christopher Howard
2017-09-30  8:24 ` Mark H Weaver
2017-10-06 13:01 ` Thompson, David
2017-10-06 15:53   ` Christopher Howard
2017-10-06 16:11     ` Thompson, David

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