Skip to content

Instantly share code, notes, and snippets.

@mooreniemi
Created October 2, 2016 19:18
Show Gist options
  • Save mooreniemi/5c8969bbe66d5acb1f12169c03bc5a96 to your computer and use it in GitHub Desktop.
Save mooreniemi/5c8969bbe66d5acb1f12169c03bc5a96 to your computer and use it in GitHub Desktop.
/*
* =====================================================================================
*
* Filename: Compose.c
*
* Description: Proc composition
*
* Version: 1.0
* Created: 10/01/2016 16:14:22
* Revision: none
* Compiler: gcc
*
* Author: Alex Moore-Niemi
*
* =====================================================================================
*/
#include <ruby.h>
// Defining a space for information and references about the module to be stored internally
VALUE Compose = Qnil;
// Prototype for the initialization method - Ruby calls this, not you
void Init_compose();
/*
* def compose
* proc do |i,x|
* self.(i.(x))
* end.curry
* end
*/
VALUE method_compose(VALUE self, VALUE other_proc) {
VALUE result = rb_proc_new(self, other_proc);
FILE *f = fopen("clog.txt", "w");
if (f == NULL) {
printf("no log file found\n");
exit(1);
}
printf(f, "proc: %s\n", self);
return result;
}
// The initialization method for this module
void Init_compose() {
rb_define_method(rb_cProc, "compose", method_compose, -2);
rb_define_method(rb_cProc, "*", method_compose, -2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment