Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7006

Re: Proposal for easier syntax for define-unless-already-defined pattern

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news-1.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: Proposal for easier syntax for define-unless-already-defined pattern
Date Wed, 30 Jul 2014 19:41:26 +0200
Lines 28
Message-ID <c3sp27F40ebU1@mid.individual.net> (permalink)
References <fedb7003-f5e4-457b-9120-1ad937a9eedc@googlegroups.com> <bf498877-a244-4b0d-bab1-c4820534e7d7@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net jZca+TW3ibwojTmt/9UQ5QjcA4djNiyVOLFYqnZuV/Lbn2B2w=
Cancel-Lock sha1:8OispofuRabLf84y4KI7O8kF+Qo=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0
In-Reply-To <bf498877-a244-4b0d-bab1-c4820534e7d7@googlegroups.com>
Xref csiph.com comp.lang.ruby:7006

Show key headers only | View raw


On 29.07.2014 18:44, Eugene Gilburg wrote:
> Forgot to add, the `?=` syntax should be context-sensitive to
> primitive types. E.g.
>
> some_hash[:some_member] ?= 'some_value'
>
> Should check for `some_hash.key?(:some_value)`

That is unlikely to happen.  The compiler cannot reliably determine that 
some_hash is a Hash for all cases and hence method #key? must be used 
instead of #defined?.

> Which will be assigned if the key does not exist, but not be assigned
> if the key exists but has `false` or `nil` value (another difference
> with the `||=` pattern).

The only way to make that happen is to require the object to also 
implement #key? besides of #[] and #[]= - but then for example Array 
would need this as well.  Which prompts the question what does #key? 
return for in index less than the Array's length where the value stored 
here is nil?

Kind regards

	robert


Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Proposal for easier syntax for define-unless-already-defined pattern Eugene Gilburg <eugene.gilburg@gmail.com> - 2014-07-29 09:40 -0700
  Re: Proposal for easier syntax for define-unless-already-defined pattern Eugene Gilburg <eugene.gilburg@gmail.com> - 2014-07-29 09:44 -0700
    Re: Proposal for easier syntax for define-unless-already-defined pattern Robert Klemme <shortcutter@googlemail.com> - 2014-07-30 19:41 +0200
  Re: Proposal for easier syntax for define-unless-already-defined pattern Robert Klemme <shortcutter@googlemail.com> - 2014-07-30 19:45 +0200

csiph-web