Re: [racket-dev] safe version of racket/unsafe/ops?

2010-09-28 Thread Robby Findler
You could put all the requires into one file and then re-export
things? (At least for now.) Also, you can end up exporting too much,
ie unsafe-call-with-current-continuation :).

Robby

On Mon, Sep 27, 2010 at 11:20 PM, John Clements
cleme...@brinckerhoff.org wrote:

 On Sep 27, 2010, at 8:14 PM, Robby Findler wrote:

 I was thinking of something like this:

 (require (prefix-in unsafe- racket/fixnum))
 (unsafe-fx+ #f #f)
 fx+: expects type fixnum as 1st argument, given: #f; other arguments were: 
 #f

 Right, but there are lots of unsafe-ops (e.g.: unsafe-vector-length); if I'm 
 working on a large file that uses racket/unsafe/ops, I'd like to just toggle 
 it to racket/unsafe/actuallynotunsafeops to get better error messages.

 John


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


Re: [racket-dev] [plt] Push #21156: master branch updated

2010-09-28 Thread Eli Barzilay
Can we please not have this??  The whole point of having uniform names
is that you can use require/provide things easily so there's no need
for a library.

In addition, the usual way things went so far was to write safe code,
and then turn on unsafely by adding requires with dropping the
prefix, or do it locally by adding `unsafe-'.  Now the development
line would be to start safely, then add unsafe, then to debug you add
this other unsafe thing which is really not unsafe.


7 minutes ago, cleme...@racket-lang.org wrote:
 collects/racket/unsafe/safe-ops.rkt
 ~~~
 --- /dev/null
 +++ NEW/collects/racket/unsafe/safe-ops.rkt
 @@ -0,0 +1,25 @@
 +#lang racket
 +
 +(require racket/fixnum
 + racket/flonum)
 +
 +
 +;; the point of this file is to provide functions that are labeled
 +;; as unsafe but are actually safe.  This provides an easy means to
 +;; disable unsafety; a require of racket/unsafe/ops can be replaced
 +;; with a require of racket/unsafe/safe-ops. 
 +
 +;; this list is almost certainly incomplete; I feel partially justified
 +;; in adding it to the tree anyhow because 
 +;; a) it's easy to extend, and
 +;; b) it appears to me (based on the require of #%unsafe in the corresponding
 +;; 'ops' library) that determining the full set of functions will require
 +;; mucking around in the C source, and not being very confident about 
 +;; my conclusions.
 +
 +
 +(provide (prefix-out unsafe- (all-from-out racket/fixnum))
 + (prefix-out unsafe- (all-from-out racket/flonum))
 + (prefix-out unsafe- (combine-out vector-length
 +  vector-ref
 +  vector-set!)))

-- 
  ((lambda (x) (x x)) (lambda (x) (x x)))  Eli Barzilay:
http://barzilay.org/   Maze is Life!
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] [plt] Push #21156: master branch updated

2010-09-28 Thread John Clements

On Sep 28, 2010, at 8:23 AM, Eli Barzilay wrote:

 Can we please not have this??  The whole point of having uniform names
 is that you can use require/provide things easily so there's no need
 for a library.

Sure, I don't feel strongly about it.  Done.

To be clear, my use case is this: I'm trying to debug a seg fault in a large 
library, with 500 uses of 'unsafe-' operators.  I want to see whether using 
the corresponding safe variants eliminates the crash.  The global search and 
replace is a bit of a pain; replacing racket/unsafe/ops with 
racket/unsafe/safe-ops is much easier.

Naturally, though, you can always roll your own as needed.

John



smime.p7s
Description: S/MIME cryptographic signature
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev

Re: [racket-dev] [plt] Push #21156: master branch updated

2010-09-28 Thread Eli Barzilay
An hour ago, John Clements wrote:
 
 On Sep 28, 2010, at 8:23 AM, Eli Barzilay wrote:
 
  Can we please not have this??  The whole point of having uniform names
  is that you can use require/provide things easily so there's no need
  for a library.
 
 Sure, I don't feel strongly about it.  Done.

Thanks(!)

I should have clarified further -- what we have at the momemt is a
consisten use of an unsafe part in the path for potentially
segfaulting functionality.  So having some unsafe/safe thing doesn't
make much sense (and begs the question about undebugging some things
with unsafe/safe/unsafe).

In any case, I think that something that would have made you happier
is for the `unsafe/foo' libraries to provide the same name as the safe
ones.  This way you'd only need to toggle the `unsafe/' prefix on or
off.  (I'd like that change too, but we're probably deep enough in the
current setup to change that...)


 To be clear, my use case is this: I'm trying to debug a seg fault in
 a large library, with 500 uses of 'unsafe-' operators.  I want to
 see whether using the corresponding safe variants eliminates the
 crash.  The global search and replace is a bit of a pain; replacing
 racket/unsafe/ops with racket/unsafe/safe-ops is much easier.
 
 Naturally, though, you can always roll your own as needed.

First, I think that what was suggested earlier should work -- changing
this:

  (require unsafe/foo)
  -
  (require (prefix-in unsafe- foo))

But the more common use case (which I've done in a number of places)
is to use `foo' first, make sure the code runs and write a ton of
tests, then turn the require into one that *drops* the `unsafe-'
prefix.

A slightly different approach is in `racket/private/sort' -- define
names that are used throughout, and switch the definition from a safe
one to an unsafe one.

-- 
  ((lambda (x) (x x)) (lambda (x) (x x)))  Eli Barzilay:
http://barzilay.org/   Maze is Life!
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] [plt] Push #21156: master branch updated

2010-09-28 Thread John Clements

On Sep 28, 2010, at 10:09 AM, Eli Barzilay wrote:

 An hour ago, John Clements wrote:
 
 On Sep 28, 2010, at 8:23 AM, Eli Barzilay wrote:
 
 Can we please not have this??  The whole point of having uniform names
 is that you can use require/provide things easily so there's no need
 for a library.
 
 Sure, I don't feel strongly about it.  Done.
 
 Thanks(!)
 
 I should have clarified further -- what we have at the momemt is a
 consisten use of an unsafe part in the path for potentially
 segfaulting functionality.  So having some unsafe/safe thing doesn't
 make much sense (and begs the question about undebugging some things
 with unsafe/safe/unsafe).
 
 In any case, I think that something that would have made you happier
 is for the `unsafe/foo' libraries to provide the same name as the safe
 ones.  This way you'd only need to toggle the `unsafe/' prefix on or
 off.  (I'd like that change too, but we're probably deep enough in the
 current setup to change that...)

I thought about this, but I really like the current setup, where the 
unsafe-ness must be indicated at the use of the function.  I think this is 
especially true of common primitives like vector-length.  If I were debugging 
a piece of code, it would never occur to me that an ordinary-looking call to 
'vector-length' might actually be unsafe.

 
 
 To be clear, my use case is this: I'm trying to debug a seg fault in
 a large library, with 500 uses of 'unsafe-' operators.  I want to
 see whether using the corresponding safe variants eliminates the
 crash.  The global search and replace is a bit of a pain; replacing
 racket/unsafe/ops with racket/unsafe/safe-ops is much easier.
 
 Naturally, though, you can always roll your own as needed.
 
 First, I think that what was suggested earlier should work -- changing
 this:
 
  (require unsafe/foo)
  -
  (require (prefix-in unsafe- foo))

This doesn't work for (require racket/unsafe/ops); that's why I wanted to add 
it.

 
 But the more common use case (which I've done in a number of places)
 is to use `foo' first, make sure the code runs and write a ton of
 tests, then turn the require into one that *drops* the `unsafe-'
 prefix.

This frightens me, for the reasons I describe above.

 
 A slightly different approach is in `racket/private/sort' -- define
 names that are used throughout, and switch the definition from a safe
 one to an unsafe one.

That sounds like what you described before, though perhaps I'm not 
understanding you.


John



smime.p7s
Description: S/MIME cryptographic signature
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev

Re: [racket-dev] [plt] Push #21160: master branch updated

2010-09-28 Thread Jon Rafkind

 http://www.cs.utah.edu/~rafkind/tmp/lines.png

This is not yet enabled, to see it change (show-line-numbers?) to #t. I 
don't know how to add menu options and configuration stuff off-hand, if 
anyone can whip it up quickly go for it, otherwise it will take me some 
extra time to figure it out.


Also this doesn't work well for split panes. When the definitions canvas 
is split the line numbers don't get split as well.


On 09/28/2010 02:24 PM, rafk...@racket-lang.org wrote:

rafkind has updated `master' from e4a598ccb2 to d112eb4ceb.
   http://git.racket-lang.org/plt/e4a598ccb2..d112eb4ceb

=[ 1 Commits ]==

Directory summary:
  100.0% collects/drracket/private/

~~

d112eb4 Jon Rafkindrafk...@racket-lang.org  2010-09-28 13:49
:
| add line numbers pane to drracket
:
   M collects/drracket/private/unit.rkt |  143 +++--

=[ Overall Diff ]===

collects/drracket/private/unit.rkt
~~
--- OLD/collects/drracket/private/unit.rkt
+++ NEW/collects/drracket/private/unit.rkt
@@ -447,8 +447,103 @@ module browser threading seems wrong.
  (set! definitions-text% (make-definitions-text%)))
definitions-text%)))

