Tony Garnock-Jones | 30 Oct 22:57 2014

Promises and parameters

Hi all,

Does this seem like the morally-correct thing for promises to do in the
presence of parameters?

-> (define x (make-parameter 3))
-> (define y (parameterize ((x 4)) (delay (list (x)))))
-> (parameterize ((x 5)) (force y))
'(5)

I was expecting '(4), because I felt that delay should be more like let
than lambda, if you see what I mean. That is, I expected that (delay
expr) and (let ((foo expr)) (delay foo)) should be pretty similar except
for exactly when expr gets evaluated.

Tony
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

C K Kashyap | 30 Oct 19:16 2014
Picon

Programmatic drawing

Dear Racket folks,

I'd like to use Dr Racket to generate some drawings. I liked the way I can compose and create images using slideshow. I could not figure how I could draw arbitrary curves though?

When I looked for it I found the racket/draw package. Can the racket/draw functions be used along with slideshow? 

Or is there any other recommended package for achieving interactive drawing creation?

Regards,
Kashyap
____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Byron Davies | 30 Oct 00:01 2014
Picon

Pretty-printing properties in syntax browser

I’m putting large s-expressions as properties on syntax objects.  When I display them in the right pane of
the syntax browser, they go way off the side of the pane.  I’d like to be able to pretty-print the values of properties.

I can’t figure out how to insert pretty-print into the property display routine.  Any ideas?

[I accidentally sent this to dev rather than users.  Sorry to those who get it twice. — Byron]

____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Wayne Iba | 29 Oct 22:23 2014

Typed-Racket slow-down by more than factor of two

I recently posted a question about interactions between a typed/racket module and an untyped module.  Asumu pointed me to a known problem in the contract system that has not yet been addressed.  http://docs.racket-lang.org/guide/contracts-gotchas.html#%28part._.Mixing_set__and_contract-out%29

By adding getter functions for my provided variables, I was able to get the code working.  At this point, about one-fifth of my code is now typed.  Unfortunately, this version is 2.5 times slower than the original.

So my questions:
1. Is this unsurprising?  Do I need to port all of my code before I can expect to see a speed-up?  (And until then can expect a slow-down?)
2. A number of my data structures use byte numbers.  Am I incurring a penalty using Byte and should instead use Index or some other numeric type? (My application hits memory limits so delaying that is important unless it is the case that using the smaller numbers costs many times more than the space required for larger number types.)
3. I'm doing a fair bit of mutation of byte strings and defined structures.  Could this explain the slow down in TR?
4. Could the getter functions added in response to Asumu's pointer be causing significant performance penalties?
5. What else might I consider?

Thanks for any help. --Wayne


____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Konrad Hinsen | 29 Oct 17:32 2014
Picon

Typed Racket frustration

It's one of those days when I wonder if I should keep on playing with
Typed Racket.  It's just too frustrating.

Like my previous frustration events, today's is related to the fact
that Typed Racket implements only some subset of Racket, but that this
is not documented anywhere. On the contrary, the documentation suggests
that my code should work but it doesn't.

Here's an illustration of today's problem. Of course it happened in the
middle of some complex expression in real life - Murphy at work. But even
in this minimal example it's surprising.

------------------------------
#lang typed/racket

(: foo (HashTable Integer Integer))
(define foo (hash 1 2))
------------------------------

The error message is:

