From: Dmitry Gutov <dgutov@yandex.ru>
To: John Yates <john@yates-sheets.org>
Cc: emacs-devel <emacs-devel@gnu.org>
Subject: Re: Guidelines for the "symbol" syntax class
Date: Mon, 4 Jan 2016 04:34:04 +0200 [thread overview]
Message-ID: <5689DA1C.7000701@yandex.ru> (raw)
In-Reply-To: <CAJnXXojy1b6LUdXcC+cDVPYT-OJMXCE8m8yqObE9oUYwU_PGbg@mail.gmail.com>
On 01/04/2016 04:21 AM, John Yates wrote:
> On Sun, Jan 3, 2016 at 8:35 PM, Dmitry Gutov <dgutov@yandex.ru
> <mailto:dgutov@yandex.ru>> wrote:
> >
> > => [:<=>, :==, :===, :eql?, :hash, :casecmp, :+, :*, :%, :[], :[]=,
> :insert, :length, :size, :bytesize, :empty?, ...]
>
> It seems similar to C++'s operator keyword. Am I getting closer? Is
> the colon required to abut the subsequent characters or can one write :
> <=> (note intervening space)?
No space allowed. See this usage example:
irb(main):003:0> "abc" == "def"
=> false
irb(main):004:0> String.instance_method(:==)
=> #<UnboundMethod: String#==>
irb(main):005:0> "abc".size
=> 3
irb(main):006:0> String.instance_method(:size)
=> #<UnboundMethod: String#size>
irb(main):007:0> "abc".method(:size)
=> #<Method: String#size>
irb(main):008:0> "abc".method(:size).call
=> 3
You can have Symbols with any name, though. So they are not tied to
methods, variables or anything.
Here's a good explanation:
http://www.randomhacks.net/2007/01/20/13-ways-of-looking-at-a-ruby-symbol/,
in particular, comparison #6 rings true: Ruby Symbols are similar to
Lisp symbols. In Lisp, one can reference a dynamically bound variable,
or call a function, using a symbol:
(let ((sym 'car)) (funcall sym nil))
or even
(let ((sym 'car)) (funcall (symbol-function sym) nil))
which is similar to "abc".method(:size).call I've tried above.
prev parent reply other threads:[~2016-01-04 2:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-03 5:09 Guidelines for the "symbol" syntax class Dmitry Gutov
2016-01-03 22:56 ` John Wiegley
2016-01-04 0:46 ` Dmitry Gutov
2016-01-04 0:51 ` Stefan Monnier
2016-01-04 0:58 ` Dmitry Gutov
2016-01-04 1:13 ` John Yates
2016-01-04 1:18 ` Dmitry Gutov
[not found] ` <CAJnXXog5fO_h5UNnVR67EJtT+u7+G-BVMFV3FnJgK=weGj0m_w@mail.gmail.com>
2016-01-04 2:01 ` Dmitry Gutov
2016-01-04 0:55 ` John Wiegley
2016-01-04 1:14 ` Dmitry Gutov
2016-01-04 2:56 ` Stefan Monnier
2016-01-04 3:47 ` Dmitry Gutov
[not found] ` <CAJnXXogonsWpqadNpX0BijzoiztorYP1d=b31seBfvGVBwwT_Q@mail.gmail.com>
[not found] ` <5689CC5C.4000408@yandex.ru>
[not found] ` <CAJnXXojy1b6LUdXcC+cDVPYT-OJMXCE8m8yqObE9oUYwU_PGbg@mail.gmail.com>
2016-01-04 2:34 ` Dmitry Gutov [this message]
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-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5689DA1C.7000701@yandex.ru \
--to=dgutov@yandex.ru \
--cc=emacs-devel@gnu.org \
--cc=john@yates-sheets.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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).