Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Stephen Chang
Here's a program that prints the first 10 Fibonacci numbers: #lang racket (define (lazy-map f . lsts) (define flsts (map force lsts)) (if (ormap null? flsts) null (cons (apply f (map car flsts)) (lazy (apply lazy-map f (map cdr flsts)) (define fib (cons 1 (cons 1

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Jos Koot
Thanks for your interesting replies. It was just my first thought. Jos > -Original Message- > From: users-boun...@racket-lang.org > [mailto:users-boun...@racket-lang.org] On Behalf Of Neil Toronto > Sent: martes, 09 de abril de 2013 22:00 > To: users@racket-lang.org > Subject: Re: [rack

[racket] using Python to pipe data through Racket

2013-04-09 Thread Matthew Butterick
New Racket user, first list question. I'm using scribble/text as a preprocessor language for a system mostly written in Python. What's the best way to process an arbitrary chunk of scribble/text data, using Racket, from within a Python script? Right now I'm making a temp file that begins "#lang

Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Ryan Culpepper
See SRFI-45 (http://srfi.schemers.org/srfi-45/srfi-45.html) for a discussion of why lazy is necessary (ie, why force and delay are not sufficient in practice). Racket's lazy might (?) be slightly different from the one discussed there, though. See this post by Eli for why: http://srfi.schemer

Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Neil Toronto
The following program creates four infinite lists and tries to take the first of each. Only the last expression raises an error. #lang racket (require racket/promise) (define ones (lazy (cons 1 ones))) (define ones* (delay (cons 1 ones*))) (car (force ones)) (car (force ones*)) (define twos

Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Lewis Brown
Thanks, Danny. I am trying to understand how to use promises, in particular for lazy programming. I know there are various implementations that solve this more simply: racket/stream and racket/lazy; but I'd like to see how it's done with the more primitive racket/promise library. It appears tha

Re: [racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Danny Yoo
Are you sure you're not looking for the racket/stream library instead? For example: #lang racket (require racket/stream) (define ones (stream-cons 1 ones)) Racket Users list: http://lists.racket-lang.org/users

[racket] how to use 'lazy' from racket/promise

2013-04-09 Thread Lewis Brown
I'm trying to understand how to use (lazy body ...+) to generate an infinite list. Would somebody please provide an example or two using it, say for ones and fibs. Thanks very much. lb Racket Users list: http://lists.racket-lang.org/users

[racket] Playing with module resolvers

2013-04-09 Thread Danny Yoo
I thought the following example might tickle people: ;; #lang racket/base (require net/url net/uri-codec json) ;; Experiments with module-name-resolvers. (define old-module-name-resolver (current-module-name

Re: [racket] Build documentation with more than one job

2013-04-09 Thread Juan Francisco Cantero Hurtado
On 04/09/13 20:26, Matthew Flatt wrote: At Thu, 07 Mar 2013 01:21:13 +0100, Juan Francisco Cantero Hurtado wrote: On 03/06/13 22:30, Matthew Flatt wrote: Meanwhile, beware that `-j' isn't useful without support for places. (Probably `raco setup' should issue a warning in that case..) OK. I wa

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Neil Toronto
On 04/09/2013 11:41 AM, Hendrik Boom wrote: On Tue, Apr 09, 2013 at 08:26:31PM +0200, Jos Koot wrote: Would it be possible to use Stirling's approximation for a fast inexact first approximation for factorials of very big numbers and from

Re: [racket] Planet2 questions

2013-04-09 Thread Greg Hendershott
In my experience Planet 1 makes introducing a new version enough of an effort that you're not inclined to do it casually. As a result, there's a tendency for changes to accumulate on (say) GitHub, before getting rolled up into a Planet update. At least that's what I found myself doing. With the ne

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Hendrik Boom
On Tue, Apr 09, 2013 at 08:26:31PM +0200, Jos Koot wrote: > Would it be possible to use > Stirling's > approximation for a fast inexact first approximation for factorials of very > big numbers and from there quickly get to an exact factorial

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Jos Koot
Would it be possible to use Stirling's approximation for a fast inexact first approximation for factorials of very big numbers and from there quickly get to an exact factorial? (if exactness is required) I don't know for I haven't thought th

Re: [racket] Build documentation with more than one job

2013-04-09 Thread Matthew Flatt
At Thu, 07 Mar 2013 01:21:13 +0100, Juan Francisco Cantero Hurtado wrote: > On 03/06/13 22:30, Matthew Flatt wrote: > > Meanwhile, beware that `-j' isn't useful without support for places. > > (Probably `raco setup' should issue a warning in that case..) > > OK. I was just testing if "-j N" reduce

[racket] What is racket/cmdline?

2013-04-09 Thread Danny Yoo
Deepak, please place a useful subject line on your emails. Right now, your emails have no subject line, which makes it difficult for people to judge whether or not the question is interesting to them. I'm changing the subject line to "What is cmdline?". --- It's a bit hard to answer this questi

Re: [racket] (no subject)

2013-04-09 Thread Norman Gray
On 2013 Apr 9, at 16:55, deepak verma wrote: > what does command line do? http://docs.racket-lang.org/reference/Command-Line_Parsing.html -- Norman Gray : http://nxg.me.uk SUPA School of Physics and Astronomy, University of Glasgow, UK Racket Users list: http://lis

Re: [racket] Planet2 questions

2013-04-09 Thread Berthold Bäuml
> >> on top of such a low level system one can add more convenient interfaces for >> users for the more standard use cases, e.g., mimicking the version >> disregarding behavior of planet2 -- but it is not possible to do it the >> other way round. > > > Are you sure? You can add commands to

Re: [racket] Planet2 questions

2013-04-09 Thread Matthias Felleisen
On Apr 9, 2013, at 12:18 PM, Berthold Bäuml wrote: > on top of such a low level system one can add more convenient interfaces for > users for the more standard use cases, e.g., mimicking the version > disregarding behavior of planet2 -- but it is not possible to do it the other > way round.

Re: [racket] Planet2 questions

2013-04-09 Thread Berthold Bäuml
On 09.04.2013, at 16:11, Matthias Felleisen wrote: > > On Apr 8, 2013, at 6:03 PM, Berthold Bäuml wrote: > >> Another interesting model for package management (even including, e.g., how >> to check out and commit packages during development) has emerged over the >> last years in our field

[racket] Command line Syntax Checker tool (for Vim)

2013-04-09 Thread Ory Band
I'm looking for a command-line tool to check the syntax of my Racket / PLT-Scheme code. The purpose of this is to build a syntax-checker for Syntastic Vim plugin (https://github.com/scrooloose/syntastic). Something very similar to what gcc, jslint, and other command-line syntax checkers can do.

[racket] (no subject)

2013-04-09 Thread deepak verma
what does command line do? Racket Users list: http://lists.racket-lang.org/users

[racket] (no subject)

2013-04-09 Thread deepak verma
what does the following part in the code do. (module+ main (require racket/cmdline) ;; By default, use as the port. This can be overridden ;; at the command line. (define current-port (make-parameter )) (void (command-line #:once-each [("-p" "--port") p "Port"

Re: [racket] Adding a raco command not working for me

2013-04-09 Thread Greg Hendershott
Carl and Matthew, thank you! On Tue, Apr 9, 2013 at 6:24 AM, Carl Eastlund wrote: > If you want your tool to be in the submodule named main, your definition of > raco-commands should be: > > (define raco-commands '(("frog" (submod frog main) "run Frog" #f))) > > Carl Eastlund > > > On Mon, Apr 8,

Re: [racket] Planet2 questions

2013-04-09 Thread Matthias Felleisen
On Apr 8, 2013, at 6:03 PM, Berthold Bäuml wrote: > Another interesting model for package management (even including, e.g., how > to check out and commit packages during development) has emerged over the > last years in our field of research with the open source ROS (robot operating > system

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Pierpaolo Bernardi
On Tue, Apr 9, 2013 at 3:30 PM, Pierpaolo Bernardi wrote: while the for version should be almost all big x big. > oops, no. The for version should be almost all fix x big. Here's a count considering also the type of the result of the multiplication: > (fact 100) #hash(((fix fix -> fix) . 4

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Pierpaolo Bernardi
On Tue, Apr 9, 2013 at 2:51 PM, Laurent wrote: > On Tue, Apr 9, 2013 at 2:42 PM, Matthew Flatt wrote: > >> (for/product ([p (in-range (+ m 1) (+ n 1))]) p) > > > > But I don't fully understand why a simple (for/product ([p (in-range 1 > (add1 n))]) p) is as fast as the iota variants. > I don't

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Laurent
On Tue, Apr 9, 2013 at 2:42 PM, Matthew Flatt wrote: > (for/product ([p (in-range (+ m 1) (+ n 1))]) p) This fact/for variant is a clear winner: > (time (void (fact/for 100))) cpu time: 6948 real time: 6956 gc time: 964 > (time (void (factorial 100))) cpu time: 9936 real time: 9951 gc

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Matthew Flatt
At Tue, 9 Apr 2013 14:02:27 +0200, Laurent wrote: > But if you write all 10 cases, aren't the lists constructed anyway before > calling `*'? Applying `*' to N arguments doesn't construct a list of N arguments. There's a continuation frame that accumulates the N arguments, but in a way that tends t

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Pierpaolo Bernardi
On Tue, Apr 9, 2013 at 2:02 PM, Laurent wrote: > But if you write all 10 cases, aren't the lists constructed anyway before > calling `*'? > I'll leave the answer to someone who knows exactly how the compiler works. Intuitively, I thought my case should be better, but measuring them gives no app

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Laurent
But if you write all 10 cases, aren't the lists constructed anyway before calling `*'? On Tue, Apr 9, 2013 at 2:00 PM, Pierpaolo Bernardi wrote: > Or, more lispy: > > ;; from included; to excluded. > (define (mult from to) > (case (- to from) > ((0) 1) > ((1) from) > ((2) (* from

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Pierpaolo Bernardi
Or, more lispy: ;; from included; to excluded. (define (mult from to) (case (- to from) ((0) 1) ((1) from) ((2) (* from (+ from 1))) ((3) (* from (+ from 1) (+ from 2))) ;; ... (else (let ((middle (quotient (+ from to) 2))) (* (mult from middle) (mult middle t

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Pierpaolo Bernardi
But why generate lists which are immediately discarded? ;; from excluded; to included (define (mult from to) (case (- to from) ((0) 1) ((1) to) ((2) (* (- to 1) to)) ((3) (* (- to 2) (- to 1) to)) ;; ... (else (let ((middle (quotient (+ from to) 2))) (* (mult

Re: [racket] Adding a raco command not working for me

2013-04-09 Thread Carl Eastlund
If you want your tool to be in the submodule named main, your definition of raco-commands should be: (define raco-commands '(("frog" (submod frog main) "run Frog" #f))) Carl Eastlund On Mon, Apr 8, 2013 at 10:37 PM, Greg Hendershott wrote: > Ah. You mean I need an info.rkt for the package, an

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Laurent
On Mon, Apr 8, 2013 at 9:34 PM, Bradley Lucier wrote: > (define (iota m n) > (let loop ((result '()) > (n (- n 1))) >(if (<= m n) > (loop (cons n result) > (- n 1)) > result))) > > (define (partial-factorial m n) > ;; computes the product (m+1) * ..

Re: [racket] Math - factorial.rkt, binomial.rkt and memoization

2013-04-09 Thread Laurent
On Mon, Apr 8, 2013 at 9:34 PM, Jens Axel Søgaard wrote: > > Would it make sense to use memoization more broadly for the definition > of the factorial > > in the math lib, maybe with a `provide'd parameter to control how many > values can be > > memoized? > > An interesting question. First of all