Re: [racket-users] Impersonating a 0-arity function

2015-08-22 Thread Jens Axel Søgaard
Here is an example that wraps create with a procedure that
adds 1 to all elements of the list that create returns.

#lang racket/base

(struct wrap (vals))

(define (create)
  (displayln "A")
  '(1 2 3))

(define create-wrap
  (impersonate-procedure create
(lambda ()
  (displayln "B")
  (λ (result)
(displayln "C")
(displayln (list "Result: " result))
(map add1 result)

(create-wrap)

The result is:

B
A
C
(Result:  (1 2 3))
'(2 3 4)


2015-08-21 1:44 GMT+02:00 Benjamin Greenman :

> I'd like to change the result of a 0-arity function, but I need help
> crafting the right magic spell. Here's my attempt.
>
>
> #lang racket/base
>
> (struct wrap (vals)) ;; Wrap a list
> (define (create) '())
>
> (define create-wrap
>   (impersonate-procedure create
> (lambda ()
>   ;;(values ;; -- this will run, but it doesn't wrap the result
> like I'd like.
>   (values (lambda (r) (wrap r))
>   (values)
>
> (create-wrap) ;; Error! result arity mismatch: expected 1, got 0.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Impersonating a 0-arity function

2015-08-22 Thread Benjamin Greenman
I'd like to change the result of a 0-arity function, but I need help
crafting the right magic spell. Here's my attempt.


#lang racket/base

(struct wrap (vals)) ;; Wrap a list
(define (create) '())

(define create-wrap
  (impersonate-procedure create
(lambda ()
  ;;(values ;; -- this will run, but it doesn't wrap the result
like I'd like.
  (values (lambda (r) (wrap r))
  (values)

(create-wrap) ;; Error! result arity mismatch: expected 1, got 0.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Impersonating a 0-arity function

2015-08-21 Thread Benjamin Greenman
Thank you!

On Fri, Aug 21, 2015 at 2:38 PM, Matthew Flatt  wrote:

> At Fri, 21 Aug 2015 12:44:08 -0400, Benjamin Greenman wrote:
> > I'd like to change the result of a 0-arity function, but I need help
> > crafting the right magic spell. Here's my attempt -- this even possible?
> >
> >
> > #lang racket/base
> >
> > (struct wrap (vals)) ;; Wrap a list
> > (define (create) '())
> >
> > (define create-wrap
> >   (impersonate-procedure create
> > (lambda ()
> >   ;;(values ;; -- this will run, but it doesn't wrap the result
> > like I'd like.
> >   (values (lambda (r) (wrap r))
> >   (values)
> >
> > (create-wrap) ;; Error! result arity mismatch: expected 1, got 0.
>
> Just return the result-wrapping function, since that's one result
> (i.e., one more than the zero results for zero arguments):
>
>  #lang racket/base
>
>  (struct wrap (vals)) ;; Wrap a list
>  (define (create) '())
>
>  (define create-wrap
>(impersonate-procedure create
>  (lambda ()
>(lambda (r) (wrap r)
>
>  (create-wrap)
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Impersonating a 0-arity function

2015-08-21 Thread Matthew Flatt
At Fri, 21 Aug 2015 12:44:08 -0400, Benjamin Greenman wrote:
> I'd like to change the result of a 0-arity function, but I need help
> crafting the right magic spell. Here's my attempt -- this even possible?
> 
> 
> #lang racket/base
> 
> (struct wrap (vals)) ;; Wrap a list
> (define (create) '())
> 
> (define create-wrap
>   (impersonate-procedure create
> (lambda ()
>   ;;(values ;; -- this will run, but it doesn't wrap the result
> like I'd like.
>   (values (lambda (r) (wrap r))
>   (values)
> 
> (create-wrap) ;; Error! result arity mismatch: expected 1, got 0.

Just return the result-wrapping function, since that's one result
(i.e., one more than the zero results for zero arguments):

 #lang racket/base

 (struct wrap (vals)) ;; Wrap a list
 (define (create) '())

 (define create-wrap
   (impersonate-procedure create
 (lambda ()
   (lambda (r) (wrap r)

 (create-wrap)




-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Impersonating a 0-arity function

2015-08-21 Thread Benjamin Greenman
I'd like to change the result of a 0-arity function, but I need help
crafting the right magic spell. Here's my attempt -- this even possible?


#lang racket/base

(struct wrap (vals)) ;; Wrap a list
(define (create) '())

(define create-wrap
  (impersonate-procedure create
(lambda ()
  ;;(values ;; -- this will run, but it doesn't wrap the result
like I'd like.
  (values (lambda (r) (wrap r))
  (values)

(create-wrap) ;; Error! result arity mismatch: expected 1, got 0.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.