Neil Toronto | 22 Feb 21:51
Picon
Gravatar

TR disappearing types?

The following program types without trouble:

#lang typed/racket

(struct: (a) Foo ())

(: make-foo (All (a) (a -> (Foo a))))
(define (make-foo x)
   (Foo))

(ann (make-foo 1) : (Foo String))

It doesn't seem like it should, though. If this is the right behavior, 
is there a way to get a `Foo' parameterized on type `a' without actually 
storing the value? I'm trying to use TR to check programs that can't 
actually be run (i.e. written in a lambda calculus extended with 
uncountable sets).

Neil ⊥
____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Neil Toronto | 22 Feb 19:17
Picon
Gravatar

How do I make TR refinements work?

When I run this code:

#lang typed/racket

(: ten? (Integer -> Boolean))
(define (ten? x)
   (= x 10))

(declare-refinement ten?)
(define-type Ten (Refinement ten?))

I get this error:

Type Checker: cannot declare refinement for non-predicate Nothing in: 
(Refinement ten?)

But the test in "refinement-even.rkt" uses `even?' to define a 
refinement type, so I must be missing something. What is it?

Neil ⊥
____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Roelof Wobben | 22 Feb 12:49
Picon
Favicon
Gravatar

Re: exercise problem

Op 22-2-2012 9:58, Roelof Wobben schreef:
Thanks,

I have now a answer to my question.
I will debug my programm with check-expect and wil take a look at the second edition.

Roelof



Op 21-2-2012 22:40, Stephen Bloch schreef:

On Feb 21, 2012, at 3:18 PM, Roelof Wobben wrote:

Op 21-2-2012 20:51, Stephen Bloch schreef:
On Feb 21, 2012, at 2:43 PM, Roelof Wobben wrote:
But now I get this error message : unsaved editor>:27:23: function call: expected a function after the open parenthesis, but found a part in: (tarief1 amount) When I do (tarief 1 amount) instead of ((tarief amount))
Yes, that's where the syntax error is. So you've fixed that.

I fixed that?  I always thought that if I use another function that I must be into ().
So In my opinion one () for the then part and one () for the function call.

No, there is no pair of parentheses for the "then" part, only one for the function call.

(cond [question answer]
           [question answer]
           ...
           [question answer])
where each question and each answer is an expression (usually a function call).

1) Have you written a complete set of test cases, with right answers, using "check-expect"? Since there are four categories of input for this problem, you need at least four test cases, and you should probably have three more for the boundaries, a total of seven test cases.

Nope, check-expect is not explained on chapter section 3 of the book how to design programms. So I did not use that function.  I can make test-cases but then in this form

(= (tarief 495) 1,2375)

That should work too, although it's not as convenient.  Make sure you put a bunch of those test cases in the Definitions pane, after the definition:

(define (tarief blah blah)
   blah blah blah
   )

(= (tarief 495) 1,2375)
(= (tarief 0) 0)
(= (tarief 100) whatever)
...

That will also solve the next problem:

3) Have you used the Stepper to watch what your program is doing?

Yes, when I do (payback 2600) on the prompt and press Step I only see a message  All definitions have been sucessfully evaluated and not other outcome so that did not help me any further.

The Stepper only works on expressions in the Definitions pane, not the Interactions pane.  If you put your test cases in the Definitions pane as described above, the Stepper will help you find where things are going wrong.

BTW, check-expect is not discussed in _How to Design Programs_ because it hadn't been invented yet when the book was written.  It's quite easy to use, though: replace the = sign in the above tests with check-expect, and when you hit "Run" you'll get a report of which of your test cases worked, the expected answer and the actual answer.

You might consider working through the Second Edition of _How to Design Programs_ instead; see http://www.ccs.neu.edu/home/matthias/HtDP2e/ .






I found a working solution but I wonder if there is a better way to achieve the answer in the Beginning Student modus.

The solution I found is this one:


(define (tarief4 amount)
  (*(- amount 2500)0.01))
    

(define (tarief3 amount)
  (cond
    [ ( < amount 2500)(* (- amount 1500)0.0075)]
    [ else (  * .0075 1000)]))

(define (tarief2 amount)
  (cond
    [ ( < amount 1500)(* ( - 1000 amount) .0050) ]
    [ else ( * 1000 0.0050)]))


(define (tarief1 amount)
  (cond
    [ (< amount 500) (* 0.0025 amount)]
    [ else (* 0.0025 500)]
    ))


(define (payback amount)
  (cond
    [ (<= amount 500) (tarief1 amount)]
    [ (and ( <= amount 1500) (> amount 500)) (+ (tarief1 amount)(tarief2 amount))]
    [ (and ( <= amount 2500) (> amount 1500)) (+ (tarief3 amount) (tarief2 amount) (tarief1 amount))]
    [ else (+ (tarief4 amount)(tarief3 amount)(tarief2 amount)(tarief1 amount))]
    )
   )


Roelof Wobben

____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Neil Van Dyke | 22 Feb 00:23
Picon
Favicon

anyone want to take over the drracket sicp support?

Anyone want to take over development of the DrRacket SICP support?

http://www.neilvandyke.org/racket-sicp/

It could benefit from a few things:

* Reimplement the language framework-y bits to be more consistent with 
the newer, documented ways of doing language framework-y bits.

* Integrate the picture language code rather than pull from a different 
package (we have agreed to do this).

* Decide whether to do something more like teachpacks or 
problem-set-specific "#lang" or "require", so that user is getting 
exactly the definitions that s/he is supposed to get for a particular 
problem set.

* Work through the SICP exercises, and make test suite based on correct 
assignment answers.  The test suite has already been started.

* Handle the occasional bug report.

If no one volunteers, I will handle the occasional bug report, but 
unlikely that I'll have time to do more than that in the next couple years.

--

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

Roelof Wobben | 21 Feb 20:43
Picon
Favicon
Gravatar

exercise problem

Hello,

I try to make this exercise :

How to Design Programs: An Introduction to Computing and Programming

Some credit card companies pay back a small portion of the charges a customer makes over a year. One company returns

  1. .25% for the first $500 of charges,

  2. .50% for the next $1000 (that is, the portion between $500 and $1500),

  3. .75% for the next $1000 (that is, the portion between $1500 and $2500),

  4. and 1.0% for everything above $2500.

Thus, a customer who charges $400 a year receives $1.00, which is 0.25 · 1/100 · 400, and one who charges $1,400 a year receives $5.75, which is 1.25 = 0.25 · 1/100 · 500 for the first $500 and 0.50 · 1/100 · 900 = 4.50 for the next $900.

Determine by hand the pay-backs for a customer who charged $2000 and one who charged $2600.

Define the function pay-back, which consumes a charge amount and computes the corresponding pay-back amount

So I made this :

(define (tarief4 amount)
  (cond
    [ ( < amount 2500)(- (* .00100 amount)2500)]
    [ else ( - ( * .0100 1000) 2500)]))
 

(define (tarief3 amount)
  (cond
    [ ( < amount 2500)(- (* .0075 amount)1500)]
    [ else ( - ( * .0075 1000) 1500)]))

(define (tarief2 amount)
  (cond
    [ ( < amount 1500)(- (* .0050 amount)500)]
    [ else ( - ( * .0050 1000) 500)]))


(define (tarief1 amount)
  (cond
    [ (< amount 500) (* 0.025 amount)]
    [ else (* 0.025 500)]
    ))


(define (payback amount)
  (cond
    [ (<= amount 500) ((tarief1 amount))]
    [ (and ( <= amount 1500) (> amount 500)) (+ (tarief1 amount)(tarief2 amount))]
    [ (and ( <= amount 2500) (> amount 1500)) (+ (tarief3 amount) (tarief2 amount))]
    [ else (+ (tarief4 amount)(tarief3 amount))]
    ))

   
But now I get this error message :
unsaved editor>:27:23: function call: expected a function after the open parenthesis, but found a part in: (tarief1 amount)

When I do (tarief 1 amount) instead of ((tarief amount)) I don't get the error message but the outcome of (payback 2600) is not right.

Anyone a tip for me ?

Roelof




____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Michael Sperber | 21 Feb 20:01
Picon

Commercial Users of Functional Programming 2012: Call for Presentations


	   COMMERCIAL USERS OF FUNCTIONAL PROGRAMMING 2012
			      CUFP 2012
                       http://cufp.org/conference
			CALL FOR PRESENTATIONS
			 Copenhagen, Denmark
			      Sep 13-15
		      Co-located with ICFP 2012
			 Sponsored by SIGPLAN
	    Talk Proposal Submission Deadline 29 June 2012

The annual CUFP workshop is a place where people can see how others
are using functional programming to solve real world problems; where
practitioners meet and collaborate; where language designers and users
can share ideas about the future of their favorite language; and where
one can learn practical techniques and approaches for putting
functional programming to work.

Giving a CUFP Talk
==================

If you have experience using functional languages in a practical
setting, we invite you to submit a proposal to give a talk at the
workshop. We're looking for two kinds of talks:

Experience reports are typically 25 minutes long, and aim to inform
participants about how functional programming plays out in real-world
applications, focusing especially on lessons learned and insights
gained. Experience reports don't need to be highly technical;
reflections on the commercial, management, or software engineering
aspects are, if anything, more important.

Technical talks are also 25 minutes long, and should focus on teaching
the audience something about a particular technique or methodology,
from the point of view of someone who has seen it play out in
practice. These talks could cover anything from techniques for
building functional concurrent applications, to managing dynamic
reconfigurations, to design recipes for using types effectively in
large-scale applications. While these talks will often be based on a
particular language, they should be accessible to a broad range of
programmers.

If you are interested in offering a talk, or nominating someone to do
so, send an e-mail to sperber(at)deinprogramm(dot)de or
avsm2(at)cl(dot)cam(dot)ac(dot)uk by 29 June 2012 with a short
description of what you'd like to talk about or what you think your
nominee should give a talk about. Such descriptions should be about
one page long.

There will be a short scribes report of the presentations and
discussions but not of the details of individual talks, as the meeting
is intended to be more a discussion forum than a technical
interchange. You do not need to submit a paper, just a proposal for
your talk!  

Program Committee
=================

    Mike Sperber (Active Group), co-chair
    Anil Madhavapeddy (University of Cambridge), co-chair
    Ashish Agarwal (New York University)
    Thomas Arts (QuviQ AB)
    Chris Houser (LonoCloud)
    Tomas Petricek (University of Cambridge)
    Heiko Seeberger (Typesafe)
    Stefan Wehr (factis research)
    Noel Welsh (untyped)

More information
================

For more information on CUFP, including videos of presentations from
previous years, take a look at the CUFP website at
http://cufp.org. Note that presenters, like other attendees, will need
to register for the event. Presentations will be video taped and
presenters will be expected to sign an ACM copyright release
form. Acceptance and rejection letters will be sent out by July 16th.

Guidance on giving a great CUFP talk
====================================

Focus on the interesting bits: Think about what will distinguish your
talk, and what will engage the audience, and focus there. There are a
number of places to look for those interesting bits.

    Setting: FP is pretty well established in some areas, including
    formal verification, financial processing and server-side
    web-services. An unusual setting can be a source of interest. If
    you're deploying FP-based mobile UIs or building servers on oil
    rigs, then the challenges of that scenario are worth focusing
    on. Did FP help or hinder in adapting to the setting?

    Technology: The CUFP audience is hungry to learn about how FP
    techniques work in practice. What design patterns have you
    applied, and to what areas? Did you use functional reactive
    programming for user interfaces, or DSLs for playing chess, or
    fault-tolerant actors for large scale geological data processing? 
    Teach us something about the techniques you used, and why we
    should consider using them ourselves.

    Getting things done: How did you deal with large software
    development in the absence of a myriad of pre-existing support
    that are often expected in larger commercial environments (IDEs,
    coverage tools, debuggers, profilers) and without larger, proven
    bodies of libraries? Did you hit any brick walls that required
    support from the community?

    Don't just be a cheerleader: It's easy to write a rah-rah talk
    about how well FP worked for you, but CUFP is more interesting
    when the talks also spend time on what doesn't work. Even when the
    results were all great, you should spend more time on the
    challenges along the way than on the parts that went smoothly.
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Gustavo Massaccesi | 21 Feb 19:29
Picon
Favicon

Problem with default-indices files in Web-Server

I wanted to make a 100% racket website (no html files), using the
standard plt-web-server.exe (version 5.2.1, Windows). I need that all
the pages are customized to each user.

So I edited the configuration-table.rkt file to include the index.rkt
in the list of default indices.

;--
;Edited File: configuration-table.rkt
( ...
 (default-host-table
   (host-table
     (default-indices "index.rkt" "index.html" "index.htm")
     ...))
 ...)
;--

For example, I use the example from
http://docs.racket-lang.org/web-server/servlet.html as "index.rkt"
(with (require web-server/http/xexpr)) in the web-root/htdoc
directory, and launched the webserver.

If I go to http://localhost/index.rkt , the example works as expected
and I see the "Hi Mom!" message.

But if I go to http://localhost/ , then I get the source code of the
"index.rkt" file, something like.
#lang racket (require web-server/managers/none) ... (...(...(...(body
(h1 "Hi Mom!")))))
but I expected to see only the "Hi Mom!" message.

Now I'm using a index.htm file with a redirection:
<meta http-equiv="REFRESH" content="1;url=/index.rkt">
so the problem is almost solved.

But I don't know if there is a better solution. Another problem is
that the source code of the .rkt files may have some secret info that
the users should not see (this is not my case).

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

Matthias Felleisen | 21 Feb 17:15
Favicon

style: nested cond (fine!)


On Feb 21, 2012, at 8:41 AM, Stephen Bloch wrote:

> On Feb 21, 2012, at 7:18 AM, Rodolfo Carvalho wrote:
> 
>> BTW I just found the nested-cond pattern appearing on HtDP, throughout section 9:
>> http://htdp.org/2003-09-26/Book/curriculum-Z-H-13.html
> 
> That happens when you follow the HtDP design recipe directly and there are conditionals for two unrelated
reasons, e.g. 
> 
> (cond [(empty? L) ...]
>            [(cons? L)
>                 (cond [(snark? (first L)) ...]
>                            [(boojum? (first L)) ...]
>                            [(beeblebrox? (first L)) ...]
>                 )])
> 
> Yes, this COULD be collapsed into ... 

We *subtract* points from solutions when students flatten out such conds in 'CS1'. At this stage in their
development programmers must be able to go from a quasi-algebraic data definitions to code (and back). If
they were to write this code in Java ('CS2'), they wouldn't have conds for the outer part -- they'd use
dispatch. Hence I consider this version the only one that is correct -- morally speaking. 

Adult/experienced programmers may flatten the cond -- if they know certain conditions hold about the data
types involved and **all** programmers who will read their code in the future. 

Eli knows all this -- which is why he wrote that the tool cannot be used without human post-processing. It
isn't an automatic tool -- it must be placed in context. 

-- Matthias

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

Roelof Wobben | 21 Feb 15:49
Picon
Favicon
Gravatar

why here a endless loop

I have this script :

(define (nettoloon h)
   ( - (brutoloon h) (belasting h)))

(define (belasting h)
   (cond
     [(< (brutoloon h) 240) (* 0 (brutoloon h))]
     [(and (< (brutoloon h) 480)  (> (brutoloon h) 240)) ( * 0.15 
(brutoloon h))]
     [else ( * 0.28 ( nettoloon h))]))

(define (brutoloon h)
   (* 12 h))

But it seems there a error in belasting.
When I do (belasting 239) I don't get a answer but a memory error 
problem. And I don't see why this happens.

Can anyone help me finding out what is wrong here ?

Regards,

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

Kieron Hardy | 21 Feb 08:25
Picon
Gravatar

Changing the background color of a GUI button.

Hi all,

How do I change the background color (and/or style of border etc.) of a GUI button? Given the code below, what should I put in the set-state-x methods to indicate a difference between a normal and selected button?

Also any comments on program style and/or substance are appreciated (I apologize in advance if the layout offends).

Cheers,

Kieron.

****

#lang racket/gui

(define color-button%
  (class button%
    (inherit refresh)

    (define toggle
      (let ([f #f])
        (lambda ()
          (set! f (not f))
          f
          )
        )
      )
   
    (define (set-state-normal)
      (printf "color-button%: set-state-normal:\n")
      ; ??? ; set background color to normal
      (refresh)
      )

    (define (set-state-selected)
      (printf "color-button%: set-state-selected:\n")
      ; ??? ; set background color to red
      (refresh)
      )
   
    (define click-callback
      (lambda (button control-event)
        (printf "color-button%: click-callback:\n")
        (if (toggle)
          (set-state-selected)
          (set-state-normal)
          )
        )
      )

    (super-new (callback click-callback))

    )
  )

(define f (new frame%
               [label "Colored Button"]
               [min-width 100]
               [min-height 200]
               )
  )

(define b (new color-button%
              [parent f]
              [label "push me"]
              )
  )

(send f show #t)

____________________
  Racket Users list:
  http://lists.racket-lang.org/users
Joe Gilray | 21 Feb 06:10
Picon
Gravatar

DrRacket crashes

I've been playing with large streams, lists and vectors of primes for the past couple of days and have seen the following behavior on my Win7 system 3 times:


In the middle of a memory intensive operation the disk will start to rattle and the system will be slower (I measured with (time) about a 30% slow down) after several more operations suddenly DrRacket will become unresponsive and Win7 will "search for a solution to the problem" which I cancel.  After about 5 minutes of furious disk rattling the DrRacket session will terminate without a message, but the disk will continue to thrash for about another 15 minutes.

I'm using version 5.2.1

-Joe

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

Gmane