luksamuk / believe

A Bel Lisp interpreter built with C, written as a book/literate program (archived)
MIT License
52 stars 4 forks source link

`(join)` should work #7

Closed masak closed 5 years ago

masak commented 5 years ago

The join primitive checks that it has exactly two arguments:

Bel*
bel_prim_join(Bel *args)
{
    BEL_CHECK_ARITY(args, 2);
    return bel_mkpair(bel_car(args),
                      bel_car(bel_cdr(args)));
}

But under "Primitives" in the language guide there's this phrase:

Missing arguments default to nil.

In other words, (join) should work, and should mean the same as (join nil nil). The source code itself uses (join) 8 times, to create "empty pairs", often used as markers or to be filled in later.

Even (type) should work — somewhat weirdly — and should presumably return 'symbol (since nothing else is specified).

The definition of applyprim in the Bel source bears this out. There's an error for 'overargs being signaled, but no corresponding error for too few arguments. Instead, car and cadr simply return nil when there are no arguments to be found.

luksamuk commented 5 years ago

Fixing this will be my next task. Also,

The definition of applyprim in the Bel source bears this out. There's an error for 'overargs being signaled, but no corresponding error for too few arguments. Instead, car and cadr simply return nil when there are no arguments to be found.

This calls for attention, then. It seems like this needs fixing on all primitives or on the BEL_CHECK_ARITY macro. Since there is a "max" cap but not a "min" cap, I'll probably rename it to BEL_CHECK_MAX_ARITY or something.