From: "matheusrich (Matheus Richard) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "matheusrich (Matheus Richard)" <noreply@ruby-lang.org>
Subject: [ruby-core:117244] [Ruby master Feature#6594] Integrated Functor
Date: Wed, 20 Mar 2024 00:21:04 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-107331.20240320002104.137@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-6594.20120615090238.137@ruby-lang.org
Issue #6594 has been updated by matheusrich (Matheus Richard).
@mame Can we close this issue?
----------------------------------------
Feature #6594: Integrated Functor
https://bugs.ruby-lang.org/issues/6594#change-107331
* Author: trans (Thomas Sawyer)
* Status: Assigned
* Assignee: matz (Yukihiro Matsumoto)
----------------------------------------
I know the developers meeting is coming up so I'd like to get a few ideas I've had sitting in the wings out in the air before then.
One the more useful is the idea of integrating Functors directly into the language. "Functor" is the term I use for "higher-order function".
I blogged about this idea and you can read it here: http://trans.github.com/2011-09-07-ruby-heart-higher-order-functions/
The super short version is this:
~~~ruby
def f => op, arg
arg.send(__op__, arg)
end
f + 3 #=> 6
f * 3 #=> 9
~~~
Another example:
~~~ruby
class String
def file => op, *args
File.send(__op__, self, *args)
end
end
"README.rdoc".file.mtime #=> 2012-06-14 12:34:45 -0400
~~~
I'm using `=>` as means of indicating a higher-order function. Of course another syntax could be used if this won't fly. The important thing is the idea of higher-order functions being integrated directly into the language. Doing this without that integration requires the creation of an intermediate object for each call which is very inefficient.
---Files--------------------------------
6594.pdf (77.8 KB)
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/
parent reply other threads:[~2024-03-20 0:21 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <redmine.issue-6594.20120615090238.137@ruby-lang.org>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-107331.20240320002104.137@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
--cc=noreply@ruby-lang.org \
--cc=ruby-core@ml.ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).