all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: Perl, etc has these "?"-prefix modifiers/codes/whatever. Precisely which does emacs have (and NOT have)?
Date: Thu, 18 Feb 2010 12:46:14 +0100	[thread overview]
Message-ID: <877hqaojg9.fsf@galatea.lan.informatimago.com> (raw)
In-Reply-To: hlilkf$s99$1@panix1.panix.com

dkcombs@panix.com (David Combs) writes:

> Subj:  Perl, etc has these "?"-prefix modifiers/codes/whatever.  
>        Precisely which does emacs have (and NOT have)?
>
>
> Please, someone, make an ascii or html table or even plain text 
> list of all these neat "new" non-standard ops that perl and
> even php and ruby etc seem to have now, comparing them
> to what Emacs has or don't have.

emacs lisp has a lot of data types.  But in lisp, the types are not
associated to the variables, but to the values.  Therefore names
(symbols are used to name things in general in lisp) don't need to be
marked in any special way.

In lisps where there is both lexical bindings and dynamic bindings, such
as Common Lisp, there's a convention to distinguish dynamic variable
from lexical variables:

    - Dynamic variables are surrounded by stars:    *variable*

    - Lexical variables are surrounded by nothing:   variable

in addition:

    - Constant variables are surrounded by pluses:  +variable+

But in emacs lisp, there is only dynamic binding, so this convention is
not applied by emacs lisp programmers in general (but Common Lisp
programmers writing emacs lisp code tend to use it, so you may see it
applied for *global-variables* vs. local-variables).


Finally, in lisp, a name may have several meanings.  We distinguish
often the variable and the function meanings, and call lisps that
distinguish them "lisp-2", while lisps that don't (eg. scheme or LeLisp)
are called "lisp-1".  But there are a lot of other meanings a name may
take.  For example, in emacs lisp, a same name may be used to variable,
a function, a tagbody tag, a catch tag (catch also takes other objects),
a block name, etc. And moreover, as a programmer, you can add new
meanings to a name by writing new functions and macros (so the
classifications should really be "lisp-infinity+1" vs. "lisp-infinity").

Anyways, the distinction of meaning of a name in lisp is not done by the
form of the name, but by the context in which it is found.

For example, in a function call, a name in first position is interpreted
as a function name, while the same name in the other position would be
interpreted as a variable name. In the case of a block name, the first
argument (second position in the block form) is interpreted as a block
name.

(defun f (f) (1+ f))
(let ((f 41)) 
   (block f
     (return-from f (f f))))  ; On this line, first f is a block name, 
            ; second f is a function name, third f is a variable name.
--> 42




Here is an non-exclusive example of the various meaning the name haha
may be attached to in lisp:

(require 'cl)
                   
(defmacro show (&rest exprs)
  `(progn
     ,@(mapcar (lambda (expr) `(insert (format "%60s = %S\n" ',expr ,expr))) exprs)))


(defvar haha 0)
(defun haha () 1)
(progn
  (let ((haha 3)) 
    (flet ((haha () 4))
      (block haha
        (catch 'haha
          (tagbody
             (if (zerop haha) (go haha))
             (print '(it was not zero))
             (show haha (symbol-value 'haha) 
                   (haha) (funcall (function haha)) (funcall 'haha))
             (throw 'haha nil)
           haha
             (print '(it was  zero))
             (show haha (symbol-value 'haha)
                   (haha) (funcall (function haha)) (funcall 'haha))
             (return-from haha t))))))
  (show haha (symbol-value 'haha)
        (haha) (funcall (function haha)) (funcall 'haha)))

(it was not zero)
                                                        haha = 3
                                 (symbol-value (quote haha)) = 3
                                                      (haha) = 4
                                   (funcall (function haha)) = 4
                                      (funcall (quote haha)) = 4
                                                        haha = 0
                                 (symbol-value (quote haha)) = 0
                                                      (haha) = 1
                                   (funcall (function haha)) = 1
                                      (funcall (quote haha)) = 1



(In Common Lisp, output would be different, because it as lexical
bindings as an additionnal meaning for names:

(IT WAS NOT ZERO) 
                                                        HAHA = 3
                                        (SYMBOL-VALUE 'HAHA) = 3
                                                      (HAHA) = 4
                                            (FUNCALL #'HAHA) = 4
                                             (FUNCALL 'HAHA) = 1
                                                        HAHA = 0
                                        (SYMBOL-VALUE 'HAHA) = 0
                                                      (HAHA) = 1
                                            (FUNCALL #'HAHA) = 1
                                             (FUNCALL 'HAHA) = 1
)

 

-- 
__Pascal Bourguignon__



  reply	other threads:[~2010-02-18 11:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-18  6:10 Perl, etc has these "?"-prefix modifiers/codes/whatever. Precisely which does emacs have (and NOT have)? David Combs
2010-02-18 11:46 ` Pascal J. Bourguignon [this message]
2010-02-18 16:57   ` John Withers
     [not found]   ` <mailman.1450.1266512270.14305.help-gnu-emacs@gnu.org>
2010-02-18 19:02     ` Pascal J. Bourguignon
2010-02-18 21:38       ` John Bokma
2010-02-18 21:42       ` John Withers
     [not found]       ` <mailman.1460.1266529372.14305.help-gnu-emacs@gnu.org>
2010-02-19  0:53         ` David Combs
2010-02-19  1:06         ` Pascal J. Bourguignon
2010-02-19  2:36           ` John Withers
     [not found]           ` <mailman.1470.1266547034.14305.help-gnu-emacs@gnu.org>
2010-02-19  6:48             ` Tim X
2010-02-20 21:14               ` John Withers
     [not found]               ` <mailman.1559.1266700478.14305.help-gnu-emacs@gnu.org>
2010-02-23 12:33                 ` Tim Landscheidt
2010-02-18 16:23 ` Tyler Smith
     [not found] ` <mailman.1449.1266510261.14305.help-gnu-emacs@gnu.org>
2010-02-19  0:59   ` David Combs
2010-02-19  3:22     ` Tyler Smith
2010-02-24 19:54 ` Stefan Monnier

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877hqaojg9.fsf@galatea.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.