reddit / emacs

Why Are Lisp Macros So Great!?

a-concerned-mother · 2022-11-20 20:06
arthurno1 · 2022-11-21 00:48
Ha, cool; didn't know about "with-c-syntax". There is an old experiment called [Parcil](http://www.wbricken.com/pdfs/02teach/03ai/lisp03-parci.pdf), I found it once by a change while I was looking for compilers and parser in CL. Just as a curiosa. I don't know if Parcil ever become "a thing"; I have just seen that paper.
SlowValue · 2022-11-21 21:27
here is another simple example: Imagine following C source code snippet (it could be [libSDL](https://wiki.libsdl.org/SDL_RenderSetLogicalSize) code): if( render_set_logical_size(...) < 0 ){ fprintf(stderr, "error set_logical_size: %i \n" get_error()); return 1; } if( set_render_target(...) < 0 ){ fprintf(stderr, "error render_target: %i \n" get_error()); return 1; } if( set_render_draw_color(...) < 0 ){ fprintf(stderr, "error draw_color: %i \n" get_error()); return 1; } if( render_clear(...) < 0 ){ fprintf(stderr, "error clear: %i \n" get_error()); return 1; } Now with a simple macro `check-all-return-values`, equivalent CL source code, using same lib through cffi, could look like this: (check-all-return-values (render_set_logical_size ...) (set_render_target ...) (set_render_draw_color ...) (render_clear ...)) I'll leave the implementation of the macro to the reader, it is not very complicated to implement.