[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] Implementing buffer gap
From: |
felix winkelmann |
Subject: |
Re: [Chicken-users] Implementing buffer gap |
Date: |
Tue, 28 Dec 2004 22:03:28 +0100 |
On Tue, 28 Dec 2004 20:30:01 +0000, Joel Reymont <address@hidden> wrote:
> Folks,
>
> I'm trying to implement a buffer for my mini-editor. I'd like to use the
> buffer gap technique where a gap in the buffer is moved around to the
> edit point. See <http://www.djmnet.org/lore/buffer-gap.txt>.
>
> My issue is picking the right Chicken functions for moving the memory
> around. I thought of using a byte vector and memory-move! but I don't
> think I can use it to move bytes _within_ the byte vector.
>
You can do that, by using locatives:
#;1> (use lolevel)
; loading library lolevel ...
#;2> (define x (string->byte-vector "this is a medium sized string"))
#;3> ,d x
byte vector of size 29:
0: 74 68 69 73 20 69 73 20 61 20 6d 65 64 69 75 6d this is a medium
16: 20 73 69 7a 65 64 20 73 74 72 69 6e 67 sized string
#;3> (move-memory! (make-locative x 5) (make-locative x 18) 2)
#;4> ,d x
byte vector of size 29:
0: 74 68 69 73 20 69 73 20 61 20 6d 65 64 69 75 6d this is a medium
16: 20 73 69 73 65 64 20 73 74 72 69 6e 67 sised string
#;4>
(my apologies for this rather silly example)
Basically, a locative wraps an object and an offset, and move-memory!
accepts locatives as arguments.
cheers,
felix