[ prog / sol / mona ]

prog


Monads,Async/Await : Algebraic Effects in C99

15 2021-01-14 11:23

>>12-14

#define isstring(x) _Generic((x),char*:1,default:0)

OK, but how can you use that *in* a macro. Take something like this in Lisp (where `pick` is already defined somewhere else):

(defmacro pop-random (list)
  "Pick an element from LIST and remove it."
  (assert (symbolp list))
  (let ((sym (gensym)))
    `(let ((,sym (pick ,list)))
       (setf ,list (delete ,sym ,list))
       ,sym)))

The first line makes sure that `list` is a symbol, and will trigger a compile-time error if that isn't the case. No special DSL needed. To my knowledge, this isn't possible with CPP. Or am I wrong?

There is nothing "Too dangerous" for C, even inline assembler insert in the middle of function.

C is not in danger, C is the danger. Imagine "regular", 9to5 programmers using stuff like what you are describing. It would all fall apart. That's the reason why businesses are interested in boring languages like Java.

Its entirely possible to do such things as loops, monads, functional composition.

Sure, the point I think that most people who compare C and Lisp (even though it might not be the right thing to do) shouldn't be that it isn't possible, but that it shouldn't be done, or you are really straining the language. E.g. Order seems cool, but look more like a POC to me. I don't hate C, I just think it shouldn't be used this way. If you want to do Lisp, use Lisp. If you need C, keep it clean, simple and readable.

69


VIP:

do not edit these