Skip to content

Commit 126ffec

Browse files
committed
optimized destructuring_bind
1 parent 1ac1d70 commit 126ffec

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

arc.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -625,17 +625,10 @@ namespace arc {
625625
}
626626

627627
error destructuring_bind(atom arg_name, atom val, int val_unspecified, const shared_ptr<struct env>& env) {
628-
if (no(arg_name)) {
629-
if (no(val))
630-
return ERROR_OK;
631-
else {
632-
return ERROR_ARGS;
633-
}
634-
}
635-
else if (arg_name.type == T_SYM) {
628+
switch (arg_name.type) {
629+
case T_SYM:
636630
return env_assign(env, get<sym>(arg_name.val), val);
637-
}
638-
else if (arg_name.type == T_CONS) {
631+
case T_CONS:
639632
if (is(car(arg_name), sym_o)) { /* (o ARG [DEFAULT]) */
640633
if (val_unspecified) { /* missing argument */
641634
if (!no(cdr(cdr(arg_name)))) {
@@ -657,8 +650,13 @@ namespace arc {
657650
}
658651
return destructuring_bind(cdr(arg_name), cdr(val), no(cdr(val)), env);
659652
}
660-
}
661-
else {
653+
case T_NIL:
654+
if (no(val))
655+
return ERROR_OK;
656+
else {
657+
return ERROR_ARGS;
658+
}
659+
default:
662660
return ERROR_ARGS;
663661
}
664662
}

arc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#endif
3636

3737
namespace arc {
38-
constexpr auto VERSION = "0.30";
38+
constexpr auto VERSION = "0.31";
3939

4040
enum type {
4141
T_NIL,

0 commit comments

Comments
 (0)