[racket-users] Re: Functional augmenting
Hi Neil, On Tue, 8 Jan 2019 14:28:29 -0500, Neil Van Dyke wrote: >In current Racket, the defining module wasn't expecting its own >procedure definition to change out from under it, and other users of >that module also weren't expecting it to change. > >Racket semantics for procedures seems good for software engineering, as >well as for tools static analysis, and as a foundation for DSLs and >other languages implemented as transformations to Racket, and I don't >want to break all that. > >When we want polymorphism, we can use something like generics, which >normally tells both humans and tools that a particular different >abstraction is happening (even if you implemented it with normal >procedures -- the code and documentation would tell you of the >abstraction). Whether to do that is also a decision of the module that >provides the procedure/generic definition and documents it. > >[1] However, if `before` in the quoted example is actually only >syntactic sugar for `define` with `apply`, then it's not mutating the >original procedure, so I can put down the fire extinguisher. AFAICS the example is nothing but a wrapper that mutates the input to the original. I see nothing wrong with that. Even in the case of generics, in no case is the original procedure being mutated. It's simply being superceded by a new [same name] function that (theoretically) adds value. The new function may (or not) call the original as part of its working. For normal functions/procedures I don't see harm in wrappers that specialize them to new environments. This is done all the time. If you are objecting to the wrapper having the same name as the original function then I take your point about potential confusion ... but otherwise I'm lost. >In that >syntactic sugar case, whether to do it is a very local decision, of each >module that internally opts to use that sugar. Maybe that sugar makes >sense, for those particular modules that use it, within whatever >project/organization maintains that source code. George -- 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] Re: Functional augmenting
On Tue, Jan 8, 2019 at 4:35 PM Jens Axel Søgaard wrote: > > Den tir. 8. jan. 2019 kl. 21.40 skrev David Storrs : >> >> >> This. In an ideal world, before/after/around would be parameterized so that >> you can make the change only for a defined scope. >> >> Still, the intent was never that it would extend its effects outside the >> current module. > > In that case you can use let-syntax and to redefine #%app. If we're talking module scope, there's (require (rename-in racket/base [+ rkt:+])), then define + as you prefer, using rkt:+ or not as you like. If we're talking local scope, there's local-require. Or simply (let ([+ my-plus]) (+ 1 2 3)). Both are syntactically apparent. (The first is more apparent when the require is at the top and the module isn't too long.) In terms of cognitive load, it's just roses by other names. If we're talking dynamic scope, then it sounds like generics / classes / passing a function as an argument, are likely to be better than "monkey-patching" or "advising". That kind of stuff has its place for emergency hot-fixes or endless mutable balls of end-user mud like Emacs. But it's refreshingly sane not to have it as part of the language or package ecosystem, I think? -- 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] Re: Functional augmenting
Den tir. 8. jan. 2019 kl. 21.40 skrev David Storrs : > > This. In an ideal world, before/after/around would be parameterized so > that you can make the change only for a defined scope. > Still, the intent was never that it would extend its effects outside the > current module. > In that case you can use let-syntax and to redefine #%app. /Jens Axel -- 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] Re: Functional augmenting
On Tue, Jan 8, 2019 at 12:47 PM Eric Griffis wrote: > Apologies for the backtracking, but I'm still having trouble understanding > before/after/between and ordinary function composition. For non-method > functions, what's the difference? > Easy extension of existing code. For example: (define/contract (process hsh) (-> (hash/c symbol? any/c) list?) (for/list ([key (sort (hash-keys hsh) symbolsymbols)) (before process hash-keys->symbols) Or, perhaps you want to tighten the contract of 'process' from "returns a list" to "returns a list of integers", but only in one module. You can use with-contract, or you can write a wrapper function, or you can say (after process (or/c (and/c (listof integer?) identity) (curry raise-arguments-error 'oops "bad result")) Or, maybe you want to ensure that, iff you're running in debug mode, all calls to 'process' will log their inputs and outputs, but you don't want to modify all the places where 'process' is called in the entire file. How about this?: ; at top of file (when is-debug-mode? (around process (lambda (hsh) (log-debug hsh) (define result (inner hsh)) (log-debug result) result)) ...and now you don't need to change it anywhere else. > Also, I'd never heard of these functions as a Perl dev. A quick search > turns up Moose. Is that what you're talking about? > Yep. On Tue, Jan 8, 2019 at 2:28 PM Neil Van Dyke wrote: > > [1] However, if `before` in the quoted example is actually only > syntactic sugar for `define` with `apply`, then it's not mutating the > original procedure, so I can put down the fire extinguisher. In that > syntactic sugar case, whether to do it is a very local decision, of each > module that internally opts to use that sugar. Maybe that sugar makes > sense, for those particular modules that use it, within whatever > project/organization maintains that source code. This. In an ideal world, before/after/around would be parameterized so that you can make the change only for a defined scope. Still, the intent was never that it would extend its effects outside the current module. -- 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] Re: Functional augmenting
Sorry, I think I was being very unclear. I was only discouraging something `defadvice`-like mutating the behavior of normal Racket procedures, which looks like what was probably originally described: > (define (greet name) (println (string-append "Hi, " name))) [...] > (before greet ~a) ; argument to greet is now passed to ~a before greet gets it > (greet 'bob) "Hi, bob!" I think the most the likely reason one would do `before` like this [1] (rather than simply altering the definition source code of `greet` in the normal fashion, or defining a `greet` or `greet2` that wraps the original `greet`), is that you want to change the behavior of `greet` for other modules/environments, even though you don't normally control the module/environment in which `greet` is defined. So you're mutating a normal procedure object that continues to be used in other environments, which I think defies expectations in Racket. In current Racket, the defining module wasn't expecting its own procedure definition to change out from under it, and other users of that module also weren't expecting it to change. Racket semantics for procedures seems good for software engineering, as well as for tools static analysis, and as a foundation for DSLs and other languages implemented as transformations to Racket, and I don't want to break all that. When we want polymorphism, we can use something like generics, which normally tells both humans and tools that a particular different abstraction is happening (even if you implemented it with normal procedures -- the code and documentation would tell you of the abstraction). Whether to do that is also a decision of the module that provides the procedure/generic definition and documents it. [1] However, if `before` in the quoted example is actually only syntactic sugar for `define` with `apply`, then it's not mutating the original procedure, so I can put down the fire extinguisher. In that syntactic sugar case, whether to do it is a very local decision, of each module that internally opts to use that sugar. Maybe that sugar makes sense, for those particular modules that use it, within whatever project/organization maintains that source code. -- 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] Re: Functional augmenting
My bad. I confused ordinary with generic. On Tue, Jan 8, 2019, 9:47 AM Eric Griffis Apologies for the backtracking, but I'm still having trouble understanding > before/after/between and ordinary function composition. For non-method > functions, what's the difference? > > Also, I'd never heard of these functions as a Perl dev. A quick search > turns up Moose. Is that what you're talking about? > > Eric > > > On Tue, Jan 8, 2019, 8:57 AM David Storrs >> >> >> On Mon, Jan 7, 2019 at 9:58 PM Neil Van Dyke >> wrote: >> >>> George Neuner wrote on 1/7/19 4:49 PM: >>> > Though I mostly agree with you, your "advice" does have its uses: >>> > >>> > >>> http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html >>> > in particular see the sections on method combinations. >>> >>> Thank you; I should've looked it up before incorrectly assuming that you >>> were talking about "advice" from some Lisps. I initially thought the >>> original question was getting at something like `defadvice`: >>> >>> >>> https://franz.com/support/documentation/10.1/doc/operators/excl/defadvice.htm >>> >>> https://www.gnu.org/software/emacs/manual/html_node/elisp/Porting-old-advice.html >>> >>> Part of what bugs me is violation of expectations: In Racket, when I >>> see or use a procedure reference in some code, I expect to get a >>> particular procedure implementation. (Given a straightforward >>> understanding of `#lang`, `require`, scoping, and syntax extension.) If >>> that's instead documented to be a generic, then my expectations change >>> to the implementation I receive (probably) performing an analogous >>> operation. (Actually, in Racket, I'd say generics and classes are >>> usually used only when overriding is definitely happening.) >>> >> >> When I use 'advice' (a term which strikes me as an odd choice -- where >> does it come from?), it's typically because I have a commonly-used library >> function with a defined interface that isn't quite what I need. >> String-handling functions are a good example; if my data sources mean I'm >> going to be feeding either symbols or strings into something that always >> wants strings, then I can either remember to (e.g.) always wrap a (map ~a) >> around the args or I can use a 'before' and call it a day. >> >> >>> -- >>> 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. >> > -- 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] Re: Functional augmenting
Hi Neil, On 1/7/2019 9:58 PM, Neil Van Dyke wrote: George Neuner wrote on 1/7/19 4:49 PM: Though I mostly agree with you, your "advice" does have its uses: http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html in particular see the sections on method combinations. Thank you; I should've looked it up before incorrectly assuming that you were talking about "advice" from some Lisps. I initially thought the original question was getting at something like `defadvice`: https://franz.com/support/documentation/10.1/doc/operators/excl/defadvice.htm https://www.gnu.org/software/emacs/manual/html_node/elisp/Porting-old-advice.html Part of what bugs me is violation of expectations: In Racket, when I see or use a procedure reference in some code, I expect to get a particular procedure implementation. (Given a straightforward understanding of `#lang`, `require`, scoping, and syntax extension.) If that's instead documented to be a generic, then my expectations change to the implementation I receive (probably) performing an analogous operation. (Actually, in Racket, I'd say generics and classes are usually used only when overriding is definitely happening.) I read the pages on defadvice / advise. It seems more general than generic CL before/after/around methods in that [if I understand correctly] advice can be applied to any function, not just one defined by defgeneric. But I'm not sure how your objection applies. Using generic functions really is not different from using a class hierarchy - you expect the different methods (classes) to be somehow related, but you accept that each may do things differently. And you accept that a FOO in one hierarchy may have no relationship whatsoever to a FOO in a different hierarchy. So too, function FOO on one set of data types may have no relation to function FOO on a different set of data types. The before/after/around methods have no analogue in any object system I am aware of. But they do have uses, and implementing their functionality in the objects systems I do know requires instrumenting every [participating] class in the hierarchy. The generic solution saves duplicating a lot of [possibly error prone] type specific code. YMMV, George -- 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] Re: Functional augmenting
On Mon, Jan 7, 2019 at 9:58 PM Neil Van Dyke wrote: > George Neuner wrote on 1/7/19 4:49 PM: > > Though I mostly agree with you, your "advice" does have its uses: > > > > > http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html > > in particular see the sections on method combinations. > > Thank you; I should've looked it up before incorrectly assuming that you > were talking about "advice" from some Lisps. I initially thought the > original question was getting at something like `defadvice`: > > > https://franz.com/support/documentation/10.1/doc/operators/excl/defadvice.htm > > https://www.gnu.org/software/emacs/manual/html_node/elisp/Porting-old-advice.html > > Part of what bugs me is violation of expectations: In Racket, when I > see or use a procedure reference in some code, I expect to get a > particular procedure implementation. (Given a straightforward > understanding of `#lang`, `require`, scoping, and syntax extension.) If > that's instead documented to be a generic, then my expectations change > to the implementation I receive (probably) performing an analogous > operation. (Actually, in Racket, I'd say generics and classes are > usually used only when overriding is definitely happening.) > When I use 'advice' (a term which strikes me as an odd choice -- where does it come from?), it's typically because I have a commonly-used library function with a defined interface that isn't quite what I need. String-handling functions are a good example; if my data sources mean I'm going to be feeding either symbols or strings into something that always wants strings, then I can either remember to (e.g.) always wrap a (map ~a) around the args or I can use a 'before' and call it a day. > -- > 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] Re: Functional augmenting
David Thrane Christiansen wrote on 1/7/19 6:02 PM: A quick grep of the source makes it look like there's at least some support for these. But the docs are certainly less easy to navigate than Scribble docs! The developer of Swindle, Eli Barzilay, was one of the developers of Scribble, as well. :) For now, I think you have to work from various documents and files at: http://barzilay.org/Swindle/ (Swindle goes back to early PLT/Racket days, when you were lucky if you got a "README" file, much less a "doc.txt". You can tell from that Web page that a lot of work went into idiomatic polish for DrScheme at the time. Once there were package systems and richer documentation formats and other tools, I imagine there's only so much expert time and funding to go around, for so much work to be done. Eli is one of the prominent contributors to PLT/Racket who unfortunately I haven't seen on the list in a while.) -- 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] Re: Functional augmenting
George Neuner wrote on 1/7/19 4:49 PM: Though I mostly agree with you, your "advice" does have its uses: http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html in particular see the sections on method combinations. Thank you; I should've looked it up before incorrectly assuming that you were talking about "advice" from some Lisps. I initially thought the original question was getting at something like `defadvice`: https://franz.com/support/documentation/10.1/doc/operators/excl/defadvice.htm https://www.gnu.org/software/emacs/manual/html_node/elisp/Porting-old-advice.html Part of what bugs me is violation of expectations: In Racket, when I see or use a procedure reference in some code, I expect to get a particular procedure implementation. (Given a straightforward understanding of `#lang`, `require`, scoping, and syntax extension.) If that's instead documented to be a generic, then my expectations change to the implementation I receive (probably) performing an analogous operation. (Actually, in Racket, I'd say generics and classes are usually used only when overriding is definitely happening.) -- 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] Re: Functional augmenting
> Swindle/CLOS does implement generic functions, but I'm not aware that it > also implements the before / after / around methods that we have been > talking about. But then, it does so much I may just have missed > something ... its documentation can be tough to read at times. A quick grep of the source makes it look like there's at least some support for these. But the docs are certainly less easy to navigate than Scribble docs! David -- 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] Re: Functional augmenting
On 1/7/2019 5:32 PM, David Thrane Christiansen wrote: > The basic generics machinery isn't terribly hard to implement inside a > compiler. I'm not sure though how I would do it on top of Racket. I'm > sure I could hack up some ugly macros that would work, but it seems like > it needs to be a language to be done right. What about Swindle? https://docs.racket-lang.org/swindle/index.html David Swindle/CLOS does implement generic functions, but I'm not aware that it also implements the before / after / around methods that we have been talking about. But then, it does so much I may just have missed something ... its documentation can be tough to read at times. Thanks for reminding me about it. George -- 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] Re: Functional augmenting
> The basic generics machinery isn't terribly hard to implement inside a > compiler. I'm not sure though how I would do it on top of Racket. I'm > sure I could hack up some ugly macros that would work, but it seems like > it needs to be a language to be done right. What about Swindle? https://docs.racket-lang.org/swindle/index.html David -- 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] Re: Functional augmenting
On 1/7/2019 2:23 PM, Neil Van Dyke wrote: George Neuner wrote on 1/7/19 1:12 PM: Your examples look a lot like what is possible using Lisp's generic functions: specifically "before", "after" and "around" functions. Before/after/around are what I call "advice". Advice is a lifesaver when you need it and there's no good documented interface. For example: "I really-really-really need that one function in that library I use to work differently, but I'm not allowed to modify that library, and I plan to quit this job before anyone else sees my code or tries to update to a new version of that library". But I don't think of advice as good for documented and maintainable code for software engineering. 13 of one, baker's dozen of the other. Though I mostly agree with you, your "advice" does have its uses: http://www.gigamonkeys.com/book/object-reorientation-generic-functions.html in particular see the sections on method combinations. And this is the "documentation" for generic functions in Lisp: http://www.lispworks.com/documentation/HyperSpec/Body/m_defgen.htm#defgeneric http://www.lispworks.com/documentation/HyperSpec/Body/m_defmet.htm#defmethod The basic generics machinery isn't terribly hard to implement inside a compiler. I'm not sure though how I would do it on top of Racket. I'm sure I could hack up some ugly macros that would work, but it seems like it needs to be a language to be done right. YMMV, George -- 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] Re: Functional augmenting
George Neuner wrote on 1/7/19 1:12 PM: Your examples look a lot like what is possible using Lisp's generic functions: specifically "before", "after" and "around" functions. Before/after/around are what I call "advice". Advice is a lifesaver when you need it and there's no good documented interface. For example: "I really-really-really need that one function in that library I use to work differently, but I'm not allowed to modify that library, and I plan to quit this job before anyone else sees my code or tries to update to a new version of that library". But I don't think of advice as good for documented and maintainable code for software engineering. Perhaps half of programming language features and engineering processes is giving us non-advice ways to accomplish our goals. :) (Now I'm bracing for a funny thing that sometimes happens. If you mention something that can be done, but that you discourage, it gets in people's heads, and some people also read up and experiment with it, which gets it more into their heads, and, the next time people are solving a problem, and different solutions are popping into their heads... this can lead to the discouraged thing being done more than if you'd never mentioned it at all. It's like if the language documentation for Racket discusses `eval` prominently, even with discouragement, and then `eval` is in new programmers' heads as a tool to use, before they really understand what are almost always better ways, like a baby velociraptor climbing over a litter of puppies, when what you ultimately need is a nice family dog. Crud; I might've just done it again. :) -- 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] Re: Functional augmenting
On Mon, Jan 7, 2019 at 1:12 PM George Neuner wrote: > Hi David, > > On 1/7/2019 12:57 PM, David Storrs wrote: > > I haven't worked with Racket's generics before, but a quick skim through > the documentation suggests that no, that's not it. Racket generics appear > to relate to collections and structs, whereas I was looking for something > that operates on arbitrary functions. Perhaps I've misunderstood something? > > > I wasn't talking about Racket but about Common Lisp. Your examples look a > lot like what is possible using Lisp's generic functions: specifically > "before", "after" and "around" functions. I was asking if Lisp was the > source of your aspirations. > Ah. No, it wasn't. My aspirations were based on experience in Perl, although Perl may have borrowed these constructs from CL. -- 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] Re: Functional augmenting
Hi David, On 1/7/2019 12:57 PM, David Storrs wrote: I haven't worked with Racket's generics before, but a quick skim through the documentation suggests that no, that's not it. Racket generics appear to relate to collections and structs, whereas I was looking for something that operates on arbitrary functions. Perhaps I've misunderstood something? I wasn't talking about Racket but about Common Lisp. Your examples look a lot like what is possible using Lisp's generic functions: specifically "before", "after" and "around" functions. I was asking if Lisp was the source of your aspirations. Unfortunately I don't know of any existing way to do that in Racket. [Obviously, someone could build the needed infrastructure.] George -- 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] Re: Functional augmenting
On Sun, Jan 6, 2019 at 4:28 PM George Neuner wrote: > On Fri, 4 Jan 2019 13:30:43 -0500, David Storrs > wrote: > > >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!" > > > > : > > > >> (before greet ~a) ; argument to greet is now passed to ~a before greet > >gets it > > > > : > > > >; or, alternatively, instead of pre, let's do: > >> (after greet list) > > > > : > > > >; or, how about full control? > >> (around greet > > (lambda (name) > >(displayln "About to enter greet") > >(inner (~a name)) > >(displayln "After greet"))> > > > Not that I can help wrt Racket, but this looks a lot like generic > functions in Lisp. Is that what you're trying to achieve? > I haven't worked with Racket's generics before, but a quick skim through the documentation suggests that no, that's not it. Racket generics appear to relate to collections and structs, whereas I was looking for something that operates on arbitrary functions. Perhaps I've misunderstood something? Dave > > > George > > -- > 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.
[racket-users] Re: Functional augmenting
On Fri, 4 Jan 2019 13:30:43 -0500, David Storrs wrote: >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!" > > : > >> (before greet ~a) ; argument to greet is now passed to ~a before greet >gets it > > : > >; or, alternatively, instead of pre, let's do: >> (after greet list) > > : > >; or, how about full control? >> (around greet > (lambda (name) >(displayln "About to enter greet") >(inner (~a name)) >(displayln "After greet"))> Not that I can help wrt Racket, but this looks a lot like generic functions in Lisp. Is that what you're trying to achieve? George -- 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.