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 5:04

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

>>2
Well, main selling point of LISP = Powerful macro system. Show some of that power.

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

If provided C macro is obviously inferior it would show how superior and elegant LISP syntax is(wtihout judgement on performance):
If there is no clear way to accomplish some LISP macro it would show a deficiency in C
If the LISP macro is easily translated into C preprocessor, it would make C superior.
If the LISP macro requires a complex C hack or multiple C function calls, this would also showcase simplicity of LISP.

Name: Anonymous 2011-12-08 5:32

Regular expression matcher macro, which compiles to machine code.

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

>>5
provide LISP code with clear and exact explanation of what it does.
Don't provide abstract examples or claims or LISP superiority.

Name: Anonymous 2011-12-08 5:39

>>3
nope, it is elegancy. writing in LISP more like an art than programming.

also not sure about what you mean by "lines". LISP code is basically a single line.

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

>>5
also, C file(with regex library) can produce a C output file(fprintf result strings) which would be compiled as second stage
system("compiler -flags output.c")
Its not complex just awkward.

Name: Anonymous 2011-12-08 5:45

hey frozenfurfag if you want people to like you here do something awesome like port the code into a simple turing-equivalent cellular automaton or something.
no one cares if you can rewrite code in C.

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

>>5 it would work like this:
1.C code produces Output.C using regexes and string parsing functions.
2.C code calls compiler to compile output.c to output.exe
3.control is transffered to output.exe,C code stops.

Name: Anonymous 2011-12-08 5:56

>>6
When you pay me enough.

Name: Anonymous 2011-12-08 5:57

Name: Anonymous 2011-12-08 5:58

>>10
Feel the elegancy of raw C!

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

>>13
In some cases you may want to compile and load dynamically object files like tiny .dll's or .o files into the parent process executable space,
but they all require calling the compiler at least once(to produce the executable object file: it may be even 1 function long).
Anyway i've not seen any clear example of LISP macro which does something exclusive to LISP, so i could compare and propose an equivalent(which could even not use regexes or some complex features, just C code).

Name: Anonymous 2011-12-08 6:13

>>14
exclusive to LISP
>>2

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

>>15
Not that, show something which is requiring to writing a page of code to work to replicate a line of LISP.
Even better: show equivalent "ugly" C code vs "elegant" LISP code, so i could try to rewrite it in far less space.

Name: Anonymous 2011-12-08 6:28

Inb4 Frozen writes a horrible LISP interpreter inside C

Name: Anonymous 2011-12-08 6:30

Executable XML users challenge?

Name: Anonymous 2011-12-08 6:31

It's not spelled ``LISP''.

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

>>17
I wouldn't write any run-time based code. Its very counterproductive to achieving any performance.
Compilation always has an advantage since it it not limited in time: a 1 hour compilation of an executable will outperform interpreted file which cannot spend time to interpret and optimize much, since it has to run at real-time.

Name: Anonymous 2011-12-08 6:34

Name: Anonymous 2011-12-08 6:35

>>16

(sort '(6 5 8 1 10 4) #'<)
(sort '(6 5 8 1 10 4) #'>)



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

int comparator(const void *num1, const void *num2) {
    return *(const int *)num1 - *(const int *)num2;
}

int comparator2(const void *num1, const void *num2) {
    return *(const int *)num2 - *(const int *)num1;
}

int main(int argn, char *args[]){
  int arr1[] = {6, 5, 8, 1, 10, 4};
  int arr2[] = {6, 5, 8, 1, 10, 4};
  int i;
  qsort(arr1, sizeof(arr1)/sizeof(int), sizeof(int), comparator);
  for(i=0; i<(int)(sizeof(arr1)/sizeof(int)); i++) printf("%d ", arr1[i]);
  printf("\n");
  qsort(arr2, sizeof(arr2)/sizeof(int), sizeof(int), comparator2);
  for(i=0; i<(int)(sizeof(arr2)/sizeof(int)); i++) printf("%d ", arr2[i]);

  return 0;
}

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

>>22
I don't see anything wrong with the C code, here is equivalent macro
#define sort(array,function)   qsort(array, sizeof(array)/sizeof(array[0]), sizeof(array[0]),function)
#include <stdio.h>
#include <stdlib.h>
int comparator(const void *num1, const void *num2) {
    return *(const int *)num1 - *(const int *)num2;}
int comparator2(const void *num1, const void *num2) {
    return *(const int *)num2 - *(const int *)num1;}


int main(int argn, char *args[]){
  int arr1[] = {6, 5, 8, 1, 10, 4};
  int arr2[] = {6, 5, 8, 1, 10, 4};
  int i;
sort(arr1,comparator);
   for(i=0; i<(int)(sizeof(arr1)/sizeof(int)); i++) printf("%d ", arr1[i]);
  printf("\n");
sort(arr2,comparator2);
  for(i=0; i<(int)(sizeof(arr2)/sizeof(int)); i++) printf("%d ", arr2[i]);

  return 0;
}

Name: Anonymous 2011-12-08 6:50

>>23
except that it is ugly as shit and huge comparing to lisp version? seriously, in lisp you simply say "sort" and give an array and a comparison operator and viola. in C you are surrounded with type casting, stupid tricks like sizeof a/sizeof *a, had to redefine a simple comparison operator etc

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

is it pretty now?
#define STDMAIN int main(int argc,char**argv){;
#define STDEND ;return 0;};
typedef unsigned int u4;
u4 i;
#define sort(array,function)   qsort(array, sizeof(array)/sizeof(array[0]), sizeof(array[0]),function)
#define printints(array) ;for(i=0;i<(sizeof(array)/sizeof(array[0]));i++){printf("%d ",array[i]);};puts("");
#include <stdio.h>
#include <stdlib.h>
int comparator(const void *num1, const void *num2) {
    return *(const int *)num1 - *(const int *)num2;}
