Chris Angelico <[email protected]>: > How does C let you create new keywords?
With #define. Nowhere near as elegant (flexible, hygienic) as in Lisp,
but used to create new syntax:
include/linux/list.h:
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
include/linux/wait.h:
#define __wait_event_interruptible(wq, condition, ret) \
do { \
DEFINE_WAIT(__wait); \
\
for (;;) { \
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
if (condition) \
break; \
if (!signal_pending(current)) { \
schedule(); \
continue; \
} \
ret = -ERESTARTSYS; \
break; \
} \
finish_wait(&wq, &__wait); \
} while (0)
In the latter example, note how "condition" is embedded in the middle of
the macro and evaluated repeatedly.
Marko
--
https://mail.python.org/mailman/listinfo/python-list
