3 ms·
Can anyone describe a use-case for "first class messages"?
by amitport 6y ago
Can anyone describe a use-case for "first class messages"?
- ww520 6y agoI think it's similar to partial function application. First class message is a partially applied function with some parameters bound and some "parameter holes" left unbounded. When the message is sent to a target, the rest of the parameters are filled in to build the full message to be sent. In that case, complicate messages with lots of parameters can be pre-built with parameters partially filled in. The pre-built messages can then be repeatedly used subsequently. I think that's how it works. OTOH, I could have completely misunderstood the first class message idea. Someone more familiar with the language can probably explain better.
- zelphirkalt 6y agoAlthough, could this message thing not be modelled with lambdas taking remaining "holes" as arguments, "formatting" the message, which are given as arguments to functions? The gain seems smaller than the gain from first class procedures, but it is an interesting idea, which might avoid some lambda wrapping in the code.
- bjoli 6y agoI don't think I have to explain this to you (hello fellow guiler!), but in a language with first class procedures and proper macros there doesn't have to be any lambda typing overhead. I implemented "megacut" in guile, which is a clojuresque lambda shorthand: #%(+ %1 5 (* %2 4)) => (lambda (%1 %2) (+ %1 5 (* %2 4))) in about 30 lines of code (unhygienically, though, but that should be a small fix in a psyntax-based scheme)
- zelphirkalt 6y agoHehe, you are correct, indeed I did not think of macros in the moment. We do have some megacut wrapping overhead then though ;) Can you post a link to the macro on the Guile user list? Perhaps someone can rewrite it to a hygienic macro. Some people there very proficient in macrology. I am not that proficient in macrology. I am also trying to maintain a list of libraries and things for Guile, which I could add this too.
- bjoli 6y agoI have written enough macros to be able to do it (among others, the guile-for-loops macros). There are some issues with a macro like this. I can make it quasi-hygienic by hygienically checking for megacut (right now I am just comparing symbols, as returned by datum->syntax). Doing it in another way than "Any binding looking like %n and %& will be captured and shadowed" is pretty much unsolved using any standard scheme. I could probably hack something together using syntax-locally-bound-identifiers, but then I would have to implement local macro expansion (which is possible. I'm just lazy!). The link is https://hg.sr.ht/~bjoli/megacut/ https://hg.sr.ht/~bjoli/megacut/ Btw, the link for guile-for-loops should be updated in your list: https://hg.sr.ht/~bjoli/guile-for-loops https://hg.sr.ht/~bjoli/guile-for-loops
- zelphirkalt 6y agoThanks! I'll get to it later : )
- tgv 6y agoLike (partial) functions as values, you can pass along the message/method, e.g. as a parameter to another function. In other languages, you'd have to create a function for each message/method, and more than one if it's overloaded (although I don't know how Elena handles that).
- arakov 6y agoA first class message is similar to the function to invoke this message. So it is just a special case of first class function. I uses first class messages to implement a dynamic record - http://www.rosettacode.org/wiki/Dynamic_variable_names#Elena http://www.rosettacode.org/wiki/Dynamic_variable_names#Elena
- deleted 6y ago[deleted]