Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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 !!mJCwdV5J0Xy2A212011-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:
Anonymous2011-12-08 5:32
Regular expression matcher macro, which compiles to machine code.
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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.
>>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 !!mJCwdV5J0Xy2A212011-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:
Anonymous2011-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 !!mJCwdV5J0Xy2A212011-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:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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:
Anonymous2011-12-08 6:28
Inb4 Frozen writes a horrible LISP interpreter inside C
Name:
Anonymous2011-12-08 6:30
Executable XML users challenge?
Name:
Anonymous2011-12-08 6:31
It's not spelled ``LISP''.
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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]);
>>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 !!mJCwdV5J0Xy2A212011-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
(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)).
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
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:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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;}
>>55
to irk your static typed shit,
duh.
inb4 void*
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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:
Anonymous2011-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 !!mJCwdV5J0Xy2A212011-12-08 10:02
#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
>>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 !!mJCwdV5J0Xy2A212011-12-08 10:20
to make 1000 empty C files with same exact line #include <void.h> is left as exercise to the reader.
any way, I am done with this bullshit. enjoy your life
Name:
Anonymous2011-12-08 10:39
>>77
And standard qsort comparator function takes const void *.
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-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");
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 10:40
>>79
void* is the the universal type you can cast anything to it.
Name:
Anonymous2011-12-08 10:44
>>81
Yes but you are casting
int ( * comparator ) ( const void *, const void * )
to
int ( * comparator ) ( float *, float * )
which is not standard
>>43
It was just an example. Sometimes you need to use a macro instead of a function, but you want the arguments (at least some of them) to only be evaluated once.
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 11:57
>>85
The function is textually identical to a macro call and can be used inline identically to a macro.
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 12:12
here are all variants of such calls:
int i;
#define STDMAIN main(int argc,char**argv){;
#define STDEND ;return 0;};
#define square_inline(x) ((x)=(x)*(x)) //evaluates X three times
#define square(x) ((x)*(x)) //evaluates X two times
inline int square_func(int x){return x*x;} //evaluates X one time
//pick any you like
STDMAIN;
int x=2;
printf(" %d",x);
square_inline(x);
printf(" %d",x);
x=square_func(x);
printf(" %d",x);
x=square(x);
printf(" %d",x);
STDEND
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 12:17
and a bonus void function
void square_via_pointer(int* x){*x*=*x;}
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 12:17
So, will anyone write an equivalent C macro for >>39
, or LISP wins?
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 12:59
>>90
if you can compare "hello world" to "0.0" you have problems
Name:
Anonymous2011-12-08 13:05
>>91 "hello world" "0.0"
If you can't compare two strings, your language has problems.
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 13:09
>>91
Not that, 0.0 as double, which is 5th position
and "Hello World" as string at end.
Your macro can be used to compare 0.0 to "Hello World"
since i lack any Lisp interpreters, can you tell me what happens when you sort your "array" after the "hello world" is added?
Name:
2011-12-08 13:21
>remove-if #'integerp
and he claims that using a separate array is different
Typical LITHP retard
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 13:23
>>94
Its functionally different, he checks the value type(which is stored by LISP) so the array is constructed in-place.
Its incredibly inefficient, but "elegant". Still he didn't answer what happen when you sort the entire array with doubles ,ints, and "Hello world"
Even just picking a single Monad for C would be hard, to say the least for generalizing the design pattern. Take Maybe for instance. Write a macro that makes it so that if any assignment in a block resolves to NULL, the whole block immediately returns NULL (and the other statements are not even evaluated.)
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 13:27
>>96
Can you describe what happens after append, can you sort the list or not?
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 13:29
>>97
If i want to juggle lambdas and compare double to strings, i'd rather use JavaScript.
Name:
Anonymous2011-12-08 13:33
>>98
I can't, but how is it related to the code snippet from >>39?
>>99
Mah boi, you probably want to re-read your OP post.
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-08 13:37