Racket's OO system has the 'augment' family of functionality that allows
you to change how a function works.  I'm wondering if there's a way to do
something similar in functional Racket.  For example, when I was working in
Perl I used to be able to do something like this Racket pseudocode:

> (define (greet name)
  (println (string-append  "Hi, " name)))

> (greet "bob")
"Hi, bob!"

> (greet 'bob)
; string-append: contract violation
;   expected: string?
;   given: 'bob
;   argument position: 2nd
; [,bt for context]

> (before greet ~a)  ; argument to greet is now passed to ~a before greet
gets it

> (greet 'bob)
"Hi, bob!"

; or, alternatively, instead of pre, let's do:
> (after greet list)

> (greet "bob")
'("Hi, bob!")

; or, how about full control?
> (around greet
  (lambda (name)
    (displayln "About to enter greet")
    (inner (~a name))
    (displayln "After greet"))

> (greet 'bob)
About to enter greet
"Hi, bob!"
After greet

Is there an equivalent in Racket?

-- 
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.

Reply via email to