[racket] Low level manipulation on numbers

2011-10-08 Thread nicolas.o...@gmail.com
Dear all,

I am trying to write a small implementation of Protocol Buffers (
http://code.google.com/p/protobuf/  ) and I have difficulties
with bit manipulations, especially to transform a negative integer into a
series of bytes and back.

I can not find an implementation of a non-arithmetic shift for fixnums, and
a way to specify which size of fixnum to construct.

I can't also find an easy way to get the byte representation of flonums.

Do you have any idea?

Best regards,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Low level manipulation on numbers

2011-10-08 Thread nicolas.o...@gmail.com
Thank you so much for your very quick answer.
It seems that the conversion to and from bytes are what I was looking for.
With that, it is quite easy to do all the manipulations I want.

Best,

Nicolas.


On Sat, Oct 8, 2011 at 6:57 PM, Matthew Flatt  wrote:

> At Sat, 8 Oct 2011 17:41:35 +0100, "nicolas.o...@gmail.com" wrote:
> > I am trying to write a small implementation of Protocol Buffers (
> > http://code.google.com/p/protobuf/  ) and I have difficulties
> > with bit manipulations, especially to transform a negative integer into a
> > series of bytes and back.
> >
> > I can not find an implementation of a non-arithmetic shift for fixnums,
> and
> > a way to specify which size of fixnum to construct.
>
> There aren't different sizes of fixnums. When you want to convert an
> exact integer to bytes, then `integer->integer-bytes' lets you specify
> the size.
>
> There also isn't a logical shift operator, if I understand what you're
> after. If you work with positive integers, then `arithmetic-shift'
> (plus `bitwise-and'?) behaves like a logical shift. If you want
> logical-shift effects for finite 2's complement representations, then
> you probably don't really want to work on fixnum representations, which
> are 63 or 31 bits, but instead some power of 2 via bitwise operations
> like `bitwise-ior', `bitwise-and', and arithmetic shifts of negative
> numbers. Note also that `integer-bytes->integer' lets you say whether
> to interpret a set of bytes as unsigned or as 2's complement.
>
> > I can't also find an easy way to get the byte representation of flonums.
>
> `real->floating-point-bytes'
>
>


-- 
Sent from an IBM Model M, 15 August 1989.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

[racket] begin and let/cc

2011-10-14 Thread nicolas.o...@gmail.com
Dear all,

I don't understand this behaviour:

> (define k #f)
> (begin (let/cc out (set! k out)) 5)
5
> (k #f)
#f
> (let () (let/cc out (set! k out)) 5)
5
> (k #f)
5


Does begin something special regarding continuation?


Best regards,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] begin and let/cc

2011-10-14 Thread nicolas.o...@gmail.com
Thank you so much. That clarifies it.
Is there a list of forms that splice into their context?

On Fri, Oct 14, 2011 at 9:27 PM, Jos Koot  wrote:

> **
> In addition to my previous mail:put the code in the definitions window of
> DrRacket and use the macro stepper to see how the code is expanded.
> Jos
>
>  --
> *From:* users-boun...@racket-lang.org [mailto:
> users-boun...@racket-lang.org] *On Behalf Of *nicolas.o...@gmail.com
> *Sent:* viernes, 14 de octubre de 2011 21:40
> *To:* users@racket-lang.org
> *Subject:* [racket] begin and let/cc
>
>  Dear all,
>
> I don't understand this behaviour:
>
> > (define k #f)
> > (begin (let/cc out (set! k out)) 5)
> 5
> > (k #f)
> #f
> > (let () (let/cc out (set! k out)) 5)
> 5
> > (k #f)
> 5
>
>
> Does begin something special regarding continuation?
>
>
> Best regards,
>
> Nicolas.
>



-- 
Sent from an IBM Model M, 15 August 1989.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

[racket] Liveliness of variables and GC

2011-10-26 Thread nicolas.o...@gmail.com
Dear all,

I am struggling to find the origin of a memory leak in a small program I
wrote.
In order to help me searching, I would like to know a few details on the
implementation of Racket.

1)
(define (f x y)
(lambda () x))
(define g (f 2 veryBigObject) )

Can I be sure that g does not retain a pointer to veryBigObject?


2) (g is a function)

(define (f)
   (let ([x veryBigObject])
  (g)))

Can I be sure that veryBigObject is not retained by f during the execution
of g?

3) Same program.
g now captures its continuation. Can I be sure that this continuation does
not retain veryBigObject?


Best regards,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Liveliness of variables and GC

2011-10-26 Thread nicolas.o...@gmail.com
Thank you so much for the very quick answer.

Best,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Liveliness of variables and GC

2011-10-27 Thread nicolas.o...@gmail.com
I am still struggling a bit.

Is there a way to profile/snapshot/inspect memory?

What is the canonical way to find a memory leak in a Racket program?

Best regards,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

[racket] Memory and delimited continuations

2011-10-27 Thread nicolas.o...@gmail.com
Dear all,

Following on my memory leak problem, I managed to minimise my program.
And I still don't understand why it leaks.

Here is a minimised example:

(define prompt1 (make-continuation-prompt-tag 'p1))
(define prompt2 (make-continuation-prompt-tag 'p2))

(define (capture-and-abort prompt-tag)
  (call-with-composable-continuation
   (lambda (k) (abort-current-continuation prompt-tag k))
  prompt-tag))

(define (test i)
   (call-with-continuation-prompt
 (lambda ()
   (call-with-continuation-prompt
(lambda()
  (for ((j i))
(capture-and-abort prompt1)
(capture-and-abort prompt2)))
prompt2))
   prompt1))

(test 10)

Calling test with any number 100 000 or higher will allocate memory very
fast.
What is the reason for that and how can I solve this?

Best regards,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Memory and delimited continuations

2011-10-29 Thread nicolas.o...@gmail.com
Thank you very much.
If I can help in any way, please ask.

Best regards,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Memory and delimited continuations

2011-10-29 Thread nicolas.o...@gmail.com
The new master version got rid of my memory leak.
Thank you so much for the quick patch.

Best,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] DrRacket needs work

2011-11-13 Thread nicolas.o...@gmail.com
I like Dr Racket very much,  but I have a small problem that might be easy
to solve:

When hitting return in the middle of a line, in the REPL, in does not
evaluate the line but adds a line break.
I think this might be the right behaviour but I would like to have a way to
send the s-expr to evaluation without having to go to
the end of the s-expr first.

Is there a way to do that?

Best,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] DrRacket needs work

2011-11-13 Thread nicolas.o...@gmail.com
It works. Thank you very much.


On Sun, Nov 13, 2011 at 1:40 PM, Chris  wrote:

> +1 on this. I know other REPLs (at least python) do the same, but I think
> behaving like a command line would be more natural to most people.
> Ctrl+Enter to evaluate, Enter to line break would be nice too.
>
>
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

[racket] Sending a method as a symbol

2011-11-13 Thread nicolas.o...@gmail.com
Dear all,

Is there a function to send to a class with a dynamic symbol instead of a
static one?

As in (send  'method-name)

send seems to reduce to find-method/who, but this function is not exported.

Best regards,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Sending a method as a symbol

2011-11-16 Thread nicolas.o...@gmail.com
On Tue, Nov 15, 2011 at 8:14 PM, Grant Rettke  wrote:

>
> That is like eval but for talking to objects?
>


More like looking up an interned symbol from a namespace.
(A very limited form of eval...)

Best,
Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users

Re: [racket] Implementing delimited continuations using a CPS transform

2011-11-24 Thread nicolas.o...@gmail.com
I think your solution is perfectly sensible.

shift/reset needs two CPS transformations. Then you have two
continuations : one local (up to the next reset), one global
(from the next reset to the toplevel). The global one is usually
called the meta-continuation, and often denoted m.

I think this is explained in "Abstracting Control" by Filinski and Danvy.

This blog post shows an evaluator for shift/reset where you can see
the two continuations at work:

http://calculist.blogspot.com/2006/11/shift-and-reset-via-two-continuations.html


Best regards,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Implementing delimited continuations using a CPS transform

2011-11-24 Thread nicolas.o...@gmail.com
> But you could also break the tail-call discipline of CPS and translate [shift 
> e] as \k. (k [e](\x.x))
> Or you can use our 'abstract' continuations to manipulate a stack of 
> continuations directly.

What are your 'abstract' continuations? Sounds very interesting.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Implementing delimited continuations using a CPS transform

2011-11-24 Thread nicolas.o...@gmail.com
It is often used to represent a function that applies on a term, or an
expression.

  [ t ]  means the function [] applied to t.

In those papers, it often represent a CPS transform.

Like [ x ] = \ k . k x would mean "the cps transform of 'x' is '\ k .
k x' , or cps(x) = \ k . k x.

Using [ _ ] is a bit nicer.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users


Re: [racket] Racket Web Server

2011-12-12 Thread nicolas.o...@gmail.com
>
> PS You also mentioned sedna. I'm guessing you might also be frustrated
> with relation databases? I am also tired of writing ORMs and am using the
> move to Racket as a good chance to move to different ways of storing
> data, I've found that Riak http://wiki.basho.com/ works well, and its the
> best fit for the type of apps I develop.


Hi,

Riak looks very nice indeed. Do you have any library to interface
Racket with Riak?

Best regards,

Nicolas.
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/users