Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Executable XML users challenge

Name: F r o z e n V o i d !!mJCwdV5J0Xy2A21 2011-12-08 5:01

provide any LISP macro with clear explanation of its structure and function
that is :
1.concise (max 10 lines)
2.does not have a C equivalent(at least not anything above 100 lines)
3.does not use any libraries or imported complex functions which are not in C
If you provide an exact explanation/commentary on what it does i'll try to make a C solution which
is equivalent to LISP one. If i fail to do so, LISP wins, if i provide a solution you can make another macro.
If all examples in the thread are provide with C equivalents, LISP loses.

Name: Anonymous 2011-12-08 7:12

>>22
You forgot to bring your ENTERPRISE C MACRO SYSTEM FOR SYNERGISTIC LEVERAGE.

#include <stdio.h>
#include <stdlib.h>

#include "CUDDER.h"

int main (void) {
  int array_1 [] = {6, 5, 8, 1, 10, 4};
  int array_2 [] = {6, 5, 8, 1, 10, 4};

  sort(array_1,
       lambda (const void * a, const void * b) {
     return *(const int *) a - *(const int *) b;
       } lambda_end);

  puts("first:");
  foreach (int i, array_1) {
    printf("%d\n", i);
  } foreach_end;

  sort(array_2,
       lambda (const void * a, const void * b) {
     return *(const int *) b - *(const int *) a;
       } lambda_end);

  puts("second:");
  foreach (int i, array_2) {
    printf("%d\n", i);
  } foreach_end;

  return 0;
}


CUDDER.h
#ifndef __CUDDER_H
#define __CUDDER_H

#include <stdlib.h>

#define lambda(...)                \
  ({                        \
    int (*__lambda_fptr)(__VA_ARGS__);        \
    int   __lambda (__VA_ARGS__)

#define lambda_end                \
    __lambda_fptr = __lambda;            \
  })

#define foreach(var, array)                \
  ({                            \
    int __foreach_i;                    \
    for (__foreach_i = 0;                \
     __foreach_i < sizeof(array)/sizeof(array[0]);    \
     __foreach_i++) {                \
      var = array[__foreach_i];

#define foreach_end                \
    }                        \
  })

#define sort(array, comparator)            \
  qsort(array,                    \
    sizeof(array) / sizeof(array[0]),    \
    sizeof(array[0]),            \
    comparator)

#endif

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List