Improve macro expansion and returns
This commit is contained in:
14
src/lisp.h
14
src/lisp.h
@ -295,7 +295,7 @@ inline static bool NUMBERP(LispVal *v) {
|
||||
!NILP(__foreach_cur); \
|
||||
__foreach_cur = TAIL(__foreach_cur), var = HEAD(__foreach_cur))
|
||||
#define FOREACH_TAIL(var, list) \
|
||||
for (LispVal *var = list; !NILP(var); var = TAIL(var))
|
||||
for (LispVal *var = list; PAIRP(var); var = TAIL(var))
|
||||
|
||||
// #############################
|
||||
// # Allocation and references #
|
||||
@ -650,5 +650,17 @@ static inline LispVal *TAIL(LispVal *list) {
|
||||
CHECK_TYPE(TYPE_PAIR, list);
|
||||
return ((LispPair *) list)->tail;
|
||||
}
|
||||
static inline LispVal *HEAD_SAFE(LispVal *list) {
|
||||
if (!PAIRP(list)) {
|
||||
return Qnil;
|
||||
}
|
||||
return ((LispPair *) list)->head;
|
||||
}
|
||||
static inline LispVal *TAIL_SAFE(LispVal *list) {
|
||||
if (!PAIRP(list)) {
|
||||
return Qnil;
|
||||
}
|
||||
return ((LispPair *) list)->tail;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user