[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add new lisp function length= with bytecode support

From: Gdobbins
Subject: Re: [PATCH] Add new lisp function length= with bytecode support
Date: Fri, 10 Mar 2017 17:25:19 -0500

> The documentation indicates that numbers are permitted

That should have been integers. Both in the documentation and in the code.

> I gather internal--length-compare (specifically the nthcdr bit) works for “less than” but not for “greater than”, and thus the reversal approach is actually required, not just a way to reduce the quantity of code generated. Is that correct?

It's actually a limitation of the whole nthcdr approach. You can only ever save list traversal on the last argument with <, but not any with > since you need to know whether it will get bigger than the preceding argument.

> But I think
> (length< some-big-list 5)
> could still limit the work it does by using nthcdr, couldn’t it? Implement it the same as:
> (not (length< 4 some-big-list))

This sort of approach could work and would obviate the previous problem as well. I think it would be best to do it in a compiler macro which acts when passed literal numbers rather than variables holding numbers. That case is more common anyway, and it would prevent extra run-time computation.

> The doc string mention of “more efficient” is ambiguous; more efficient than what? Are you comparing against using “length” and “>”? Or are you comparing different ways the arguments to the function might be arranged?

The second one.

I'm actually considering an entirely different approach toward changing the bytecode interpreter which will be backwards compatible, not require new bytecodes, and improve run-time for these cases. If it's acceptable then it will greatly affect how length= and related can and should be implemented.

-- Graham Dobbins

reply via email to

[Prev in Thread] Current Thread [Next in Thread]