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 8:59

>>38
#define square(x) ((x) * (x))

square(rand() % 10) expands to ((rand() % 10) * (rand() % 10)). The macro is for when you only want the argument to be evaluated once, and then you use the returned value in the body of the macro.

Name: Anonymous 2011-12-08 9:01

Add syntax to C using the preprocessor.

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

>>41
if you want the rand() function to be evaluated once and this used for such cases, you easily use a function
inline int square(int x){int y=x; return y*y;}

Name: Anonymous 2011-12-08 9:08

Hey FV, what's your job?

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

>>44
I'm a free artist

Name: Anonymous 2011-12-08 9:09

>>45
And what "a free artist" does for living?

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

for ints:
square(int x){return x*x;}
for floats:
fsquare(float x){return x*x}
for doubles:
dsquare(double x){return x*x}

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

>>46
Anything he likes.

Name: Anonymous 2011-12-08 9:13

>>48
And how do earn money? You parents?

Name: Anonymous 2011-12-08 9:14

>>46
wastes welfare

Name: Anonymous 2011-12-08 9:16

I don't have a job
Just say it, bro

Name: Anonymous 2011-12-08 9:18

>>45
read: free autist

Name: Anonymous 2011-12-08 9:19

>>52
Should autists really be allowed to roam free?

Name: Anonymous 2011-12-08 9:21

>>53
As long as they don't invent any programming languages they are relatively harmless.

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

>>39
>list with floating point numbers and integers
Why are you storing the array of floats and ints at the same place?

Name: Anonymous 2011-12-08 9:32

>>55
to irk your static typed shit,
duh.
inb4 void*

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

>>56
I would just use 2 arrays and sort them separetely, with most effective sort speciazlied for the specific type.
using a mixed type array(actually an array of pointers for each element, incredibly bloated compared to int array)
make any comparison
1.first check the type of element
2.convert to common comparator type
3.compare and return result in common type
vs
1.compare two elements

Name: Anonymous 2011-12-08 9:59

>>57
Thats just an excuse. You can't write such code in C.

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

>>58
int i;
#define STDMAIN main(int argc,char**argv){;
#define STDEND ;return 0;};
#define cs4p const int*
#define cf8p const double*
#define sort(array,function) qsort((void*)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 printdoubles(array) ;for(i=0;i<(sizeof(array)/sizeof(array[0]));i++){printf("%f ",array[i]);};puts("");
#define printevens(array) ;for(i=0;i<(sizeof(array)/sizeof(array[0]));i++){if(!(array[i]&1))printf("%d ",array[i]);};puts("");
#define printodds(array) ;for(i=0;i<(sizeof(array)/sizeof(array[0]));i++){if((array[i]&1))printf("%d ",array[i]);};puts("");
#define sortpd(array,function) sort(array,function);printdoubles(array);
#define sortp(array,function) sort(array,function);printints(array);

#include <stdio.h>
#include <stdlib.h>
int cmpn(cs4p num1,cs4p num2){return *num1-*num2;}
int cmpr(cs4p num1,cs4p num2){return *num2-*num1;}
int dcmpn(cf8p a,cf8p b){return (*a>*b)- (*a<*b);}

STDMAIN;//i'm not going to re/allocate anything useless at run-time.
int intarr[]={6,5,9,2,1,8};
double doublearr[]={2.0,0.0,4.5};
sortpd(doublearr,dcmpn);
sort(intarr,cmpn);
printodds(intarr);
printevens(intarr);
puts("hello world");
STDEND

Name: Anonymous 2011-12-08 10:09

>>59
#define STDMAIN main(int argc,char**argv){;
why the fuck. why is function macro define srsly wtf.
SexuallyTransmittedDiseaseMAIN

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

>>60
STanDardMAIN
STanDardEND(Program)

Name: Anonymous 2011-12-08 10:17

>>61
I know what it's supposed to mean.
I'm just asking why the fuck would you define every function as a macro.

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

>>62
To make reusable code. I could stick those macro in void.h and use them for years.

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

>>62
consider writing 1000 C files, each could be started with
int main(int argc,char**argv){;
or
STDMAIN
which one would be easier?

Name: Anonymous 2011-12-08 10:19

>>59
so you are still arguing that C can do anything LISP does in an elegant way? I can't see an array of floats, ints in your code. it does not create a sorted array, just prints a string. and lisp code is like in two lines yet your (insufficent) C version is huge
also
(*a>*b)- (*a<*b)
lol

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

to make 1000 empty C files with same exact line #include <void.h> is left as exercise to the reader.

Name: Anonymous 2011-12-08 10:21

>>64
The one where I don't use C I use scheme because I'm not programming for an 8-bit embedded microcontroller.

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

Name: Anonymous 2011-12-08 10:25

>>68
why simply it is not *a-*b

Name: Anonymous 2011-12-08 10:27

>>63
I could stick those macro in void.h
Why did I even ask -_-
stick your dick in void.h get STD

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

>>69
doubles don't return 0, they return double 0.0

Name: Anonymous 2011-12-08 10:29

Your macros expands wrong half the time you know it right? for example

if(test)printints(array);
will expand like
if(test);for(i=0;i<(sizeof(array)/sizeof(array[0]));i++){printf("%d ",array[i]);};puts("");

do you really know C?

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

the type of return of *a-*b is double, and qsort expects the return of function to be integer.

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

>>72
I don't use such style:
if(test){printints(array); }

Name: Anonymous 2011-12-08 10:33

>>71
qsort is not stable, why do you even care equality?

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

If you expect to use short function syntax, write inline versions.
These are designed to avoid typing ;;; each time.

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

>>75
Its a comparator function which follow the standard qsort return type
1 first >second
0 equals
-1 second>first

Name: Anonymous 2011-12-08 10:36

>>74
it does not mean it is correct.

any way, I am done with this bullshit. enjoy your life

Name: Anonymous 2011-12-08 10:39

>>77
And standard qsort comparator function takes const void *.

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

>>78
I don't write inline version unless i need the return value from the macro.
printints(array) does not return a value, so it can be written as ;printints(array); to avoid typing extra ;; like
printints(array) puts("STD END MAIN");

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