[racket-dev] Preserving trailing zeros in formatting numbers as strings

2014-05-02 Thread Kathi Fisler
I'm generating class notes in HTML via scribble.  I'm trying to include the
number 10.50 (as a price in an test case, so the trailing 0 matters).  I'm
using format to produce the strings that go into the rendered html.  When I
do this (whether with ~a or ~s), the trailing 0 is dropped, producing 10.5
in my output instead of 10.50.

What can I do to preserve trailing zeros?

thanks,
Kathi
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] Implementation question

2014-05-02 Thread nicolas carraggi
Hey guys,
Thanks a lot for your quick answers!
My ping method now:
(define (ping hostname port-no personalip)  (define t (thread 
(lambda ()   (with-handlers ((exn:fail:network? (lambda (x) (begin 
(displayln (string-append hostname : (number-string port-no)  
NOO)) #f;(displayln (exn-message x) 
(define-values (in out) (tcp-connect hostname port-no)) (write 
'ping out) (write personalip out) 
(flush-output out) (display (string-append hostname : 
(number-string port-no)  )) (displayln (read in))
 (close-input-port in) (close-output-port out)  
   #t  (sync/timeout 0.01 t)  (kill-thread t))
+
This is the result when I do a multicast from 192.168.1.0 to 192.168.1.200. ( a 
lot of these don't exist and that's why tcp-connect was taking ages to throw an 
error.) Those returning a NO are existing network nodes where no server is 
running. Pong is the answer from the server running on my laptop.
 (multicast-ping 192.168.1.100 8080 0 200)192.168.1.0:8080 
 NOO192.168.1.105:8080 NOO192.168.1.108:8080 
 pong---Multicast finished!
+

It's still test-code but it's working fine now, maybe the timout time is too 
small but now it works well!
Greetings,Nicolas
Subject: Re: [racket-dev] Implementation question
From: matth...@ccs.neu.edu
Date: Sat, 19 Apr 2014 09:25:27 -0400
CC: nicocarra...@hotmail.com; dev@racket-lang.org
To: laurent.ors...@gmail.com


Let me recommend events instead: 
#lang racket
;; Nat - Void ;; wait for t seconds before connecting to google.com, then 
stop(define (do-work t)  (thread   (lambda () (with-handlers 
((exn:fail:network? (lambda (x) (displayln (exn-message x)   (sleep t)  
 (define-values (in out) (tcp-connect google.com 80))'done
;; returns #f if 3 seconds pass w/o the thread shutting down (sync/timeout 3 
(do-work (random 6)))


On Apr 19, 2014, at 8:34 AM, Laurent wrote:One simpler possibility is to use 
`tcp-connect/enable-break` and run a timer in parallel to break it after a 
shorter delay.
For example:

(define-values (in out) (values #f #f))



(define connect-thread
  (thread
   (λ()(set!-values (in out) 
(tcp-connect www.google.com 80)

(sleep 3)
(unless in
  (displayln Connection not established. Breaking thread.)


  (break-thread connect-thread))

The timer can also be place into its own thread if you need to set up several 
connections in parallel.

Hope this helps,Laurent




On Thu, Apr 17, 2014 at 6:48 PM, nicolas carraggi nicocarra...@hotmail.com 
wrote:





Hello,
I am actually using Racket/tcp for a project in Racket.I'm creating a 
peer-to-peer network but now I encountered a small problem.For a multicast I 
want to connect with each server on the same network. 

For this I use tcp-connect, but when i try to connect to an ip address which 
is not hosting a server, throwing the error only happens after more than 1 
minute. So I would like to use a modified tcp-connect with a smaller time-out.


Where can I find the implementation of tcp-connect?
I already found tcp.rkt but there it gets the tcp-connect method from 
'#%network but I can't find this one...


Greetings!Nicolas 

_

  Racket Developers list:

  http://lists.racket-lang.org/dev




_
  Racket Developers list:
  http://lists.racket-lang.org/dev

  _
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] Preserving trailing zeros in formatting numbers as strings

2014-05-02 Thread Asumu Takikawa
On 2014-04-24 05:25:07 -0400, Kathi Fisler wrote:
I'm generating class notes in HTML via scribble.  I'm trying to include
the number 10.50 (as a price in an test case, so the trailing 0 matters).
 I'm using format to produce the strings that go into the rendered html.
 When I do this (whether with ~a or ~s), the trailing 0 is dropped,
producing 10.5 in my output instead of 10.50.  

Maybe this is too late to be useful (I think the mailing list ate your
post?), but here's one way to do it:

   (~r 10.5 #:precision '(= 2))
  10.50

Cheers,
Asumu
_
  Racket Developers list:
  http://lists.racket-lang.org/dev