unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Tortoise tutorial
@ 2011-12-16 22:38 luis souto
  2011-12-17  5:49 ` zx spectrumgomas
  2011-12-20  5:29 ` zx spectrumgomas
  0 siblings, 2 replies; 5+ messages in thread
From: luis souto @ 2011-12-16 22:38 UTC (permalink / raw)
  To: guile-user

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

Hello from Spain. I installed Guile 2.0.3 and it works well. I've tried
Tortoise tutorial:
http://www.gnu.org/software/guile/docs/guile-tut/tutorial.html and it
compiled well, Gnuplot window pops up, but (tortoise-move 3) doesn't draw.
The source code is:

/* Simple backend for a Logo like tortoise drawer.  */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <libguile.h>

static const int WIDTH = 10;
static const int HEIGHT = 10;
static FILE* global_output;
static double x = 0.0;
static double y = 0.0;
static double direction = 0.0;
static int pendown = 1;

static FILE* start_gnuplot ();
static void draw_line (FILE* output, double x1, double y1, double x2,
double y2);
static SCM tortoise_reset ();
static SCM tortoise_pendown ();
static SCM tortoise_penup ();
static SCM tortoise_turn (SCM degrees);
static SCM tortoise_move (SCM length);
static void* register_functions (void* data);


static FILE* start_gnuplot ()
{
  FILE* output;
  int pipes[2];
  pid_t pid;

  pipe (pipes);
  pid = fork ();

  if (!pid)http://www.gnu.org/software/guile/docs/guile-tut/tutorial.html
    {
      dup2 (pipes[0], STDIN_FILENO);
      execlp ("gnuplot", NULL);
      return; /* Not reached.  */
    }

  output = fdopen (pipes[1], "w");

  fprintf (output, "set multiplot\n");
  fprintf (output, "set parametric\n");
  fprintf (output, "set xrange [-%d:%d]\n", WIDTH, WIDTH);
  fprintf (output, "set yrange [-%d:%d]\n", HEIGHT, HEIGHT);
  fprintf (output, "set size ratio -1\n");
  fprintf (output, "unset xtics\n");
  fprintf (output, "unset ytics\n");
  fflush (output);

  return output;
}



int main (int argc, char* argv[])
{
  global_output = start_gnuplot ();

  scm_with_guile (&register_functions, NULL);
  scm_shell (argc, argv);

  return EXIT_SUCCESS;
}




static void draw_line (FILE* output, double x1, double y1, double x2,
double y2)
{
  fprintf (output, "plot [0:1] %f + %f * t, %f + %f * t notitle\n",
           x1, x2 - x1, y1, y2 - y1);
  fflush (output);
}


static SCM tortoise_reset ()
{
  x = y = 0.0;
  direction = 0.0;
  pendown = 1;

  fprintf (global_output, "clear\n");
  fflush (global_output);

  return SCM_UNSPECIFIED;
}

static SCM tortoise_pendown ()
{
  SCM result = scm_from_bool (pendown);
  pendown = 1;
  return result;
}

static SCM tortoise_penup ()
{
  SCM result = scm_from_bool (pendown);
  pendown = 0;
  return result;
}

static SCM tortoise_turn (SCM degrees)
{
  const double value = scm_to_double (degrees);
  direction += M_PI / 180.0 * value;
  return scm_from_double (direction * 180.0 / M_PI);
}

static SCM tortoise_move (SCM length)
{
  const double value = scm_to_double (length);
  double newX, newY;

  newX = x + value * cos (direction);
  newY = y + value * sin (direction);

  if (pendown)
    draw_line (global_output, x, y, newX, newY);

  x = newX;
  y = newY;

  return scm_list_2 (scm_from_double (x), scm_from_double (y));
}


static void* register_functions (void* data)
{
  scm_c_define_gsubr ("tortoise-reset", 0, 0, 0, &tortoise_reset);
  scm_c_define_gsubr ("tortoise-penup", 0, 0, 0, &tortoise_penup);
  scm_c_define_gsubr ("tortoise-pendown", 0, 0, 0, &tortoise_pendown);
  scm_c_define_gsubr ("tortoise-turn", 1, 0, 0, &tortoise_turn);
  scm_c_define_gsubr ("tortoise-move", 1, 0, 0, &tortoise_move);
  return NULL;
}



What's wrong ?

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

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

* Re: Tortoise tutorial
  2011-12-16 22:38 Tortoise tutorial luis souto
@ 2011-12-17  5:49 ` zx spectrumgomas
  2011-12-20  5:29 ` zx spectrumgomas
  1 sibling, 0 replies; 5+ messages in thread
From: zx spectrumgomas @ 2011-12-17  5:49 UTC (permalink / raw)
  To: guile-user

Sorry, the source code is here: http://pastebin.com/dXz6QGz1



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

* Re: Tortoise tutorial
  2011-12-16 22:38 Tortoise tutorial luis souto
  2011-12-17  5:49 ` zx spectrumgomas
@ 2011-12-20  5:29 ` zx spectrumgomas
  2012-01-09 23:02   ` Andy Wingo
  1 sibling, 1 reply; 5+ messages in thread
From: zx spectrumgomas @ 2011-12-20  5:29 UTC (permalink / raw)
  To: guile-user

The problem was my value of the LC_NUMERIC locale. If locale is
spanish , decimal separator is ","  and all doubles are displayed with
a comma instead of a dot. I fixed it with :
$export LC_NUMERIC="C"



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

* Re: Tortoise tutorial
  2011-12-20  5:29 ` zx spectrumgomas
@ 2012-01-09 23:02   ` Andy Wingo
  2012-01-10 17:37     ` zx spectrumgomas
  0 siblings, 1 reply; 5+ messages in thread
From: Andy Wingo @ 2012-01-09 23:02 UTC (permalink / raw)
  To: zx spectrumgomas; +Cc: guile-user

On Tue 20 Dec 2011 06:29, zx spectrumgomas <spectrumgomas@gmail.com> writes:

> The problem was my value of the LC_NUMERIC locale. If locale is
> spanish , decimal separator is ","  and all doubles are displayed with
> a comma instead of a dot. I fixed it with :
> $export LC_NUMERIC="C"

Very interesting bug report, thanks!

Does it work if in start_gnuplot, you add:

  setenv ("LC_NUMERIC", "C");

before the

  execlp ("gnuplot", NULL);

?

Andy
-- 
http://wingolog.org/



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

* Re: Tortoise tutorial
  2012-01-09 23:02   ` Andy Wingo
@ 2012-01-10 17:37     ` zx spectrumgomas
  0 siblings, 0 replies; 5+ messages in thread
From: zx spectrumgomas @ 2012-01-10 17:37 UTC (permalink / raw)
  To: guile-user

I had already tested that. I don't know why, but it doesn't work.

I added:
#include <locale.h>

setlocale(LC_NUMERIC,"C");    before the execlp ("gnuplot", NULL);

or

setenv("LC_NUMERIC","C",1);  before the execlp ("gnuplot", NULL);


It compiles, but the bug remains.



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

end of thread, other threads:[~2012-01-10 17:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-16 22:38 Tortoise tutorial luis souto
2011-12-17  5:49 ` zx spectrumgomas
2011-12-20  5:29 ` zx spectrumgomas
2012-01-09 23:02   ` Andy Wingo
2012-01-10 17:37     ` zx spectrumgomas

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