unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: MON KEY <monkey@sandpframing.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Save `nil' from the mutant void, preserve the truth of falsehood, prevent the falsehood of truth
Date: Sun, 12 Sep 2010 20:16:26 -0400	[thread overview]
Message-ID: <AANLkTimF-5XPaZosB3B+Ns6VbOYmt-mn-bXwmPfiPTrC@mail.gmail.com> (raw)
In-Reply-To: <jwv7hirxe48.fsf-monnier+emacs@gnu.org>

On Sun, Sep 12, 2010 at 10:00 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> Two one-liners not even a Perl devotee could love:
>> (prog1 #1=(fboundp ()) (unintern #1#))
>
> Let's see how many lines of defenses you broke in the above code:

So what?

These opening two examples were intentionally pathological (and
relatively harmless) There are certainly more prosaic
examples. Likewise, there a others that are far more destructive than
those provided.  Would you prefer I provide those in a public forum as
well?

> - use of #1= in code: very bad.
Which code?

`#1=', and related reader syntax constructs aren't bad.

Indeed, they are quite prevalent in byte-code files and the language
would be hamstrung without them.

That there are any number of ways to (ab)use them is a case for
restricting the uninternment of two critical Lisp constants `t' and
`nil' (and especially nil).

> - unintern takes a symbol as argument, not a boolean, so it should
>   not be called with the return value of (fboundp ...)

No, the argument to `unintern' can be a symbol or string.

(progn
  (eval (read
         (concat
          '(40 100 101 102 97 108 105 97 115 32 39 98 121 101 32
            40 105 110 100 105 114 101 99 116 45 102 117 110 99 116
            105 111 110 32 40 98 121 116 101 45 99 111 109 112 105
            108 101 32 35 39 40 108 97 109 98 100 97 32 40 120 41 32
            40 117 110 105 110 116 101 114 110 32 120 41 41 41 41 41)
          nil)))
  (bye (symbol-name 'bye))
  (fboundp 'bye))


> - calling unintern without an obarray arg is a bad idea.
Yeah,
a) Because there is really only one first class obarray.
b) because restriction aren't placed on certain constants in obarray.

>
> Maybe we should make the second argument mandatory.

That would be nice.

But, it should also require that the NAME arg _must_ be a string.
Better yet would be to also return the string on success:

This would allow interrogation of the obaray with success on failure:

 (not (intern-soft (unintern "bubba33" '<mandatory-ob>)))
 ;=> t

>
> The real nil is safely stored in a C variable `Qnil' which you should be
> able to get via something like (not t).

`nil' has to evaluate for both the empty list and a "symbol constant".
`(not t)' just makes it a "symbol constant".

See illustrations from previous example w/re to push.

> But I don't think Elisp lets you re-intern it,

I can't find a way.

> since `intern' only takes a string rather than a symbol.

Yeah, but again there is the weird corner case of interning the 0
length string.  Which, as shown in previous mail causes additional
headaches when attempting to re-intern a symbol.

emacs -Q

(prin1
(let ((s1 (intern (symbol-name (make-symbol ""))))
      (s2 (intern (symbol-name '#:)))
      cmp)
  (setq cmp `((,#1=s1 ,#1#) (,#2=s2 ,#2#)))
  `(:S1-LEN ,(length (car cmp))
    :S1-LEN ,(length (cadr cmp))
    :S1-IS-S1 ,(eq (caar cmp) (car (cdar cmp)))
    :S2-IS-S2 ,(eq (car (cadr cmp)) (cadr (cadr cmp)))
    :CAR-S1-IS-CAR-S2 ,(eq (caar cmp) (car (cadr cmp)))
    :CADR-S1-IS-CADR-S2 ,(eq (car (cdar cmp)) (cadr (cadr cmp)))
    :S1-IDENTITY ,(identity s1)
    :S1-IDENTITY ,(identity s1)
    :S1-SYM-NAME ,(symbol-name s1)
    :S2-SYM-NAME ,(symbol-name s2)
    :S2-UNINTD   ,(unintern (car (cadr cmp)))
    :S1-UNINTD   ,(unintern (caar cmp))))
(current-buffer))

(:S1-LEN 2 :S1-LEN 2
 :S1-IS-S1 t :S2-IS-S2 t
 :CAR-S1-IS-CAR-S2 t :CADR-S1-IS-CADR-S2 t
 :S1-IDENTITY  :S1-IDENTITY  ;; <- Note, that _is_ an identity
 :S1-SYM-NAME "" :S2-SYM-NAME ""
 :S2-UNINTD t :S1-UNINTD nil)

>
>        Stefan
>

/s_P\



  reply	other threads:[~2010-09-13  0:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-11 23:33 Save `nil' from the mutant void, preserve the truth of falsehood, prevent the falsehood of truth MON KEY
2010-09-12  0:16 ` Lars Magne Ingebrigtsen
2010-09-12 11:04 ` Andy Wingo
2010-09-12 14:00 ` Stefan Monnier
2010-09-13  0:16   ` MON KEY [this message]
2010-09-13  9:52     ` Stefan Monnier
2010-09-14  5:11       ` MON KEY
2010-09-14 11:14         ` Stefan Monnier
     [not found]         ` <51808.130.55.118.19.1284998205.squirrel@webmail.lanl.gov>
2010-09-22  1:37           ` MON KEY

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=AANLkTimF-5XPaZosB3B+Ns6VbOYmt-mn-bXwmPfiPTrC@mail.gmail.com \
    --to=monkey@sandpframing.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).