Scheme of things

I add a little color to the concept of interfacing using scheme or `guile` or Kawa or a Lisp like language. I personally have an easier time dealing with the code when it is highlighted with color in `kate`. The output is nothing special but it works and that means it is a base case I can extend and test and always revert to see what I screwed up if it fails. Also I wanted to conceptualize CDR and CAR and CONS. It all relates and this does have something to do with trees and matrices and solutions. The sum of the parts is something else and just develops. I suppose it could be something that I could say is "glympisifith"[sic] or some other made up word to reference the complete system, but I don't think people can communicate at that level.


I had said that I would delve deeper into scheme and ".scm" scripting and how it gets integrated in a program and how the scripts actually execute. I have a queue that keeps all the things I must complete and they get pushed and popped all the time. When I am at a dead end to understand something I pop the process and solve the relationships so that I have that dependency satisfied and continue toward the goal. So today I had to pop scheme, guile, Lisp and that category so I could understand how these things relate. I also have to do the same thing with Python+blender along with Python+gimp and ".scm" with many things.

The basic template for this came from GNU here. I didn't find it so clear how all the pieces got assembled and perhaps the person who wrote that tutorial thought they were being very clear, but I did not find it so. This code compiles and runs on my machine. It just makes a box. The point is not to have an elegant application, but to identify the nuance of interfacing (language A) with (language B).


#include <libguile.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> static double x, y; static double direction; static int pendown; /* Simple backend for a Logo like tortoise drawer. */ static const int WIDTH = 10; static const int HEIGHT = 10; static FILE* start_gnuplot () { FILE* output; int pipes[2]; pid_t pid; pipe (pipes); pid = fork (); if (!pid) { 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; } static FILE* global_output; 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 void tortoise_reset () { x = y = 0.0; direction = 0.0; pendown = 1; fprintf (global_output, "clear\n"); fflush (global_output); } static void tortoise_pendown () { pendown = 1; } static void tortoise_penup () { pendown = 0; } static void tortoise_turn (double degrees) { direction += M_PI / 180.0 * degrees; } static void tortoise_move (double length) { double newX, newY; newX = x + length * cos (direction); newY = y + length * sin (direction); if (pendown) draw_line (global_output, x, y, newX, newY); x = newX; y = newY; } static void* register_functions (void* data) { return NULL; } int main( int argc, char *argv[]) { int i; global_output = start_gnuplot (); //scm_with_guile (&register_functions, NULL); //scm_shell (argc, argv); tortoise_pendown (); for (i = 1; i <= 4; ++i) { tortoise_move (3.0); tortoise_turn (90.0); } }


# Basic Makefile for the tortoise package. CFLAGS = `guile-config compile` LIBS = `guile-config link` .PHONY: clean build run build: tortoise clean: rm -f tortoise tortoise.o run: tortoise ./tortoise tortoise: tortoise.o gcc $< -o $@ $(LIBS) tortoise.o: tortoise.c gcc -c $< -o $@ $(CFLAGS)

So I get the concept now and `guile` is a bit more understandable in the concept of a universal constructor. I have the framework now and I can fill in easily now from other languages as everything is pretty much the same when you program. I prefer assembly language but it isn't the do all and end all of getting things done, it is just more predictable for me as I am essentially switching gates to get the result I want and in that way I can make it virtually deterministic.

0 comments:

Contributors

Automated Intelligence

Automated Intelligence
Auftrag der unendlichen LOL katzen