4 ms·
> The direct translation of the C expression to Lisp would actually be (-> a (-> b (-> c d))) Not really. -> looks like binary infix operator, but it is really
by zajio1am 2y ago
> The direct translation of the C expression to Lisp would actually be (-> a (-> b (-> c d)))
Not really. -> looks like binary infix operator, but it is really an unary postfix operator (parametrized by field). Because field itself is not a first-class entity in C.
- Zambyte 2y agoEither -> is a binary operator or is is not an operator in the expression at all, and the unary postfix operators are ->b, ->c, and ->d. In the latter case, that gives us (->d (->c (->b a))) in Lisp, which I can see how ypu could get, but I don't agree. #include <stdio.h> #include <stdlib.h> struct foo { int a; }; int main() { struct foo *f = malloc(sizeof(struct foo)); f->a = 5; printf("%d\n", f->b); free(f); return 0; } test.c:11:21: error: no member named 'b' in 'struct foo' 11 | printf("%d\n", f->b); | ~ ^ 1 error generated. What do you mean when you say fields are not first class in C?