Re: [racket] polymorphic functions

2012-10-14 Thread Asumu Takikawa
On 2012-10-13 23:18:27 +0300, Răzvan Rotaru wrote: >@Greg, I know sequences and the functions around it, and they are indeed >part of what I'm looking for. Essentially, I am speaking about replacing >the core scheme functions, which work with lists, with generic versions >that work

Re: [racket] Function composition in Racket

2012-10-14 Thread Justin R. Slepak
To use prop:procedure, just give a function which will handle the application of the structure to some arguments. The define-values is only there because the for/fold has two accumulators (sum and x) and will therefore return two values (the values of those accumulators). This means its context

Re: [racket] Function composition in Racket

2012-10-14 Thread Justin R. Slepak
Instead of trying to peek inside a lambda, you could implement polynomials as (transparent) structs and use prop:procedure to allow them to be applied to numbers: (struct polynomial (coeffs) #:transparent #:property prop:procedure (lambda (poly num) (define-values (result x*) (fo

Re: [racket] Function composition in Racket

2012-10-14 Thread Gregory Woodhouse
Uh... never mind. I should have looked for the obvious > (define (f x) (+ x 1)) > (define (g x) (* x x)) > ((compose f g) 1) 2 > ((compose f g) 2) 5 > On Oct 14, 2012, at 4:00 PM, Gregory Woodhouse wrote: > Now, my question is: is there a notation in Racket for representing > composition tha

[racket] Function composition in Racket

2012-10-14 Thread Gregory Woodhouse
I wrote a small recursive function to convert a list (a0 a1 ... an) coefficients into a polynomial function ;;Given a list (a0 a1 ... an) return a function that computes ;;p(x) = a0 + a1*x + ... + an*x^n (define (polynomial coeffs) (lambda (x) (cond [(= (length coeffs) 0) 0] [