int comparator2(const void *num1, const void *num2) {
    return *(const int *)num2 - *(const int *)num1;}
STDMAIN
  u4 arr1[] = {6, 5, 8, 1, 10, 4};
  u4 arr2[] = {6, 5, 8, 1, 10, 4};
sort(arr1,comparator);printints(arr1);
sort(arr2,comparator2);printints(arr2);
 STDEND

Name: Anonymous 2011-12-08 6:54

>>25
it hurts to look

Name: Anonymous 2011-12-08 6:58

>>25
I lol'd hard. It's been FrozenVoid'd

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

Name: Anonymous 2011-12-08 7:39

C is PIG DISGUSTING.

I'm happy to let the C autists squabble about performance. Just keep hacking away, cretins - make my LISP interpreter grow stronger!

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

//void.h 610 bytes
#define STDMAIN int main(int argc,char**argv){;
#define STDEND ;return 0;};
#define cv0p  const void*
#define cs4p const int*
#define is4 inline int
#define sort(array,function)   qsort(array, sizeof(array)/sizeof(array[0]), sizeof(array[0]),function)
#define printints(array) ;for(i=0;i<(sizeof(array)/sizeof(array[0]));i++){printf("%d ",array[i]);};puts("");
#define sortp(array,function)  sort(array,function);printints(array);
#include <stdio.h>
#include <stdlib.h>
is4 cmpn(cv0p num1, cv0p num2){return *(cs4p)num1-*(cs4p)num2;}
is4 cmpr(cv0p num1, cv0p num2){return *(cs4p)num2-*(cs4p)num1;}
//main.c 78 bytes
STDMAIN int i;int arr[]={6,5,8, 1,10,4};sortp(arr,cmpn);sortp(arr,cmpr);STDEND

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

Any other LISP macro which is hard to make in C?

Name: Anonymous 2011-12-08 8:11

>>31
I still can't see an elegant replacement to sort.

Name: Anonymous 2011-12-08 8:21

>>32
Are you blind? Legit question.

Name: Anonymous 2011-12-08 8:22

>>33
Yes, after seeing >>30 I carved my own eyes

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

A bit better without those void pointers
//523 bytes void.h
int i;
#define STDMAIN main(int argc,char**argv){;
#define STDEND ;return 0;};
#define cs4p const int*
#define sort(array,function) qsort(array, sizeof(array)/sizeof(array[0]),sizeof(array[0]),function)
#define printints(array) ;for(i=0;i<(sizeof(array)/sizeof(array[0]));i++){printf("%d ",array[i]);};puts("");
#define sortp(array,function) sort(array,function);printints(array);
#include <stdio.h>
#include <stdlib.h>
cmpn(cs4p num1,cs4p num2){return *num1-*num2;}
cmpr(cs4p num1,cs4p num2){return *num2-*num1;}
//main.c 71 bytes
STDMAIN;int arr[]={6,5,8,1,10,4};sortp(arr,cmpn);sortp(arr,cmpr);STDEND

Name: Anonymous 2011-12-08 8:47

(defmacro once-only ((&rest names) &body body)
  (let ((gensyms (loop for n in names collect (gensym))))
    `(let (,@(loop for g in gensyms collect `(,g (gensym))))
      `(let (,,@(loop for g in gensyms for n in names collect ``(,,g ,,n)))
        ,(let (,@(loop for n in names for g in gensyms collect `(,n ,g)))
           ,@body)))))


Used in other macros to make sure arguments are only evaluated once. For example:

(defmacro m1 (x)
  `(+ ,x ,x))


(m1 (f)) expands to (+ (f) (f)).

(defmacro m2 (x)
  (once-only (x)
    `(+ ,x ,x)))


(m2 (f)) expands to something equivalent to (let ((y (f))) (+ y y)).

Name: Anonymous 2011-12-08 8:52

>>35
//removed bloated strings identifiers
//411 bytes void.h
int i;
#define STDMAIN main(int argc,char**argv){;
#define STDEND ;return 0;};
#define cs4p const int*
#define R return
#define s(a,f) qsort(a,sizeof(a)/sizeof(a[0]),sizeof(a[0]),f)
#define pi(a) ;for(i=0;i<(sizeof(a)/sizeof(a[0]));i++){printf("%d ",a[i]);};puts("");
#define sp(a,f) s(a,f);pi(a);
#include <stdio.h>
#include <stdlib.h>
cn(cs4p n1,cs4p n2){R *n1-*n2;}
cr(cs4p n1,cs4p n2){R *n2-*n1;}
//main.c 55 bytes
STDMAIN;int a[]={6,5,8,1,10,4};sp(a,cn);sp(a,cr);STDEND

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

>>36
Why you would need such a cludge to protect yourself from evaluating arguments?
Can you explain it in C terms?

Name: Anonymous 2011-12-08 8:57

Ok, I want you to implement a special sorting algorithm. in this algorithm you will implement a list with floating point numbers and integers. return a list that floating point at the beginning and sorted, after that sorted odd numbers and finally sorted even numbers. oh and append "hello world" to end of the list

(setq l '(6 5 2.0 9 0.0 2 1 4.5 8))
(append (sort (remove-if #'integerp l) #'<) (sort (remove-if  #'evenp (remove-if #'floatp l)) #'<) (sort (remove-if  #'oddp (remove-if #'floatp l)) #'<) "Hello World")

Name: Anonymous 2011-12-08 8:57

>>39
and output list is
(0.0 2.0 4.5 1 5 9 2 6 8 . "Hello World")

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