+;; TODO: get this from the configuation file
+;; also add a menu entry that sets this property dynamically
+(define (show-line-numbers?) #f)
+
+;; links two editor's together so they scroll in tandem
+(define (linked-scroller %)
+  (class %
+ (super-new)
+ (field [linked #f])
+ (init-field line-numbers?)
+
+ (inherit insert line-start-position line-end-position)
+
+ (define/public (link-to! who)
+   (set! linked who))
+
+ #;
+ (define/override (scroll-editor-to . args)
+   (printf Scroll editor to ~a\n args))
+ #;
+ (define/override (scroll-to-position . args)
+   (printf Scroll-to-position ~a\n args))
+
+ (define (visible? want-start want-end)
+   (define start (box 0))
+   (define end (box 0))
+   (send this get-visible-line-range start end)
+   (and (= want-start (unbox start))
+(= want-end (unbox end
+
+ (define/public (scroll-to-line start end)
+   (when (not (visible? start end))
+ (send this scroll-to-position
+   (send this line-end-position start)
+   #f
+   (send this line-end-position end
+
+ (define/augment (after-delete start length)
+   (when (not line-numbers?)
+ (when linked
+   (send linked ensure-length (send this last-line
+   (inner (void) after-delete start length))
+
+ (define/augment (after-insert start length)
+   (when (not line-numbers?)
+ #;
+ (printf Send ~a linked ensure-length ~a\n linked (send this 
last-line))
+ (when linked
+   (send linked ensure-length (send this last-line
+   (inner (void) after-insert start length))
+
+ (define/public (ensure-length length)
+   (define lines (send this last-line))
+   #;
+   (printf Line count has ~a needs ~a\n lines length)
+   (when line-numbers?
+ (when (  lines (add1 length))
+   (send this delete
+ (line-start-position (add1 length))
+ (line-end-position lines)
+ #f
+ ))
+ (send this begin-edit-sequence)
+ (for ([line (in-range (add1 lines) (add1 (add1 length)))])
+   #;
+   (printf Insert line ~a\n line)
+   (insert (format ~a\n line)))
+ (send this end-edit-sequence)))
+
+ (define/override (on-paint . args)
+   (define start (box 0))
+   (define end (box 0))
+   (define (current-time) (current-inexact-milliseconds))
+   (send this get-visible-line-range start end)
+   #;
+   (printf text: Repaint at ~a to ~a at ~a!\n (unbox start) 
(unbox end) (current-time))
+   (when linked
+ (send linked scroll-to-line (unbox start) (unbox end)))
+   (super on-paint . args))
+ #;
+ (define/override (on-scroll-on-change . args)
+   (printf Scroller on-scroll-on-change ~a\n args))
+ #;
+ (define/override (scroll-to . args)
+   (printf Scrolled to ~a\n args)
+   #;
+   (super on-scroll event
+
+;; an editor that does not respond to 

[racket-dev] random-access file reading

2010-09-28 Thread John Clements
I want to read a chunk from the middle of a 50-megabyte file.  As far as I can 
see, there are no random-access file primitives currently in DrRacket.  Also, I 
don't see a skip-bytes, so it looks like I should be allocating a junk buffer 
and then repeatedly calling read-bytes to read the skipped portion into the 
junk buffer.  

Tell me if there's a simpler way to do this; doc pointers always appreciated.

John



smime.p7s
Description: S/MIME cryptographic signature
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev

Re: [racket-dev] random-access file reading

2010-09-28 Thread Jay McCarthy
I think you want file-position

http://docs.racket-lang.org/reference/port-buffers.html#(def._((quote._~23~25kernel)._file-position))

Jay

On Tue, Sep 28, 2010 at 3:15 PM, John Clements
cleme...@brinckerhoff.org wrote:
 I want to read a chunk from the middle of a 50-megabyte file.  As far as I 
 can see, there are no random-access file primitives currently in DrRacket.  
 Also, I don't see a skip-bytes, so it looks like I should be allocating a 
 junk buffer and then repeatedly calling read-bytes to read the skipped 
 portion into the junk buffer.

 Tell me if there's a simpler way to do this; doc pointers always appreciated.

 John


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




-- 
Jay McCarthy j...@cs.byu.edu
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

The glory of God is Intelligence - DC 93
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev

Re: [racket-dev] random-access file reading

2010-09-28 Thread Andreas Rottmann
John Clements cleme...@brinckerhoff.org writes:

 I want to read a chunk from the middle of a 50-megabyte file.  As far
 as I can see, there are no random-access file primitives currently in
 DrRacket.  Also, I don't see a skip-bytes, so it looks like I should
 be allocating a junk buffer and then repeatedly calling read-bytes to
 read the skipped portion into the junk buffer.

 Tell me if there's a simpler way to do this; doc pointers always appreciated.

http://docs.racket-lang.org/reference/port-buffers.html?q=binary-input-p#%28def._%28%28quote._~23~25kernel%29._file-position%29%29

I think this should do the job.

Cheers, Rotty
-- 
Andreas Rottmann -- http://rotty.yi.org/
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev