Re: [racket-users] cons-specific optimizations?

2018-11-28 Thread Gustavo Massaccesi
The last example should be (when (and (list? l) (pair? l)) (let ([x (cdr l)]) (list? x) ;==> #t )) Gustavo Technical note: The optimizer wants to be sure that (cdr l) is safe before asserting that x is a list?. It should be ok to mark x as a list?, because if there is an error the inner

Re: [racket-users] cons-specific optimizations?

2018-11-28 Thread Gustavo Massaccesi
Some additional comments about this subject. A big difference is that in Chez Scheme the cons are mutable, and that makes it almost impossible to make any optimization with the lists at the Chez Scheme level. With the current Racket implementation there are a few reductions at compile time for

Re: [racket-users] cons-specific optimizations?

2018-11-28 Thread Matthew Flatt
Right. An alternative would be to set decide eagerly, but `list?` tests are infrequent relative to pair constructions. Then again, a function like `list` can and does set the "is a list" bit eagerly and cheaply on newly allocated pairs. At Wed, 28 Nov 2018 18:16:31 +0100, Robby Findler wrote: >

Re: [racket-users] cons-specific optimizations?

2018-11-28 Thread George Neuner
On 11/28/2018 12:15 PM, Alexis King wrote: > On Nov 28, 2018, at 07:15, Matthew Flatt wrote: > > Yes, that's special handling for pairs in the sense that the > traditional Racket implementation takes advantage of leftover bits in a > pair object, and it uses two of them for "is a list" and

Re: [racket-users] cons-specific optimizations?

2018-11-28 Thread Robby Findler
Also "don't know yet". Robby On Wed, Nov 28, 2018 at 6:15 PM Alexis King wrote: > > On Nov 28, 2018, at 07:15, Matthew Flatt wrote: > > > > Yes, that's special handling for pairs in the sense that the > > traditional Racket implementation takes advantage of leftover bits in a > > pair object,

Re: [racket-users] cons-specific optimizations?

2018-11-28 Thread Alexis King
> On Nov 28, 2018, at 07:15, Matthew Flatt wrote: > > Yes, that's special handling for pairs in the sense that the > traditional Racket implementation takes advantage of leftover bits in a > pair object, and it uses two of them for "is a list" and "not a list". > > Racket-on-Chez doesn't have

Re: [racket-users] cons-specific optimizations?

2018-11-28 Thread Matthew Flatt
At Wed, 28 Nov 2018 03:13:16 -0800 (PST), Tony Garnock-Jones wrote: > On Wednesday, November 28, 2018 at 2:43:26 AM UTC, Matthew Flatt wrote: > > > > The compilers in both cases know some facts about how `cons` relates to > > other primitives, but they also know how structure constructors and >

Re: [racket-users] cons-specific optimizations?

2018-11-28 Thread Tony Garnock-Jones
On Wednesday, November 28, 2018 at 2:43:26 AM UTC, Matthew Flatt wrote: > > The compilers in both cases know some facts about how `cons` relates to > other primitives, but they also know how structure constructors and > accessors relate, so it's not as big a difference at that level. > There

Re: [racket-users] cons-specific optimizations?

2018-11-27 Thread Matthew Flatt
Pairs are special in both traditional Racket and Chez Scheme. In the traditional Racket implementation, every allocated object has a 16-bit tag, and one of those is "pair". For a structure, the tag is "structure", and then there's another word for the structure type. So, the test for a pair is

Re: [racket-users] cons-specific optimizations?

2018-11-27 Thread Vishesh Yadav
I recall reading some 6.x code for RacketScript, and in 6.x world pair was simply a pair of pointers in C structure[1] and `cons` was again a primitive function that created those C objects[2]. No special representation in byte-code [all values are opaque to bytecode (except ints and floats I

[racket-users] cons-specific optimizations?

2018-11-27 Thread Milo Turner
Hello all, There's something I have been very curious of lately, about low level aspects of Racket's compiler. First of all, I have always considered "cons" to be essentially the same as a struct: (struct cons [hd tl] #:transparent) (define car (procedure-rename cons-hd 'car)) (define cdr