------------------------------
 Type Checker: Polymorphic function `hash' could not be applied to arguments:
Wrong number of arguments - Expected 0, but got 2

Argument 1:
  Expected: -none-
  Given:    One
Argument 2:
  Expected: -none-
  Given:    Positive-Byte
------------------------------

DrRacket immediately pops up the documentation of (hash...) to help me:

------------------------------
 (hash key val ... ...) → (and/c hash? hash-equal? immutable?)

  key : any/c
  val : any/c
------------------------------

Of course, the Type Checker can't be wrong, so let's ask it what the type
of hash is:

  ≻ hash
  - : (All (a b) (-> (HashTable a b)))
  #<procedure:hash>

Right, no arguments. So Typed Racket's hash is a restricted version of
plain Racket's hash. But there is no documentation whatsoever of this 
restriction. Searching the Racket docs for hash yields only the one from
racket/base.

Last week's frustration was with for/set. Typed Racket doesn't have its own,
but picks up the one standard Racket which it can't typecheck. You get an
error message from the type checker that you need to add more annotation, and
when you do you get a syntax error. No hint whatsoever that Typed Racket
simply can't handle for/set.

How does anyone get any real work done with Typed Racket?

Konrad.

____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Chrakhan Barzanji | 28 Oct 15:21 2014
Picon

Try-Racket.org

Hi,
i'm trying to understand how Try-Recket Console "post"s a .ajax request to the server and
where ist the server, url? could please some  one explain?
there is also json-parse and 3 .rkt files,
but I just don't get is how they will be called and executed!
As i mentioned before I just want to use the same console like by TryRacket but in my own Website with none-english explaination! thank you..
____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Matthew Butterick | 27 Oct 21:10 2014

macro calling itself

I'm unclear why I'm getting an unbound-identifier error in this macro. I've written other
self-referencing macros in the past that have worked, so I'm unclear why this one doesn't. 

What I expect is that when `definer` is called with one argument, the first branch of `syntax-case` will
stick on a default argument and call `definer` again. Which it does, except that in that case, it only binds
the name 'id' rather than both 'id' and 'arg-id'. 

#lang racket
(require (for-syntax racket/syntax) rackunit)

(define-syntax (definer stx)
  (syntax-case stx ()
    [(_ id)
     #'(definer id zam)]
    [(_ id arg)
     (with-syntax ([arg-id (format-id stx "~a-~a" #'arg #'id)])
       #'(begin
           (define id (quote id))
           (define arg-id (quote arg-id))))]))

(definer foo-id bar)
(check-equal? foo-id 'foo-id)
(check-equal? bar-foo-id 'bar-foo-id)

(definer baz-id)
(check-equal? baz-id 'baz-id)
(check-equal? zam-baz-id 'zam-baz-id) ;; unbound identifier error

OTOH, this version of the macro, which repeats the expansion template rather than calling itself, works fine:

#lang racket
(require (for-syntax racket/syntax) rackunit)

(define-syntax (definer2 stx)
  (syntax-case stx ()
    [(_ id)
     (with-syntax ([arg-id (format-id stx "~a-~a" (format-id stx "zam") #'id)])
       #'(begin
           (define id (quote id))
           (define arg-id (quote arg-id))))]
    [(_ id arg)
     (with-syntax ([arg-id (format-id stx "~a-~a" #'arg #'id)])
       #'(begin
           (define id (quote id))
           (define arg-id (quote arg-id))))]))

(definer2 foo-id bar)
(check-equal? foo-id 'foo-id)
(check-equal? bar-foo-id 'bar-foo-id)

(definer2 baz-id)
(check-equal? baz-id 'baz-id)
(check-equal? zam-baz-id 'zam-baz-id) ;; no error this time
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Bradley Lucier | 27 Oct 19:22 2014
Picon

Re: Nice article on scientific computing in Racket

By the way, I really like the underlying theme that modern floating-point arithmetic has properties as rigorous and well defined as those of integer arithmetic, and these properties can be relied on.

Over the years I've had several people working on multi-precision arithmetic tell me that they just don't "trust" floating-point arithmetic, whether or not there are theorems that describe this behavior precisely.

And in 2003 the great Arnold Schoenhage replied to an email of mine with

> By the way, you may be interested in a very nice paper by Colin > Percival, which has the following review in Math Reviews: ..... > For modern processors where much effort has been placed to make > floating-point arithmetic very fast (often faster than integer > arithmetic), this paper might tip the speed balance to > floating-point-based FFT algorithms. The idea to use floating-point arithmetic because of its actual speed due to extra silicon efforts by the processor manufacturers is like recommending to a sportsman to `run' faster by driving a car. --- Seriously speaking, it is somewhat questionable to develop our algorithms under the biases of existing hardware; rather the hardware should be designed according to basic and clean algorithmic principles! --- Imagine how fast our multi-precision routines would be if some company would be willing to spend that much silicon for a TP32 in hardware!

So not using floating-point arithmetic was also a cultural issue for him!

TP32 is a virtual machine that Schoenhage designed to program multi-precision arithmetic algorithms, much as Knuth designed MIX to implement his algorithms.  (They're roughly at the same level, too, it's like programming in assembler.)  The difference is that TP32 has a relatively fast interpreter.

Brad
____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Konrad Hinsen | 27 Oct 11:05 2014
Picon

Nice article on scientific computing in Racket

The current issue of "Computing in Science and Engineering" has a nice
article by Neil Toronto and Jay McCarthy on "Practically Accurate
Floating-Point Math" in Racket. It is currently freely available
via IEEE's Computing Now platform:

  http://www.computer.org/portal/web/computingnow/content?g=53319&type=article&urlTitle=practically-accurate-floating-point-math

Free access is typically limited in time, so grab your copy now!

Konrad
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Konrad Hinsen | 27 Oct 09:43 2014
Picon

Re: Defining a typed language

E. Moran writes:

 > Thanks for posting this...  I was just wondering if you've considered using the
 > datum->syntax trick, yet.

No, because this is the first time I hear about this!

First of all, your code works fine under Racket 6.1 as well, which is good.

Second, I don't quite understand how it works in detail, which is bad
- for me.  It looks like it does the equivalent of adding (require
a-typed-lang/more) at the beginning of each module that uses
a-typed-lang. That's what I expected my original code to do as
well. Your comment points to the difference, which is somehow related
to the lexical context in which the (require ...) is placed. However,
understanding why this makes a difference seems to require a clearer
idea of how "require" works than I currently have. Is this documented
anywhere?

 > It'd maybe not be the most elegant solution,
 > but it could at least serve to get things moving.

Indeed. I'll update my repository with your working code and a pointer
to this thread. Thanks a lot!

 >   (displayln (impersonator? foo))

A final question: after a quick look at the documentation for impersonators,
this looks like a check that foo is indeed the original function foo and
not something wrapped in a contract, right?

Konrad.
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Hendrik Boom | 27 Oct 03:24 2014

coding with continuations

I've been sort of following Scheme since ages agoo when I read Guy 
Steele's masteer's thesis.  I understand the concepts behind 
continuations. I understad some of the schemes by which they are 
implemented with multiple stacks, stack copying, or even Chey on the 
MTA.

What I don't understand is what kinds of coding patterns are effective 
when using them to do really hairy search problems.

Can anyone give me pointers to intelligible presentations of this kind 
of informmation? 

I seen no point in reinventing wheels.

-- hendrik

____________________
  Racket Users list:
  http://lists.racket-lang.org/users


Gmane