Arc Forumnew | comments | leaders | submitlogin
2 points by cthammett 3191 days ago | link | parent

Thanks mate, below are the error codes:

  (= stack (newSA))
  #<cpointer>

   (pushSA stack 1)
  stack: undefined;
   cannot reference undefined identifier
    context...:
     /home/conan/Documents/anarki-master/ac.scm:1225:4

  (fullSA? stack)
    stack: undefined;
   cannot reference undefined identifier
    context...:
   /home/conan/Documents/anarki-master/ac.scm:1225:4

  (empytSA? stack)
  _empytSA?: undefined;
   cannot reference undefined identifier
    context...:
   /home/conan/Documents/anarki-master/ac.scm:1225:4

  (displaySA stack)
  stack: undefined;
   cannot reference undefined identifier
    context...:
   /home/conan/Documents/anarki-master/ac.scm:1225:4

  stack
  #<cpointer>

  Here is the C code:

  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  #include "StackArray.h"

  void pushStackArray(StackArray * stack, int item){
	if(stack->size < MAX){
		stack->array[stack->size] =  item;
		stack->size++;
	} else {
		printf("The stack is full\n");
	}
  }

  int popStackArray(StackArray * stack){
	if(stack->size > 0){
		stack->size--;
	} else if(stack->size == 0){
		printf("Stack array is empty\n");
	}
	return stack->array[stack->size + 1];
  }

  int fullStackArray(StackArray * stack){
	return stack->size == MAX ? 1 : 0;
  }
  int emptyStackArray(StackArray * stack){
	return stack->size == 0 ? 1 : 0;
  }

  StackArray * newStackArray(){
	StackArray * stack = malloc(sizeof(StackArray));
	int i;
	for(i = 0; i < MAX; i++){
		stack->array[i] = 0;
	}
	stack->size = 0;
	return stack;
  }

  void displayStackArray(StackArray * stack){
	int i;
	for(i = 0; i < stack->size; i++){
		printf("%d ", stack->array[i]);
	}
	printf("\n");
  }

  void delete(StackArray * stack){
	free(stack); 
  }


2 points by rocketnia 3191 days ago | link

Most of those errors are saying it can't find a global variable named "stack". That's because when you do (= stack (newSA)), you're creating a global variable called "stack" in Arc but it's called "_stack" in Racket. In your macros, you're generating Racket code that uses the Arc variable name, so it's looking for a "stack" Racket global that doesn't exist. You can potentially fix this in your macros... but why use macros when you already have functions that do what you want? :)

  (= newSA $.newStackArray)
  (= deleteSA $.delete)
  (= pushSA $.pushStackArray)
  (= popSA $.popStackArray)
  (= fullSA? $.fullStackArray)
  (= emptySA? $.emptyStackArray)
  (= displaySA $.displayStackArray)
If you absolutely need macros, then here's a fixed version of pushSA that embeds its arguments as Arc expressions rather than Racket expressions:

  (mac pushSA (stack x)
    `( ($:lambda (stack x)
         (pushStackArray stack x))
       ,stack ,x))
  ; or...
  (mac pushSA (stack x)
    `($.pushStackArray ,stack ,x))
Fixing the others would be similar, but I picked pushSA as an example because it has two arguments.

Finally, I think this line just has a simple typo:

  typo:  (emptytSA? stack)
  fix:   (emptySA? stack)
How far does this get you? I haven't tried your code, and I don't know if this will fix all your problems, but maybe it's a start!

-----

3 points by cthammett 3190 days ago | link

Hey thanks this works great. I just need to fix an easy bug in the C code for pop.

-----